diff --git a/.yamllint b/.yamllint index 415452f..8827676 100644 --- a/.yamllint +++ b/.yamllint @@ -2,9 +2,6 @@ # Based on ansible-lint config extends: default -ignore: | - *{{cookiecutter** - rules: braces: max-spaces-inside: 1 diff --git a/Dockerfile b/Dockerfile index 6183b52..bf59204 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,12 @@ FROM alpine:latest # Alpine is used on purpose because it does not come with bash, and we # want to test that subprocess-tee works even on systems without bash shell. ENV BUILD_DEPS="\ +gcc \ git \ +libffi-dev \ +musl-dev \ python3 \ +python3-dev \ py3-pip \ " diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..0eb8a5b --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: localhost + gather_facts: false + tasks: + - name: "Test" + debug: + msg: "Past glories are poor feeding." diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..74c8557 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,11 @@ +--- +dependency: + name: galaxy +driver: + name: delegated +platforms: + - name: instance +provisioner: + name: ansible +verifier: + name: ansible diff --git a/src/subprocess_tee/__init__.py b/src/subprocess_tee/__init__.py index d12a62d..6e47f12 100644 --- a/src/subprocess_tee/__init__.py +++ b/src/subprocess_tee/__init__.py @@ -74,8 +74,11 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: def tee_func(line: bytes, sink: List[str], pipe: Optional[Any]) -> None: line_str = line.decode("utf-8").rstrip() sink.append(line_str) - if not kwargs.get("quiet", False) and hasattr(pipe, "write"): - print(line_str, file=pipe) + if not kwargs.get("quiet", False): + if pipe and hasattr(pipe, "write"): + print(line_str, file=pipe) + else: + print(line_str) loop = asyncio.get_event_loop() tasks = [] diff --git a/src/subprocess_tee/test/test_func.py b/src/subprocess_tee/test/test_func.py new file mode 100644 index 0000000..c630aa3 --- /dev/null +++ b/src/subprocess_tee/test/test_func.py @@ -0,0 +1,15 @@ +"""Functional tests for subprocess-tee library.""" +import subprocess + + +def test_molecule() -> None: + """Ensures molecule does display output of its subprocesses.""" + result = subprocess.run( + ["molecule", "test"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + check=False, + ) # type: ignore + assert result.returncode == 0 + assert "Past glories are poor feeding." in result.stdout diff --git a/test-requirements.in b/test-requirements.in index 65f0495..b1dd4b7 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -1,5 +1,7 @@ +ansible-core enrich>=1.2.5 mock>=3.0.5 +molecule pytest-cov>=2.7.1 pytest-plus pytest-xdist>=1.29.0 diff --git a/test-requirements.txt b/test-requirements.txt index 605050c..4ae1954 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,41 +1,117 @@ # -# This file is autogenerated by pip-compile +# This file is autogenerated by pip-compile with python 3.9 # To update, run: # # pip-compile --output-file=test-requirements.txt setup.cfg test-requirements.in # +ansible-core==2.11.4 + # via -r test-requirements.in +ansible-lint==5.1.3 + # via molecule apipkg==1.5 # via execnet +arrow==1.1.1 + # via jinja2-time attrs==20.3.0 # via pytest +bcrypt==3.2.0 + # via paramiko +binaryornot==0.4.4 + # via cookiecutter +bracex==2.1.1 + # via wcmatch +cerberus==1.3.2 + # via molecule +certifi==2021.5.30 + # via requests +cffi==1.14.6 + # via + # bcrypt + # cryptography + # pynacl +chardet==4.0.0 + # via binaryornot +charset-normalizer==2.0.4 + # via requests +click==8.0.1 + # via + # click-help-colors + # cookiecutter + # molecule +click-help-colors==0.9.1 + # via molecule colorama==0.4.4 # via rich commonmark==0.9.1 # via rich +cookiecutter==1.7.3 + # via molecule coverage==5.5 # via pytest-cov +cryptography==3.4.8 + # via + # ansible-core + # paramiko enrich==1.2.6 - # via -r test-requirements.in + # via + # -r test-requirements.in + # ansible-lint + # molecule execnet==1.8.0 # via pytest-xdist +idna==3.2 + # via requests iniconfig==1.1.1 # via pytest +jinja2==3.0.1 + # via + # ansible-core + # cookiecutter + # jinja2-time + # molecule +jinja2-time==0.2.0 + # via cookiecutter +markupsafe==2.0.1 + # via jinja2 mock==4.0.3 # via -r test-requirements.in +molecule==3.4.0 + # via -r test-requirements.in more-itertools==8.7.0 # via pytest-plus packaging==20.9 - # via pytest + # via + # ansible-core + # ansible-lint + # molecule + # pytest +paramiko==2.7.2 + # via molecule pluggy==0.13.1 - # via pytest + # via + # molecule + # pytest +poyo==0.5.0 + # via cookiecutter py==1.10.0 # via # pytest # pytest-forked +pycparser==2.20 + # via cffi pygments==2.8.1 # via rich +pynacl==1.4.0 + # via paramiko pyparsing==2.4.7 # via packaging +pytest==6.2.3 + # via + # -r test-requirements.in + # pytest-cov + # pytest-forked + # pytest-plus + # pytest-xdist pytest-cov==2.11.1 # via -r test-requirements.in pytest-forked==1.3.0 @@ -44,16 +120,48 @@ pytest-plus==0.2 # via -r test-requirements.in pytest-xdist==2.2.1 # via -r test-requirements.in -pytest==6.2.3 +python-dateutil==2.8.2 + # via arrow +python-slugify==5.0.2 + # via cookiecutter +pyyaml==5.4.1 # via - # -r test-requirements.in - # pytest-cov - # pytest-forked - # pytest-plus - # pytest-xdist + # ansible-core + # ansible-lint + # molecule +requests==2.26.0 + # via cookiecutter +resolvelib==0.5.4 + # via ansible-core rich==10.1.0 - # via enrich + # via + # ansible-lint + # enrich + # molecule +ruamel.yaml==0.17.16 + # via ansible-lint +ruamel.yaml.clib==0.2.6 + # via ruamel.yaml +six==1.16.0 + # via + # bcrypt + # cookiecutter + # pynacl + # python-dateutil +subprocess-tee==0.3.2 + # via molecule +tenacity==8.0.1 + # via ansible-lint +text-unidecode==1.3 + # via python-slugify toml==0.10.2 # via pytest typing-extensions==3.7.4.3 # via rich +urllib3==1.26.6 + # via requests +wcmatch==8.2 + # via ansible-lint + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/tox.ini b/tox.ini index 140a3ae..9560b13 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,8 @@ minversion = 3.9.0 envlist = lint packaging - py{36,37,38,39} + deps + py isolated_build = True @@ -26,7 +27,7 @@ passenv = TERM setenv = PIP_DISABLE_VERSION_CHECK=1 - PYTEST_REQPASS=15 + PYTEST_REQPASS=16 PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 commands = @@ -37,6 +38,7 @@ whitelist_externals = find rm sh +changedir = {toxinidir} [testenv:deps] description = Update dependency lock files used for testing