1
0

test_pydsl.py 2.1 KB

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