test_pydsl.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import shutil
  5. import textwrap
  6. import pytest
  7. import salt.utils.files
  8. import salt.utils.platform
  9. import salt.utils.stringutils
  10. from tests.support.case import ModuleCase
  11. from tests.support.helpers import destructiveTest
  12. from tests.support.unit import skipIf
  13. @pytest.mark.windows_whitelisted
  14. class PyDSLRendererIncludeTestCase(ModuleCase):
  15. def setUp(self):
  16. self.directory_created = False
  17. if salt.utils.platform.is_windows():
  18. if not os.path.isdir("\\tmp"):
  19. os.mkdir("\\tmp")
  20. self.directory_created = True
  21. def tearDown(self):
  22. if salt.utils.platform.is_windows():
  23. if self.directory_created:
  24. shutil.rmtree("\\tmp")
  25. @destructiveTest
  26. @skipIf(True, "SLOWTEST skip")
  27. def test_rendering_includes(self):
  28. """
  29. This test is currently hard-coded to /tmp to work-around a seeming
  30. inability to load custom modules inside the pydsl renderers. This
  31. is a FIXME.
  32. """
  33. self.run_function("state.sls", ["pydsl.aaa"])
  34. expected = textwrap.dedent(
  35. """\
  36. X1
  37. X2
  38. X3
  39. Y1 extended
  40. Y2 extended
  41. Y3
  42. hello red 1
  43. hello green 2
  44. hello blue 3
  45. """
  46. )
  47. # Windows adds `linefeed` in addition to `newline`. There's also an
  48. # unexplainable space before the `linefeed`...
  49. if salt.utils.platform.is_windows():
  50. expected = (
  51. "X1 \r\n"
  52. "X2 \r\n"
  53. "X3 \r\n"
  54. "Y1 extended \r\n"
  55. "Y2 extended \r\n"
  56. "Y3 \r\n"
  57. "hello red 1 \r\n"
  58. "hello green 2 \r\n"
  59. "hello blue 3 \r\n"
  60. )
  61. try:
  62. with salt.utils.files.fopen("/tmp/output", "r") as f:
  63. ret = salt.utils.stringutils.to_unicode(f.read())
  64. finally:
  65. os.remove("/tmp/output")
  66. self.assertEqual(sorted(ret), sorted(expected))