Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure output is displayed by tee #47

Merged
merged 1 commit into from
Sep 13, 2021
Merged
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
Add integration testing
Tests subprocess-tee when used from inside
molecule.
ssbarnea committed Sep 13, 2021

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
commit 04006f237c21a5df0e9b19c2fbb930646d399626
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.tox
**/*.pyc
.github
build
dist
3 changes: 0 additions & 3 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -2,9 +2,6 @@
# Based on ansible-lint config
extends: default

ignore: |
*{{cookiecutter**

rules:
braces:
max-spaces-inside: 1
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -2,14 +2,22 @@ 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="\
ansible-base \
gcc \
git \
libffi-dev \
make \
musl-dev \
python3 \
python3-dev \
py3-pip \
py3-ruamel.yaml \
"

RUN \
apk add --update --no-cache \
${BUILD_DEPS}
${BUILD_DEPS} && \
pip3 install -U pip

COPY . /root/code/
WORKDIR /root/code/
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
13 changes: 7 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -66,12 +66,13 @@ setup_requires =

[options.extras_require]
test =
enrich>=1.2.5
mock>=3.0.5
pytest-cov>=2.7.1
pytest-plus
pytest-xdist>=1.29.0
pytest>=6.1.0
enrich>=1.2.6
mock>=4.0.3
molecule>=3.4.0 # ansible is needed but no direct imports are made
pytest-cov>=2.12.1
pytest-plus>=0.2
pytest-xdist>=2.3.0
pytest>=6.2.5

[options.packages.find]
where = src
7 changes: 5 additions & 2 deletions src/subprocess_tee/__init__.py
Original file line number Diff line number Diff line change
@@ -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 = []
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
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ minversion = 3.9.0
envlist =
lint
packaging
py{36,37,38,39}
deps
py

isolated_build = True

@@ -26,17 +27,20 @@ passenv =
TERM
setenv =
PIP_DISABLE_VERSION_CHECK=1
PYTEST_REQPASS=15
PYTEST_REQPASS=16
PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
commands =
python -m pytest
deps =
ansible-core
extras =
test
whitelist_externals =
find
rm
sh
changedir = {toxinidir}

[testenv:lint]
description = Runs all linting tasks