test_xdg.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from unittest import TestCase
  2. import tempfile
  3. import shutil
  4. import os
  5. from qubesagent.xdg import find_dropins, load_desktop_entry_with_dropins, \
  6. ini_to_string
  7. class TestXdg(TestCase):
  8. def setUp(self):
  9. self.tempdir = tempfile.mkdtemp()
  10. self.addCleanup(shutil.rmtree, self.tempdir)
  11. def test_00_load_desktop_entry(self):
  12. filename = os.path.join(self.tempdir, 'firefox.desktop')
  13. dropins_dir = os.path.join(self.tempdir, 'dropins')
  14. dropin_filename = os.path.join(
  15. self.tempdir, 'dropins', 'firefox.desktop.d', '030_qubes.conf')
  16. with open(filename, 'w') as f:
  17. f.write('''\
  18. [Desktop Entry]
  19. Name=Firefox
  20. Exec=firefox %u
  21. ''')
  22. os.makedirs(os.path.dirname(dropin_filename))
  23. with open(dropin_filename, 'w') as f:
  24. f.write('''\
  25. [Desktop Entry]
  26. Exec=my-firefox %u
  27. [Other Group]
  28. X-Key=yes
  29. ''')
  30. dropins = find_dropins(filename, dropins_dir)
  31. self.assertListEqual(
  32. dropins,
  33. [dropin_filename])
  34. desktop_entry = load_desktop_entry_with_dropins(filename, dropins)
  35. self.assertEqual(desktop_entry.content['Desktop Entry']['Name'],
  36. 'Firefox')
  37. self.assertEqual(desktop_entry.content['Desktop Entry']['Exec'],
  38. 'my-firefox %u')
  39. self.assertEqual(desktop_entry.content['Other Group']['X-Key'],
  40. 'yes')
  41. def test_01_init_to_string(self):
  42. filename = os.path.join(self.tempdir, 'firefox.desktop')
  43. content = '''\
  44. [Desktop Entry]
  45. Name=Firefox
  46. Exec=firefox %u
  47. [Other Group]
  48. X-Key=yes
  49. '''
  50. with open(filename, 'w') as f:
  51. f.write(content)
  52. desktop_entry = load_desktop_entry_with_dropins(filename, [])
  53. output = ini_to_string(desktop_entry)
  54. self.assertEqual(output.rstrip(), content.rstrip())