-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add basic test runner using pytest.
- Loading branch information
1 parent
e3b3f93
commit ab92a11
Showing
7 changed files
with
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*~ | ||
.pytest_cache | ||
__pycache__ |
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,28 @@ | ||
line_both = True | ||
line_sys_ignored=False | ||
|
||
line_src=True | ||
[section-both] | ||
line_both = True | ||
line_both_ignored = False | ||
line_sys_ignored = False | ||
line_formatting_mismatch_1=123 | ||
line_formatting_mismatch_2 = 123 | ||
|
||
line_formatting_nospaces_src=123 | ||
line_src = True | ||
[section-both-ignored] | ||
line_both = True | ||
|
||
|
||
[section-sys] | ||
line_sys_ignored = False | ||
|
||
[section-sys-ignored] | ||
line_sys = True | ||
line_sys_ignored = False | ||
|
||
[section][weird-kde-style] | ||
something = Yes really | ||
[section-src] | ||
line_src = True |
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,7 @@ | ||
{ | ||
"args": [ | ||
"-is", "section-sys-ignored", | ||
"-is", "section-src-ignored", | ||
"-ikr", ".*", ".*_ignored$" | ||
] | ||
} |
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,26 @@ | ||
line_both = True | ||
line_src=True | ||
line_src_ignored=False | ||
|
||
[section-both] | ||
line_both = True | ||
line_both_ignored = True | ||
line_src = True | ||
line_src_ignored = False | ||
line_formatting_nospaces_src=123 | ||
line_formatting_mismatch_1=123 | ||
line_formatting_mismatch_2 = 123 | ||
|
||
[section-both-ignored] | ||
line_both = True | ||
|
||
[section-src] | ||
line_src = True | ||
line_src_ignored = False | ||
|
||
[section-src-ignored] | ||
line_src = True | ||
line_src_ignored = False | ||
|
||
[section][weird-kde-style] | ||
something = Yes really |
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,29 @@ | ||
line_both = True | ||
line_sys=True | ||
line_sys_ignored=False | ||
|
||
[section-both] | ||
line_both = False | ||
line_both_ignored = False | ||
line_sys = True | ||
line_sys_ignored = False | ||
line_formatting_nospaces_sys=123 | ||
line_formatting_mismatch_1 = 123 | ||
line_formatting_mismatch_2=123 | ||
|
||
[section-both-ignored] | ||
line_both = False | ||
|
||
[section-sys1] | ||
line_sys = True | ||
|
||
[section-sys] | ||
line_sys = True | ||
line_sys_ignored = False | ||
|
||
[section-sys-ignored] | ||
line_sys = True | ||
line_sys_ignored = False | ||
|
||
[section][weird-kde-style] | ||
something = Yes really |
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,34 @@ | ||
import json | ||
from pathlib import Path | ||
import pytest | ||
import subprocess | ||
|
||
_TESTS_DIR = Path(__file__).parent | ||
_DATA_DIR = _TESTS_DIR / "data" | ||
_CHEZMOI_INI_MANAGER = _TESTS_DIR.parent / "bin" / "chezmoi_ini_manager.py" | ||
|
||
# Discover tests | ||
_TESTS = [e.stem for e in _DATA_DIR.glob("*.json")] | ||
|
||
|
||
@pytest.mark.parametrize("name", _TESTS) | ||
def test_example(name: str): | ||
base_name = _DATA_DIR / name | ||
with base_name.with_suffix(".json").open(mode="rt") as f: | ||
options = json.load(f) | ||
with base_name.with_suffix(".sys.ini").open(mode="rb") as sys_file: | ||
|
||
result = subprocess.run( | ||
[_CHEZMOI_INI_MANAGER, "-s", base_name.with_suffix(".src.ini")] | ||
+ options["args"], | ||
stdin=sys_file, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
assert result.returncode == options.get("expected_retcode", 0) | ||
assert result.stderr.decode("utf-8", errors="strict") == options.get( | ||
"expected_stderr", "" | ||
) | ||
with base_name.with_suffix(".expected.ini").open(mode="rb") as expected_file: | ||
expected_data = expected_file.read() | ||
assert expected_data.split(b"\n") == result.stdout.split(b"\n") |