feat: set up modularized version of project with testing
This commit is contained in:
commit
7bea08ddac
19 changed files with 1138 additions and 0 deletions
67
tests/test_projects.py
Normal file
67
tests/test_projects.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import pytest
|
||||
|
||||
from timesheets.projects import load_project_map, resolve_project_task
|
||||
|
||||
PROJECT_MAP = {
|
||||
"bugs": {"Project": "[Factry] Historian", "Task": "[Historian] Bugs"},
|
||||
"internal": {"Project": "[Factry] Internal", "Task": ""},
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# load_project_map
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestLoadProjectMap:
|
||||
def test_returns_empty_for_none(self):
|
||||
assert load_project_map(None) == {}
|
||||
|
||||
def test_loads_valid_file(self, tmp_path):
|
||||
f = tmp_path / "map.json"
|
||||
f.write_text('{"bugs": {"Project": "X", "Task": "Y"}}')
|
||||
result = load_project_map(str(f))
|
||||
assert result == {"bugs": {"Project": "X", "Task": "Y"}}
|
||||
|
||||
def test_missing_file_returns_empty(self, tmp_path, capsys):
|
||||
result = load_project_map(str(tmp_path / "nonexistent.json"))
|
||||
assert result == {}
|
||||
assert "Warning" in capsys.readouterr().err
|
||||
|
||||
def test_invalid_json_returns_empty(self, tmp_path, capsys):
|
||||
f = tmp_path / "bad.json"
|
||||
f.write_text("not json{{{")
|
||||
result = load_project_map(str(f))
|
||||
assert result == {}
|
||||
assert "Warning" in capsys.readouterr().err
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# resolve_project_task
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestResolveProjectTask:
|
||||
def test_exact_key_match(self):
|
||||
project, task = resolve_project_task("bugs", PROJECT_MAP)
|
||||
assert project == "[Factry] Historian"
|
||||
assert task == "[Historian] Bugs"
|
||||
|
||||
def test_case_insensitive_lookup(self):
|
||||
project, task = resolve_project_task("BUGS", PROJECT_MAP)
|
||||
assert project == "[Factry] Historian"
|
||||
|
||||
def test_missing_key_returns_raw(self):
|
||||
project, task = resolve_project_task("unknown", PROJECT_MAP)
|
||||
assert project == "unknown"
|
||||
assert task == ""
|
||||
|
||||
def test_empty_task_in_map(self):
|
||||
project, task = resolve_project_task("internal", PROJECT_MAP)
|
||||
assert project == "[Factry] Internal"
|
||||
assert task == ""
|
||||
|
||||
def test_empty_map(self):
|
||||
project, task = resolve_project_task("bugs", {})
|
||||
assert project == "bugs"
|
||||
assert task == ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue