qvm_ls.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. # pylint: disable=protected-access,pointless-statement
  4. #
  5. # The Qubes OS Project, https://www.qubes-os.org/
  6. #
  7. # Copyright (C) 2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  8. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import qubes
  25. import qubes.vm.adminvm
  26. import qubes.tools.qvm_ls
  27. import qubes.tests
  28. import qubes.tests.vm.adminvm
  29. class TC_00_Column(qubes.tests.QubesTestCase):
  30. def test_000_collected(self):
  31. self.assertIn('NAME', qubes.tools.qvm_ls.Column.columns)
  32. def test_100_init(self):
  33. try:
  34. testcolumn = qubes.tools.qvm_ls.Column('TESTCOLUMN', width=50)
  35. self.assertEqual(testcolumn.ls_head, 'TESTCOLUMN')
  36. self.assertEqual(testcolumn.ls_width, 50)
  37. finally:
  38. try:
  39. qubes.tools.qvm_ls.Column.columns['TESTCOLUMN']
  40. except KeyError:
  41. pass
  42. def test_101_fix_width(self):
  43. try:
  44. testcolumn = qubes.tools.qvm_ls.Column('TESTCOLUMN', width=2)
  45. self.assertGreater(testcolumn.ls_width, len('TESTCOLUMN'))
  46. finally:
  47. try:
  48. qubes.tools.qvm_ls.Column.columns['TESTCOLUMN']
  49. except KeyError:
  50. pass
  51. class TC_90_globals(qubes.tests.QubesTestCase):
  52. # @qubes.tests.skipUnlessDom0
  53. def test_100_simple_flag(self):
  54. flag = qubes.tools.qvm_ls.simple_flag(1, 'T', 'qid')
  55. # TODO after serious testing of QubesVM and Qubes app, this should be
  56. # using normal components
  57. app = qubes.tests.vm.adminvm.TestApp()
  58. vm = qubes.vm.adminvm.AdminVM(app, None, qid=0, name='dom0')
  59. self.assertFalse(flag(None, vm))
  60. vm.qid = 1
  61. self.assertTrue(flag(None, vm))
  62. def test_900_formats_columns(self):
  63. for fmt in qubes.tools.qvm_ls.formats:
  64. for col in qubes.tools.qvm_ls.formats[fmt]:
  65. self.assertIn(col.upper(), qubes.tools.qvm_ls.Column.columns)