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

Testing: Allow running tests locally and make README-test more verbose #69

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ $(PYTHON_TESTING_ENV)/.created: REQUIREMENTS.qa.txt
qa: $(PYTHON_TESTING_ENV)/.created
. $(PYTHON_TESTING_ENV)/bin/activate && \
black --check --diff . && \
flake8

flake8 && \
python3 -m pytest -vv
3 changes: 2 additions & 1 deletion REQUIREMENTS.qa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ black
flake8
flake8-pyproject
flake8-bugbear

pytest
pytest-mock
12 changes: 7 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_usage(capsys, mocker):
usbsdmux.__main__.main()
captured = capsys.readouterr()
assert captured.out == ""
assert captured.err.startswith("usage: usbsdmux")
assert captured.err.startswith("usage: usbsdmux"), "Invalid help: does not start with 'usage: usbsdmux'"


def test_help_in_readme(capsys, mocker):
Expand All @@ -21,8 +21,8 @@ def test_help_in_readme(capsys, mocker):
with pytest.raises(SystemExit):
usbsdmux.__main__.main()
captured = capsys.readouterr()
assert captured.out.startswith("usage: usbsdmux")
assert captured.err == ""
assert captured.out.startswith("usage: usbsdmux"), "Invalid help: does not start with 'usage: usbsdmux'"
assert captured.err == "", f"Execution of 'usbsdmux -h' failed: \n{captured.err}"

readme_path = os.path.join(os.path.dirname(__file__), "../", "README.rst")
readme_lines = None
Expand All @@ -35,9 +35,11 @@ def test_help_in_readme(capsys, mocker):
break
readme_lines.append(line)

assert readme_lines is not None
assert readme_lines is not None, "Bash command not found. Did you include ' $ usbsdmux -h'?"
assert readme_lines, "No output lines found. Did you indent the output correctly?"

del readme_lines[-1] # remove trailing empty line

output_lines = [f" {line}".rstrip() for line in captured.out.splitlines()]

assert output_lines == readme_lines
assert output_lines == readme_lines, "Output of 'usbsdmux -h' does not match output in README.rst"
Loading