qvm_ls.py 2.6 KB

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