Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)