From dbd8e514f5b590289aebd78875732a11ed6ef866 Mon Sep 17 00:00:00 2001 From: antoine Date: Wed, 3 Jun 2020 22:18:36 +0200 Subject: [PATCH] All good. --- potodo/_po_file.py | 6 ++- potodo/potodo.py | 6 ++- tests/fixtures/repository/excluded/file4.po | 6 ++- tests/fixtures/repository/folder/excluded.po | 7 ++++ tests/test_potodo.py | 41 ++++++++++---------- 5 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 tests/fixtures/repository/folder/excluded.po diff --git a/potodo/_po_file.py b/potodo/_po_file.py index 9d3480d..17e5a01 100644 --- a/potodo/_po_file.py +++ b/potodo/_po_file.py @@ -1,3 +1,4 @@ +import itertools from typing import Dict, Mapping, Sequence, Set, List, Iterable from pathlib import Path @@ -58,6 +59,7 @@ def is_within(file: Path, excluded: Path) -> bool: """ excluded = excluded.resolve() file = file.resolve() + return excluded in file.parents or file == excluded @@ -80,8 +82,10 @@ def get_po_files_from_repo( # Separates each directory and places all pofiles for each directory accordingly po_files_per_directory: Mapping[str, Set[Path]] = { - path.parent.name: set(path.parent.glob("*.po")) for path in all_po_files + name: set(files) for name, files in + itertools.groupby(all_po_files, key=lambda path: path.parent.name) } + end_dict: Dict[str, Sequence[PoFileStats]] = {} for directory, po_files in sorted(po_files_per_directory.items()): # For each file in each directory, gets a PoFile instance then add it to a dict diff --git a/potodo/potodo.py b/potodo/potodo.py index f54c1d8..76cb23d 100644 --- a/potodo/potodo.py +++ b/potodo/potodo.py @@ -298,7 +298,11 @@ def main() -> None: ) parser.add_argument( - "-j", "--json", action="store_true", help="format output as JSON." + "-j", + "--json", + action="store_true", + dest="json_format", + help="format output as JSON.", ) parser.add_argument( diff --git a/tests/fixtures/repository/excluded/file4.po b/tests/fixtures/repository/excluded/file4.po index 588d299..f0c6f5c 100644 --- a/tests/fixtures/repository/excluded/file4.po +++ b/tests/fixtures/repository/excluded/file4.po @@ -1,3 +1,7 @@ +#: /I/am/excluded.rst:111 +msgid "I don't care" +msgstr "Peu me chaut" + #: /I/am/excluded.rst:333 msgid "Whatever" -msgstr "Peu importe" +msgstr "" diff --git a/tests/fixtures/repository/folder/excluded.po b/tests/fixtures/repository/folder/excluded.po new file mode 100644 index 0000000..f0c6f5c --- /dev/null +++ b/tests/fixtures/repository/folder/excluded.po @@ -0,0 +1,7 @@ +#: /I/am/excluded.rst:111 +msgid "I don't care" +msgstr "Peu me chaut" + +#: /I/am/excluded.rst:333 +msgid "Whatever" +msgstr "" diff --git a/tests/test_potodo.py b/tests/test_potodo.py index 5468b92..07611e1 100644 --- a/tests/test_potodo.py +++ b/tests/test_potodo.py @@ -3,42 +3,41 @@ from pathlib import Path from potodo.potodo import exec_potodo -FIXTURE_DIR = Path(__file__).resolve().parent / "fixtures" REPO_DIR = "repository" +ABS_REPO_DIR = Path(__file__).resolve().parent / "fixtures" / REPO_DIR + +config = { + "path": f"{ABS_REPO_DIR}", + "exclude": [f"{ABS_REPO_DIR}/excluded", f"{ABS_REPO_DIR}/folder/excluded.po"], + "above": 0, + "below": 100, + "fuzzy": False, + "hide_reserved": False, + "counts": False, + "offline": True, +} def test_txt_output(capsys): exec_potodo( - path=FIXTURE_DIR / REPO_DIR, - exclude=[], - above=0, - below=100, - fuzzy=False, - hide_reserved=False, - counts=False, - offline=True, json_format=False, + **config ) captured = capsys.readouterr() + assert "file1.po" in captured.out assert "file2.po" in captured.out assert "# folder" in captured.out assert "file3.po" in captured.out assert "1 fuzzy" in captured.out assert "2 fuzzy" not in captured.out + assert "excluded" not in captured.out def test_output(capsys): exec_potodo( - path=FIXTURE_DIR / REPO_DIR, - exclude=["excluded"], - above=0, - below=100, - fuzzy=False, - hide_reserved=False, - counts=False, - offline=True, json_format=True, + **config ) output = json.loads(capsys.readouterr().out) @@ -49,7 +48,7 @@ def test_output(capsys): "files": [ { "name": "folder/file3", - "path": str(FIXTURE_DIR / REPO_DIR / "folder" / "file3.po"), + "path": f"{ABS_REPO_DIR}/folder/file3.po", "entries": 1, "fuzzies": 0, "translated": 0, @@ -64,7 +63,7 @@ def test_output(capsys): "files": [ { "name": f"{REPO_DIR}/file1", - "path": str(FIXTURE_DIR / REPO_DIR / "file1.po"), + "path": f"{ABS_REPO_DIR}/file1.po", "entries": 3, "fuzzies": 1, "translated": 1, @@ -73,7 +72,7 @@ def test_output(capsys): }, { "name": f"{REPO_DIR}/file2", - "path": str(FIXTURE_DIR / REPO_DIR / "file2.po"), + "path": f"{ABS_REPO_DIR}/file2.po", "entries": 1, "fuzzies": 0, "translated": 0, @@ -84,4 +83,4 @@ def test_output(capsys): }, ] - assert expected == output + assert output == expected