Skip to content

Commit

Permalink
fix regression bugs in tests running on python2
Browse files Browse the repository at this point in the history
(cherry picked from commit 6d1ae09)
  • Loading branch information
Alex Tremblay authored and kblomqvist committed Aug 19, 2020
1 parent fe61691 commit 11969f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import pytest
import os.path
import sys

SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))


@pytest.fixture
def fixtures_dir():
return os.path.join(SCRIPT_PATH, "fixtures")
3 changes: 3 additions & 0 deletions tests/test_build_automation_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

import pytest

if sys.version_info[0] == 2:
FileNotFoundError = IOError

SCRIPT_PATH = path.dirname(path.realpath(__file__))

requires_py27_or_py35_or_greater = pytest.mark.skipif(
Expand Down
21 changes: 13 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@
import subprocess
from subprocess import call, check_output
from textwrap import dedent
import sys

import pytest
from yasha.cli import cli
from click.testing import CliRunner


def wrap(text):
return dedent(text).lstrip()


PY2 = True if sys.version_info[0] == 2 else False


@pytest.fixture(params=('json', 'yaml', 'yml', 'toml'))
def vartpl(request):
template = {
Expand Down Expand Up @@ -356,8 +361,8 @@ def test_broken_extensions_name_error(tmpdir):


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


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

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


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


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


Expand Down

0 comments on commit 11969f5

Please sign in to comment.