All good.

This commit is contained in:
antoine 2020-06-03 22:18:36 +02:00
parent 5bc330575a
commit dbd8e514f5
5 changed files with 42 additions and 24 deletions

View File

@ -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

View File

@ -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(

View File

@ -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 ""

View File

@ -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 ""

View File

@ -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