Skip to content

Commit 4f5ffa8

Browse files
authored
Add integration testing (#47)
Tests subprocess-tee when used from inside molecule.
1 parent f037559 commit 4f5ffa8

File tree

9 files changed

+66
-14
lines changed

9 files changed

+66
-14
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.tox
2+
**/*.pyc
3+
.github
4+
build
5+
dist

.yamllint

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# Based on ansible-lint config
33
extends: default
44

5-
ignore: |
6-
*{{cookiecutter**
7-
85
rules:
96
braces:
107
max-spaces-inside: 1

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ FROM alpine:latest
22
# Alpine is used on purpose because it does not come with bash, and we
33
# want to test that subprocess-tee works even on systems without bash shell.
44
ENV BUILD_DEPS="\
5+
ansible-base \
6+
gcc \
57
git \
8+
libffi-dev \
9+
make \
10+
musl-dev \
611
python3 \
12+
python3-dev \
713
py3-pip \
14+
py3-ruamel.yaml \
815
"
916

1017
RUN \
1118
apk add --update --no-cache \
12-
${BUILD_DEPS}
19+
${BUILD_DEPS} && \
20+
pip3 install -U pip
1321

1422
COPY . /root/code/
1523
WORKDIR /root/code/

molecule/default/converge.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Converge
3+
hosts: localhost
4+
gather_facts: false
5+
tasks:
6+
- name: "Test"
7+
debug:
8+
msg: "Past glories are poor feeding."

molecule/default/molecule.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: delegated
6+
platforms:
7+
- name: instance
8+
provisioner:
9+
name: ansible
10+
verifier:
11+
name: ansible

setup.cfg

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ setup_requires =
6666

6767
[options.extras_require]
6868
test =
69-
enrich>=1.2.5
70-
mock>=3.0.5
71-
pytest-cov>=2.7.1
72-
pytest-plus
73-
pytest-xdist>=1.29.0
74-
pytest>=6.1.0
69+
enrich>=1.2.6
70+
mock>=4.0.3
71+
molecule>=3.4.0 # ansible is needed but no direct imports are made
72+
pytest-cov>=2.12.1
73+
pytest-plus>=0.2
74+
pytest-xdist>=2.3.0
75+
pytest>=6.2.5
7576

7677
[options.packages.find]
7778
where = src

src/subprocess_tee/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess:
7474
def tee_func(line: bytes, sink: List[str], pipe: Optional[Any]) -> None:
7575
line_str = line.decode("utf-8").rstrip()
7676
sink.append(line_str)
77-
if not kwargs.get("quiet", False) and hasattr(pipe, "write"):
78-
print(line_str, file=pipe)
77+
if not kwargs.get("quiet", False):
78+
if pipe and hasattr(pipe, "write"):
79+
print(line_str, file=pipe)
80+
else:
81+
print(line_str)
7982

8083
loop = asyncio.get_event_loop()
8184
tasks = []
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Functional tests for subprocess-tee library."""
2+
import subprocess
3+
4+
5+
def test_molecule() -> None:
6+
"""Ensures molecule does display output of its subprocesses."""
7+
result = subprocess.run(
8+
["molecule", "test"],
9+
stdout=subprocess.PIPE,
10+
stderr=subprocess.PIPE,
11+
universal_newlines=True,
12+
check=False,
13+
) # type: ignore
14+
assert result.returncode == 0
15+
assert "Past glories are poor feeding." in result.stdout

tox.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ minversion = 3.9.0
33
envlist =
44
lint
55
packaging
6-
py{36,37,38,39}
6+
deps
7+
py
78

89
isolated_build = True
910

@@ -26,17 +27,20 @@ passenv =
2627
TERM
2728
setenv =
2829
PIP_DISABLE_VERSION_CHECK=1
29-
PYTEST_REQPASS=15
30+
PYTEST_REQPASS=16
3031
PYTHONDONTWRITEBYTECODE=1
3132
PYTHONUNBUFFERED=1
3233
commands =
3334
python -m pytest
35+
deps =
36+
ansible-core
3437
extras =
3538
test
3639
whitelist_externals =
3740
find
3841
rm
3942
sh
43+
changedir = {toxinidir}
4044

4145
[testenv:lint]
4246
description = Runs all linting tasks

0 commit comments

Comments
 (0)