Skip to content

Commit 7c4683a

Browse files
committed
Adding tests
1 parent f9e3fdf commit 7c4683a

7 files changed

Lines changed: 720 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
***implementation reqs***
2+
3+
- Leaf implementation requirement.
4+
5+
***functional specs***
6+
7+
- Leaf functionality one.
8+
9+
- Leaf functionality two.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
requires:
3+
- pr_leaf
4+
---
5+
6+
***implementation reqs***
7+
8+
- Middle implementation requirement.
9+
10+
***functional specs***
11+
12+
- Middle functionality one.
13+
14+
- Middle functionality two.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
requires:
3+
- pr_middle
4+
---
5+
6+
***implementation reqs***
7+
8+
- Root implementation requirement.
9+
10+
***functional specs***
11+
12+
- Root functionality one.
13+
14+
- Root functionality two.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
***implementation reqs***
2+
3+
- Solo implementation requirement.
4+
5+
***functional specs***
6+
7+
- Solo functionality one.
8+
9+
- Solo functionality two.
10+
11+
- Solo functionality three.

tests/test_git_utils.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
REFACTORED_CODE_COMMIT_MESSAGE,
1313
add_all_files_and_commit,
1414
diff,
15+
get_last_finished_frid,
1516
init_git_repo,
1617
revert_changes,
1718
revert_to_commit_with_frid,
@@ -456,3 +457,73 @@ def test_revert_to_base_folder_no_commit(temp_repo):
456457
assert repo.active_branch.name == "main"
457458
assert len(list(repo.iter_commits())) == 1 # initial commit
458459
assert not file_path.exists()
460+
461+
462+
def test_get_last_finished_frid_non_existent_path():
463+
"""Return (None, None) when the repo path doesn't exist."""
464+
assert get_last_finished_frid("/path/that/does/not/exist") == (None, None)
465+
466+
467+
def test_get_last_finished_frid_empty_repo(empty_repo):
468+
"""Return (None, None) when no FRID-finished commit exists."""
469+
assert get_last_finished_frid(empty_repo) == (None, None)
470+
471+
472+
def test_get_last_finished_frid_returns_latest(empty_repo):
473+
"""Return the module name and frid from the most recent finished-frid commit."""
474+
file_path = Path(empty_repo) / "a.txt"
475+
file_path.write_text("v1")
476+
add_all_files_and_commit(
477+
empty_repo,
478+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("1"),
479+
module_name="module_a",
480+
frid="1",
481+
)
482+
483+
file_path.write_text("v2")
484+
add_all_files_and_commit(
485+
empty_repo,
486+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("2"),
487+
module_name="module_a",
488+
frid="2",
489+
)
490+
491+
assert get_last_finished_frid(empty_repo) == ("module_a", "2")
492+
493+
494+
def test_get_last_finished_frid_ignores_non_finished_commits(empty_repo):
495+
"""Commits that aren't finished-frid checkpoints must be skipped."""
496+
file_path = Path(empty_repo) / "a.txt"
497+
file_path.write_text("v1")
498+
add_all_files_and_commit(
499+
empty_repo,
500+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("1"),
501+
module_name="module_a",
502+
frid="1",
503+
)
504+
505+
# A refactor commit (not a finished-frid checkpoint) comes after.
506+
file_path.write_text("v2")
507+
add_all_files_and_commit(
508+
empty_repo,
509+
REFACTORED_CODE_COMMIT_MESSAGE.format("2"),
510+
module_name="module_a",
511+
frid="2",
512+
)
513+
514+
# The last *finished* FRID is still 1
515+
assert get_last_finished_frid(empty_repo) == ("module_a", "1")
516+
517+
518+
def test_get_last_finished_frid_without_module_name(empty_repo):
519+
"""If the commit omits the module name line, return None for the module."""
520+
file_path = Path(empty_repo) / "a.txt"
521+
file_path.write_text("v1")
522+
add_all_files_and_commit(
523+
empty_repo,
524+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format("7"),
525+
module_name=None,
526+
frid="7",
527+
)
528+
529+
assert get_last_finished_frid(empty_repo) == (None, "7")

0 commit comments

Comments
 (0)