From e8869624427012d1c0a087af2e52924175a6f252 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Sat, 6 Jan 2024 15:42:53 +0100 Subject: [PATCH] Fix bug in tests --- tests/conftest.py | 9 +++++++-- tests/unit/test_diff_grouper.py | 7 +++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c7f44601..7aead5fe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -291,10 +291,13 @@ def _(code: str, has_branches: bool = True) -> coverage_module.Coverage: ) line_number = 0 # (we start at 0 because the first line will be empty for readabilty) - for line in code.splitlines()[1:]: + for line in code.splitlines(): line = line.strip() + if not line: + continue if line.startswith("# file: "): current_file = pathlib.Path(line.split("# file: ")[1]) + line_number = 0 continue assert current_file, (line, current_file, code) line_number += 1 @@ -383,8 +386,10 @@ def _(code: str) -> tuple[coverage_module.Coverage, coverage_module.DiffCoverage current_file = None # (we start at 0 because the first line will be empty for readabilty) line_number = 0 - for line in code.splitlines()[1:]: + for line in code.splitlines(): line = line.strip() + if not line: + continue if line.startswith("# file: "): new_code += line + "\n" current_file = pathlib.Path(line.split("# file: ")[1]) diff --git a/tests/unit/test_diff_grouper.py b/tests/unit/test_diff_grouper.py index 404d56c7..2050f9d6 100644 --- a/tests/unit/test_diff_grouper.py +++ b/tests/unit/test_diff_grouper.py @@ -24,8 +24,7 @@ def test_group_annotations_more_files( ) assert list(result) == [ - groups.Group(file=pathlib.Path("codebase/code.py"), line_start=6, line_end=8), - groups.Group( - file=pathlib.Path("codebase/other.py"), line_start=17, line_end=17 - ), + groups.Group(file=pathlib.Path("codebase/code.py"), line_start=5, line_end=8), + groups.Group(file=pathlib.Path("codebase/other.py"), line_start=1, line_end=1), + groups.Group(file=pathlib.Path("codebase/other.py"), line_start=3, line_end=5), ]