Skip to content

Commit

Permalink
Clean tests
Browse files Browse the repository at this point in the history
In tests which inject template via stdin, inject the template via input
argument of subprocess.check_output rather than via command using echo
and pipe. Rationale: Less hassle with trailing LF, portability.
  • Loading branch information
kblomqvist committed Jan 31, 2021
1 parent 6ded1b8 commit 60dae25
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ def test_broken_extensions_name_error(tmpdir):


def test_render_template_from_stdin_to_stdout():
cmd = r'echo -n {{ foo }} | yasha --foo=bar -'
out = check_output(cmd, shell=True)
cmd = r'yasha --foo=bar -'
out = check_output(cmd, shell=True, input=b"{{ foo }}")
assert out == b'bar'


Expand All @@ -379,24 +379,24 @@ def test_json_template(tmpdir):

def test_mode_is_none():
"""gh-42, and gh-44"""
cmd = r'echo -n {{ foo }} | yasha -'
out = check_output(cmd, shell=True)
cmd = r'yasha -'
out = check_output(cmd, shell=True, input=b"{{ foo }}")
assert out == b''


def test_mode_is_pedantic():
"""gh-42, and gh-48"""
with pytest.raises(subprocess.CalledProcessError) as err:
cmd = r'echo {{ foo }} | yasha --mode=pedantic -'
out = check_output(cmd, shell=True, stderr=subprocess.STDOUT)
cmd = r'yasha --mode=pedantic -'
out = check_output(cmd, shell=True, stderr=subprocess.STDOUT, input=b"{{ foo }}")
out = err.value.output
assert out == b"Error: Variable 'foo' is undefined\n"
assert out.startswith(b"Error: Variable 'foo' is undefined")


def test_mode_is_debug():
"""gh-44"""
cmd = r'echo -n {{ foo }} | yasha --mode=debug -'
out = check_output(cmd, shell=True)
cmd = r'yasha --mode=debug -'
out = check_output(cmd, shell=True, input=b"{{ foo }}")
assert out == b'{{ foo }}'


Expand Down

0 comments on commit 60dae25

Please sign in to comment.