-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add app-level tests and fix fix command
fix command was broken - somehow missed adding @file_options to it...
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from collections.abc import Iterator | ||
from contextlib import contextmanager | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
from shutil import copytree | ||
|
||
from click.testing import CliRunner | ||
from pytest import MonkeyPatch, fixture | ||
|
||
from copyright2.app import list, check, fix | ||
|
||
|
||
__DIR__ = Path(__file__).parent | ||
|
||
|
||
EXAMPLES = __DIR__.parent / "examples" | ||
|
||
|
||
@contextmanager | ||
def clone_example(monkeypatch: MonkeyPatch, name: str) -> Iterator[None]: | ||
with TemporaryDirectory() as _dir: | ||
dir = Path(_dir) | ||
copytree(EXAMPLES / name, dir / name) | ||
monkeypatch.chdir(dir / name) | ||
yield | ||
|
||
|
||
@fixture | ||
def examples_readme(monkeypatch: MonkeyPatch) -> Iterator[None]: | ||
with clone_example(monkeypatch, "readme"): | ||
yield | ||
|
||
|
||
@fixture | ||
def examples_subdirs(monkeypatch: MonkeyPatch) -> Iterator[None]: | ||
with clone_example(monkeypatch, "subdirs"): | ||
yield | ||
|
||
|
||
def test_list_readme(examples_readme: None) -> None: | ||
result = CliRunner().invoke(list) | ||
|
||
assert result.exit_code == 0 | ||
|
||
assert result.stdout.splitlines() == [ | ||
"README.md", | ||
"src/readme.py", | ||
"src/ext/readme.h", | ||
"src/ext/readme.c", | ||
"4", | ||
] | ||
|
||
|
||
def test_check_readme(examples_readme: None) -> None: | ||
result = CliRunner().invoke(check) | ||
|
||
assert result.exit_code != 0 | ||
|
||
assert result.stdout.splitlines() == [ | ||
"README.md: notice not found", | ||
"src/ext/readme.h: 2: simplified timestamp expression", | ||
"2", | ||
] | ||
|
||
|
||
def test_fix_readme(examples_readme: None) -> None: | ||
result = CliRunner().invoke(fix) | ||
|
||
assert result.exit_code != 0 | ||
|
||
assert result.stdout.splitlines() == [ | ||
"README.md: notice not found", | ||
"fixing src/ext/readme.h... ok", | ||
"1", | ||
] | ||
|
||
|
||
def test_list_subdirs(examples_subdirs: None) -> None: | ||
result = CliRunner().invoke(list) | ||
|
||
assert result.exit_code == 0 | ||
|
||
assert result.stdout.splitlines() == [ | ||
"a/b/included.py", | ||
"1", | ||
] |