test_pydsl.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import textwrap
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  8. # Import Salt libs
  9. import salt.utils.files
  10. import salt.utils.platform
  11. import salt.utils.stringutils
  12. class PyDSLRendererIncludeTestCase(ModuleCase):
  13. def test_rendering_includes(self):
  14. '''
  15. This test is currently hard-coded to /tmp to work-around a seeming
  16. inability to load custom modules inside the pydsl renderers. This
  17. is a FIXME.
  18. '''
  19. self.run_function('state.sls', ['pydsl.aaa'])
  20. expected = textwrap.dedent('''\
  21. X1
  22. X2
  23. X3
  24. Y1 extended
  25. Y2 extended
  26. Y3
  27. hello red 1
  28. hello green 2
  29. hello blue 3
  30. ''')
  31. # Windows adds `linefeed` in addition to `newline`. There's also an
  32. # unexplainable space before the `linefeed`...
  33. if salt.utils.platform.is_windows():
  34. expected = 'X1 \r\n' \
  35. 'X2 \r\n' \
  36. 'X3 \r\n' \
  37. 'Y1 extended \r\n' \
  38. 'Y2 extended \r\n' \
  39. 'Y3 \r\n' \
  40. 'hello red 1 \r\n' \
  41. 'hello green 2 \r\n' \
  42. 'hello blue 3 \r\n'
  43. with salt.utils.files.fopen('/tmp/output', 'r') as f:
  44. ret = salt.utils.stringutils.to_unicode(f.read())
  45. os.remove('/tmp/output')
  46. self.assertEqual(sorted(ret), sorted(expected))