mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix test_pydsl on Windows
Fixes an issue with the test_pydsl test on Windows This test has a hardcoded path to `/tmp` which doesn't exist by default on Windows. This PR adds a setUp function to the class which adds that directory on Windows and removes it after the test run. As a result it is now a destructive test.
This commit is contained in:
parent
59e2a1f053
commit
2c3e91dbea
1 changed files with 20 additions and 4 deletions
|
@ -3,10 +3,12 @@
|
|||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import destructiveTest
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.files
|
||||
|
@ -16,6 +18,19 @@ import salt.utils.stringutils
|
|||
|
||||
class PyDSLRendererIncludeTestCase(ModuleCase):
|
||||
|
||||
def setUp(self):
|
||||
self.directory_created = False
|
||||
if salt.utils.platform.is_windows():
|
||||
if not os.path.isdir('\\tmp'):
|
||||
os.mkdir('\\tmp')
|
||||
self.directory_created = True
|
||||
|
||||
def tearDown(self):
|
||||
if salt.utils.platform.is_windows():
|
||||
if self.directory_created:
|
||||
shutil.rmtree('\\tmp')
|
||||
|
||||
@destructiveTest
|
||||
def test_rendering_includes(self):
|
||||
'''
|
||||
This test is currently hard-coded to /tmp to work-around a seeming
|
||||
|
@ -49,9 +64,10 @@ class PyDSLRendererIncludeTestCase(ModuleCase):
|
|||
'hello green 2 \r\n' \
|
||||
'hello blue 3 \r\n'
|
||||
|
||||
with salt.utils.files.fopen('/tmp/output', 'r') as f:
|
||||
ret = salt.utils.stringutils.to_unicode(f.read())
|
||||
|
||||
os.remove('/tmp/output')
|
||||
try:
|
||||
with salt.utils.files.fopen('/tmp/output', 'r') as f:
|
||||
ret = salt.utils.stringutils.to_unicode(f.read())
|
||||
finally:
|
||||
os.remove('/tmp/output')
|
||||
|
||||
self.assertEqual(sorted(ret), sorted(expected))
|
||||
|
|
Loading…
Add table
Reference in a new issue