Skip to content

Commit

Permalink
Add integration testing
Browse files Browse the repository at this point in the history
Tests subprocess-tee when used from inside
molecule.
  • Loading branch information
ssbarnea committed Sep 12, 2021
1 parent 7945a85 commit 9b29e22
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 18 deletions.
3 changes: 0 additions & 3 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# Based on ansible-lint config
extends: default

ignore: |
*{{cookiecutter**

rules:
braces:
max-spaces-inside: 1
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"

Expand Down
8 changes: 8 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: localhost
gather_facts: false
tasks:
- name: "Test"
debug:
msg: "Past glories are poor feeding."
11 changes: 11 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
dependency:
name: galaxy
driver:
name: delegated
platforms:
- name: instance
provisioner:
name: ansible
verifier:
name: ansible
7 changes: 5 additions & 2 deletions src/subprocess_tee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
15 changes: 15 additions & 0 deletions src/subprocess_tee/test/test_func.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test-requirements.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
130 changes: 119 additions & 11 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ minversion = 3.9.0
envlist =
lint
packaging
py{36,37,38,39}
deps
py

isolated_build = True

Expand All @@ -26,7 +27,7 @@ passenv =
TERM
setenv =
PIP_DISABLE_VERSION_CHECK=1
PYTEST_REQPASS=15
PYTEST_REQPASS=16
PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
commands =
Expand All @@ -37,6 +38,7 @@ whitelist_externals =
find
rm
sh
changedir = {toxinidir}

[testenv:deps]
description = Update dependency lock files used for testing
Expand Down

0 comments on commit 9b29e22

Please sign in to comment.