mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43913 from twangboy/win_fix_test_jinja
Fix `unit.templates.test_jinja` for Windows
This commit is contained in:
commit
afcaa0c591
2 changed files with 17 additions and 12 deletions
|
@ -168,8 +168,13 @@ def wrap_tmpl_func(render_str):
|
|||
if six.PY2:
|
||||
output = output.encode(SLS_ENCODING)
|
||||
if salt.utils.is_windows():
|
||||
newline = False
|
||||
if output.endswith(('\n', os.linesep)):
|
||||
newline = True
|
||||
# Write out with Windows newlines
|
||||
output = os.linesep.join(output.splitlines())
|
||||
if newline:
|
||||
output += os.linesep
|
||||
|
||||
except SaltRenderError as exc:
|
||||
log.error("Rendering exception occurred: {0}".format(exc))
|
||||
|
@ -293,7 +298,7 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
|||
# http://jinja.pocoo.org/docs/api/#unicode
|
||||
tmplstr = tmplstr.decode(SLS_ENCODING)
|
||||
|
||||
if tmplstr.endswith('\n'):
|
||||
if tmplstr.endswith(os.linesep):
|
||||
newline = True
|
||||
|
||||
if not saltenv:
|
||||
|
@ -462,7 +467,7 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
|||
# Workaround a bug in Jinja that removes the final newline
|
||||
# (https://github.com/mitsuhiko/jinja2/issues/75)
|
||||
if newline:
|
||||
output += '\n'
|
||||
output += os.linesep
|
||||
|
||||
return output
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ class TestGetTemplate(TestCase):
|
|||
out = render_jinja_tmpl(
|
||||
fp_.read(),
|
||||
dict(opts=self.local_opts, saltenv='test', salt=self.local_salt))
|
||||
self.assertEqual(out, 'world\n')
|
||||
self.assertEqual(out, 'world' + os.linesep)
|
||||
|
||||
def test_fallback_noloader(self):
|
||||
'''
|
||||
|
@ -189,7 +189,7 @@ class TestGetTemplate(TestCase):
|
|||
out = render_jinja_tmpl(
|
||||
fp_.read(),
|
||||
dict(opts=self.local_opts, saltenv='test', salt=self.local_salt))
|
||||
self.assertEqual(out, 'Hey world !a b !\n')
|
||||
self.assertEqual(out, 'Hey world !a b !' + os.linesep)
|
||||
|
||||
def test_saltenv(self):
|
||||
'''
|
||||
|
@ -208,7 +208,7 @@ class TestGetTemplate(TestCase):
|
|||
'file_roots': self.local_opts['file_roots'],
|
||||
'pillar_roots': self.local_opts['pillar_roots']},
|
||||
a='Hi', b='Salt', saltenv='test', salt=self.local_salt))
|
||||
self.assertEqual(out, 'Hey world !Hi Salt !\n')
|
||||
self.assertEqual(out, 'Hey world !Hi Salt !' + os.linesep)
|
||||
self.assertEqual(fc.requests[0]['path'], 'salt://macro')
|
||||
|
||||
def test_macro_additional_log_for_generalexc(self):
|
||||
|
@ -217,7 +217,7 @@ class TestGetTemplate(TestCase):
|
|||
more output from trace.
|
||||
'''
|
||||
expected = r'''Jinja error:.*division.*
|
||||
.*/macrogeneral\(2\):
|
||||
.*macrogeneral\(2\):
|
||||
---
|
||||
\{% macro mymacro\(\) -%\}
|
||||
\{\{ 1/0 \}\} <======================
|
||||
|
@ -241,7 +241,7 @@ class TestGetTemplate(TestCase):
|
|||
more output from trace.
|
||||
'''
|
||||
expected = r'''Jinja variable 'b' is undefined
|
||||
.*/macroundefined\(2\):
|
||||
.*macroundefined\(2\):
|
||||
---
|
||||
\{% macro mymacro\(\) -%\}
|
||||
\{\{b.greetee\}\} <-- error is here <======================
|
||||
|
@ -264,7 +264,7 @@ class TestGetTemplate(TestCase):
|
|||
If we failed in a macro, get more output from trace.
|
||||
'''
|
||||
expected = r'''Jinja syntax error: expected token .*end.*got '-'.*
|
||||
.*/macroerror\(2\):
|
||||
.*macroerror\(2\):
|
||||
---
|
||||
# macro
|
||||
\{% macro mymacro\(greeting, greetee='world'\) -\} <-- error is here <======================
|
||||
|
@ -294,7 +294,7 @@ class TestGetTemplate(TestCase):
|
|||
'file_roots': self.local_opts['file_roots'],
|
||||
'pillar_roots': self.local_opts['pillar_roots']},
|
||||
a='Hi', b='Sàlt', saltenv='test', salt=self.local_salt))
|
||||
self.assertEqual(out, u'Hey world !Hi Sàlt !\n')
|
||||
self.assertEqual(out, salt.utils.to_unicode('Hey world !Hi Sàlt !' + os.linesep))
|
||||
self.assertEqual(fc.requests[0]['path'], 'salt://macro')
|
||||
|
||||
filename = os.path.join(TEMPLATES_DIR, 'files', 'test', 'non_ascii')
|
||||
|
@ -305,7 +305,7 @@ class TestGetTemplate(TestCase):
|
|||
'file_roots': self.local_opts['file_roots'],
|
||||
'pillar_roots': self.local_opts['pillar_roots']},
|
||||
a='Hi', b='Sàlt', saltenv='test', salt=self.local_salt))
|
||||
self.assertEqual(u'Assunção\n', out)
|
||||
self.assertEqual(u'Assunção' + os.linesep, out)
|
||||
self.assertEqual(fc.requests[0]['path'], 'salt://macro')
|
||||
|
||||
@skipIf(HAS_TIMELIB is False, 'The `timelib` library is not installed.')
|
||||
|
@ -340,8 +340,8 @@ class TestGetTemplate(TestCase):
|
|||
with salt.utils.fopen(out['data']) as fp:
|
||||
result = fp.read()
|
||||
if six.PY2:
|
||||
result = result.decode('utf-8')
|
||||
self.assertEqual(u'Assunção\n', result)
|
||||
result = salt.utils.to_unicode(result)
|
||||
self.assertEqual(salt.utils.to_unicode('Assunção' + os.linesep), result)
|
||||
|
||||
def test_get_context_has_enough_context(self):
|
||||
template = '1\n2\n3\n4\n5\n6\n7\n8\n9\na\nb\nc\nd\ne\nf'
|
||||
|
|
Loading…
Add table
Reference in a new issue