@@ -53,31 +53,59 @@ def test_ingest_summary(path_type: str, path: str, ref_type: str, ref: str) -> N
5353 """
5454 is_main_branch = ref == "main"
5555 is_blob = path_type == "blob"
56- expected_lines = 7 - int ( is_main_branch ) - int ( ref_type == "Commit" )
57- expected_parsed = expected_lines - 1
56+ expected_lines = _calculate_expected_lines ( ref_type , is_main_branch = is_main_branch )
57+ expected_non_empty_lines = expected_lines - 1
5858
5959 summary , _ , _ = ingest (f"https://github.com/{ REPO } /{ path_type } /{ ref } { path } " )
6060 lines = summary .splitlines ()
61- parsed = dict (line .split (": " , 1 ) for line in lines if ": " in line )
61+ parsed_lines = dict (line .split (": " , 1 ) for line in lines if ": " in line )
6262
63- assert parsed ["Repository" ] == REPO
63+ assert parsed_lines ["Repository" ] == REPO
6464
6565 if is_main_branch :
6666 # We omit the 'Branch' line for 'main' branches.
67- assert ref_type not in parsed
67+ assert ref_type not in parsed_lines
6868 else :
69- assert parsed [ref_type ] == ref
69+ assert parsed_lines [ref_type ] == ref
7070
7171 if is_blob :
72- assert parsed ["File" ] == Path (path ).name
73- assert "Lines" in parsed
72+ assert parsed_lines ["File" ] == Path (path ).name
73+ assert "Lines" in parsed_lines
7474 else : # 'tree'
75- assert parsed ["Subpath" ] == path
76- assert "Files analyzed" in parsed
75+ assert parsed_lines ["Subpath" ] == path
76+ assert "Files analyzed" in parsed_lines
7777
78- token_match = re .search (r"\d+" , parsed ["Estimated tokens" ])
78+ token_match = re .search (r"\d+" , parsed_lines ["Estimated tokens" ])
7979 assert token_match , "'Estimated tokens' should contain a number"
8080 assert int (token_match .group ()) > 0
8181
8282 assert len (lines ) == expected_lines
83- assert len (parsed ) == expected_parsed
83+ assert len (parsed_lines ) == expected_non_empty_lines
84+
85+
86+ def _calculate_expected_lines (ref_type : str , * , is_main_branch : bool ) -> int :
87+ """Calculate the expected number of lines in the summary.
88+
89+ The total number of lines depends on the following:
90+ - Commit type does not include the 'Branch'/'Tag' line, reducing the count by 1.
91+ - The "main" branch omits the 'Branch' line, reducing the count by 1.
92+
93+ Parameters
94+ ----------
95+ ref_type : str
96+ The type of reference, e.g., "Branch", "Tag", or "Commit".
97+ is_main_branch : bool
98+ True if the reference is the "main" branch, False otherwise.
99+
100+ Returns
101+ -------
102+ int
103+ The expected number of lines in the summary.
104+
105+ """
106+ base_lines = 7
107+ if is_main_branch :
108+ base_lines -= 1
109+ if ref_type == "Commit" :
110+ base_lines -= 1
111+ return base_lines
0 commit comments