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 6997f44
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 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
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
14 changes: 14 additions & 0 deletions src/subprocess_tee/test/test_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""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"],
capture_output=True,
universal_newlines=True,
check=False,
)
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
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ minversion = 3.9.0
envlist =
lint
packaging
py{36,37,38,39}
py

isolated_build = True

Expand All @@ -26,7 +26,7 @@ passenv =
TERM
setenv =
PIP_DISABLE_VERSION_CHECK=1
PYTEST_REQPASS=15
PYTEST_REQPASS=16
PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
commands =
Expand Down

0 comments on commit 6997f44

Please sign in to comment.