Skip to content

Commit

Permalink
Merge 59c8e39 into bb6da51
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandm committed Nov 28, 2018
2 parents bb6da51 + 59c8e39 commit c05e642
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -39,7 +39,7 @@ def run_tests(self):
},
install_requires=required,
cmdclass={"test": PyTest},
tests_require=["pytest", "requests"],
tests_require=["pytest", "requests", "attrs"],
project_urls={
'Source': URL
},
Expand Down
33 changes: 18 additions & 15 deletions test/test_cli/test_script.py
@@ -1,9 +1,11 @@
import imp
import json
import subprocess
import sys
import tempfile
from pathlib import Path
from time import time
from typing import Tuple

import pytest

Expand Down Expand Up @@ -71,24 +73,29 @@ def test_help():
]


@pytest.mark.parametrize("command", test_commands)
def test_script(command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
def _validate_result(proc: subprocess.Popen) -> Tuple[str, str]:
stdout, stderr = map(bytes.decode, proc.communicate())
assert not stderr, stderr
assert stdout, stdout
assert proc.returncode == 0
print(stdout.decode())
# Note: imp package is deprecated but I can't find a way to create dummy module using importlib
module = imp.new_module("model")
exec(compile(stdout, "model.py", "exec"), module.__dict__)
return stdout, stderr


@pytest.mark.parametrize("command", test_commands)
def test_script(command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = _validate_result(proc)
print(stdout)


@pytest.mark.parametrize("command", test_commands)
def test_script_attrs(command):
command += " -f attrs"
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = map(bytes.decode, proc.communicate())
assert not stderr, stderr
assert stdout, stdout
assert proc.returncode == 0
stdout, stderr = _validate_result(proc)
assert "@attr.s" in stdout
print(stdout)

Expand All @@ -98,10 +105,7 @@ def test_script_custom(command):
command += " -f custom --code-generator json_to_models.models.attr.AttrsModelCodeGenerator"
command += ' --code-generator-kwargs "meta=true"'
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = map(bytes.decode, proc.communicate())
assert not stderr, stderr
assert stdout, stdout
assert proc.returncode == 0
stdout, stderr = _validate_result(proc)
assert "@attr.s" in stdout
print(stdout)

Expand All @@ -125,5 +129,4 @@ def test_script_custom(command):
def test_wrong_arguments(command):
print("Command:", command)
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = map(bytes.decode, proc.communicate())
assert not stderr and proc.returncode == 0, stderr
_validate_result(proc)

0 comments on commit c05e642

Please sign in to comment.