Skip to content

Commit

Permalink
test: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Mar 12, 2024
1 parent cab41f0 commit 0deeb5d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typing-extensions = ">=3.10.0.2"
black = ">=24.1.1"
isort = ">=5.13.2"
clea = ">=0.1.0rc4"
pytest = "==7.4.2"

[requires]
python_version = "3.10"
3 changes: 3 additions & 0 deletions linters.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ ignore_missing_imports = True

[mypy-clea.*]
ignore_missing_imports = True

[mypy-pytest.*]
ignore_missing_imports = True
31 changes: 31 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Test examples."""

import subprocess
import sys
from pathlib import Path

import pytest

EXAMPLES = list((Path(__file__).parent.parent / "examples").glob("*.py"))

ALLOWED_TO_FAIL = {
"missing_placeholders.py": (
"Error rendering 'Hello, ${name|John Doe}, "
"I'm ${age} years old and I like ${food|Coffee}'; "
"Value for 'age' not provided"
),
}


@pytest.mark.parametrize("example", EXAMPLES)
def test_example(example: Path) -> None:
"""Test example."""
with subprocess.Popen(
[sys.executable, example], stdout=subprocess.PIPE, stderr=subprocess.PIPE
) as process:
process.wait()
if example.name in ALLOWED_TO_FAIL:
assert process.returncode == 1, process.stderr.read().decode() # type: ignore
assert ALLOWED_TO_FAIL[example.name] in process.stderr.read().decode() # type: ignore
else:
assert process.returncode == 0, process.stderr.read().decode() # type: ignore

0 comments on commit 0deeb5d

Please sign in to comment.