From f7e5b88a958a5d79ed155b3ca51585293d912d00 Mon Sep 17 00:00:00 2001 From: Emery Berger Date: Sun, 24 Mar 2024 13:30:52 -0400 Subject: [PATCH] Updated, more coverage via running on different model and reiterating. --- tests/disabled_test_delta.py | 39 +++++++++++++ tests/disabled_test_utils.py | 57 +++++++++++++++++++ tests/test_claude_coverup_1.py | 20 +++++++ tests/test_claude_coverup_2.py | 14 +++++ tests/test_claude_coverup_3.py | 32 +++++++++++ tests/test_claude_coverup_4.py | 28 +++++++++ tests/test_claude_coverup_5.py | 27 +++++++++ tests/test_claude_coverup_6.py | 23 ++++++++ tests/test_claude_coverup_7.py | 17 ++++++ tests/test_claude_coverup_8.py | 17 ++++++ tests/test_claude_coverup_9.py | 23 ++++++++ ..._coverup_1.py => test_openai_coverup_1.py} | 0 ...overup_10.py => test_openai_coverup_10.py} | 0 ...overup_11.py => test_openai_coverup_11.py} | 0 ...overup_12.py => test_openai_coverup_12.py} | 0 ...overup_13.py => test_openai_coverup_13.py} | 0 ...overup_14.py => test_openai_coverup_14.py} | 0 ...overup_15.py => test_openai_coverup_15.py} | 0 ...overup_16.py => test_openai_coverup_16.py} | 0 ...overup_17.py => test_openai_coverup_17.py} | 0 ...overup_18.py => test_openai_coverup_18.py} | 0 ...overup_19.py => test_openai_coverup_19.py} | 0 ..._coverup_2.py => test_openai_coverup_2.py} | 0 ...overup_20.py => test_openai_coverup_20.py} | 0 ...overup_21.py => test_openai_coverup_21.py} | 0 ..._coverup_3.py => test_openai_coverup_3.py} | 0 ..._coverup_4.py => test_openai_coverup_4.py} | 0 ..._coverup_5.py => test_openai_coverup_5.py} | 0 ..._coverup_6.py => test_openai_coverup_6.py} | 0 ..._coverup_7.py => test_openai_coverup_7.py} | 0 ..._coverup_8.py => test_openai_coverup_8.py} | 0 ..._coverup_9.py => test_openai_coverup_9.py} | 0 tests/test_openai_second_coverup_1.py | 24 ++++++++ tests/test_openai_second_coverup_2.py | 24 ++++++++ tests/test_openai_second_coverup_3.py | 31 ++++++++++ tests/test_openai_second_coverup_4.py | 21 +++++++ tests/test_openai_second_coverup_5.py | 38 +++++++++++++ 37 files changed, 435 insertions(+) create mode 100644 tests/disabled_test_delta.py create mode 100644 tests/disabled_test_utils.py create mode 100644 tests/test_claude_coverup_1.py create mode 100644 tests/test_claude_coverup_2.py create mode 100644 tests/test_claude_coverup_3.py create mode 100644 tests/test_claude_coverup_4.py create mode 100644 tests/test_claude_coverup_5.py create mode 100644 tests/test_claude_coverup_6.py create mode 100644 tests/test_claude_coverup_7.py create mode 100644 tests/test_claude_coverup_8.py create mode 100644 tests/test_claude_coverup_9.py rename tests/{test_coverup_1.py => test_openai_coverup_1.py} (100%) rename tests/{test_coverup_10.py => test_openai_coverup_10.py} (100%) rename tests/{test_coverup_11.py => test_openai_coverup_11.py} (100%) rename tests/{test_coverup_12.py => test_openai_coverup_12.py} (100%) rename tests/{test_coverup_13.py => test_openai_coverup_13.py} (100%) rename tests/{test_coverup_14.py => test_openai_coverup_14.py} (100%) rename tests/{test_coverup_15.py => test_openai_coverup_15.py} (100%) rename tests/{test_coverup_16.py => test_openai_coverup_16.py} (100%) rename tests/{test_coverup_17.py => test_openai_coverup_17.py} (100%) rename tests/{test_coverup_18.py => test_openai_coverup_18.py} (100%) rename tests/{test_coverup_19.py => test_openai_coverup_19.py} (100%) rename tests/{test_coverup_2.py => test_openai_coverup_2.py} (100%) rename tests/{test_coverup_20.py => test_openai_coverup_20.py} (100%) rename tests/{test_coverup_21.py => test_openai_coverup_21.py} (100%) rename tests/{test_coverup_3.py => test_openai_coverup_3.py} (100%) rename tests/{test_coverup_4.py => test_openai_coverup_4.py} (100%) rename tests/{test_coverup_5.py => test_openai_coverup_5.py} (100%) rename tests/{test_coverup_6.py => test_openai_coverup_6.py} (100%) rename tests/{test_coverup_7.py => test_openai_coverup_7.py} (100%) rename tests/{test_coverup_8.py => test_openai_coverup_8.py} (100%) rename tests/{test_coverup_9.py => test_openai_coverup_9.py} (100%) create mode 100644 tests/test_openai_second_coverup_1.py create mode 100644 tests/test_openai_second_coverup_2.py create mode 100644 tests/test_openai_second_coverup_3.py create mode 100644 tests/test_openai_second_coverup_4.py create mode 100644 tests/test_openai_second_coverup_5.py diff --git a/tests/disabled_test_delta.py b/tests/disabled_test_delta.py new file mode 100644 index 0000000..f300ef1 --- /dev/null +++ b/tests/disabled_test_delta.py @@ -0,0 +1,39 @@ +import pytest +from hypothesis import given, strategies as st +from pathlib import Path +from coverup.delta import DeltaDebugger + + +class NumbersFinder(DeltaDebugger): + def __init__(self, numbers: set): + super().__init__(trace=print) + self._numbers = numbers + + def test(self, testset: set, **kwargs) -> bool: + return self._numbers.issubset(testset) + + +@given(st.integers(0, 50)) +def test_single(culprit): + nf = NumbersFinder({culprit}) + assert {culprit} == nf.debug(set(range(51))) + + +@given(st.lists(st.integers(0, 50), min_size=2).filter(lambda n: len(set(n)) == len(n))) +def test_multiple(nums): + nf = NumbersFinder({*nums}) + assert {*nums} == nf.debug(set(range(51))) + + +@given(st.lists(st.integers(0, 50), min_size=2).filter(lambda n: len(set(n)) == len(n))) +def test_kwargs_passed_through(nums): + class DD(NumbersFinder): + def __init__(self, numbers: set): + super().__init__({*nums}) + + def test(self, testset: set, **kwargs) -> bool: + assert 'foo' in kwargs + return super().test(testset) + + dd = DD({*nums}) + assert {*nums} == dd.debug(set(range(51)), foo=True) diff --git a/tests/disabled_test_utils.py b/tests/disabled_test_utils.py new file mode 100644 index 0000000..378def0 --- /dev/null +++ b/tests/disabled_test_utils.py @@ -0,0 +1,57 @@ +import pytest +from hypothesis import given, strategies as st +from pathlib import Path +from coverup import utils +import subprocess + +def test_format_ranges(): + assert "" == utils.format_ranges(set(), set()) + assert "1-5" == utils.format_ranges({1,2,3,5}, set()) + assert "1-3, 5" == utils.format_ranges({1,2,3,5}, {4}) + assert "1-6, 10-11, 30" == utils.format_ranges({1,2,4,5,6,10,11,30}, {8,14,15,16,17}) + + +@given(st.integers(0, 10000), st.integers(1, 10000)) +def test_format_ranges_is_sorted(a, b): + b = a+b + assert f"{a}-{b}" == utils.format_ranges({i for i in range(a,b+1)}, set()) + + +def test_lines_branches_do(): + assert "line 123 does" == utils.lines_branches_do({123}, set(), set()) + assert "lines 123-125, 199 do" == utils.lines_branches_do({123,124,125,199}, {128}, set()) + assert "branch 1->5 does" == utils.lines_branches_do(set(), set(), {(1,5)}) + assert "branches 1->2, 1->5 do" == utils.lines_branches_do(set(), set(), {(1,5),(1,2)}) + assert "line 123 and branches 1->exit, 1->2 do" == utils.lines_branches_do({123}, set(), {(1,2),(1,0)}) + assert "lines 123-124 and branch 1->exit do" == utils.lines_branches_do({123, 124}, set(), {(1,0)}) + assert "lines 123-125 and branches 1->exit, 1->2 do" == utils.lines_branches_do({123,124,125}, set(), {(1,2),(1,0)}) + + # if a line doesn't execute, neither do the branches that touch it... + assert "lines 123-125 do" == utils.lines_branches_do({123,124,125}, set(), {(123,124), (10,125)}) + + +@pytest.mark.parametrize('check', [False, True]) +@pytest.mark.asyncio +async def test_subprocess_run(check): + p = await utils.subprocess_run(['/bin/echo', 'hi!'], check=check) + assert p.stdout == b"hi!\n" + + +@pytest.mark.asyncio +async def test_subprocess_run_fails_checked(): + with pytest.raises(subprocess.CalledProcessError) as e: + await utils.subprocess_run(['/usr/bin/false'], check=True) + + assert e.value.stdout == b"" + + +@pytest.mark.asyncio +async def test_subprocess_run_fails_not_checked(): + p = await utils.subprocess_run(['/usr/bin/false']) + assert p.returncode != 0 + + +@pytest.mark.asyncio +async def test_subprocess_run_timeout(): + with pytest.raises(subprocess.TimeoutExpired) as e: + await utils.subprocess_run(['/bin/sleep', '2'], timeout=1) diff --git a/tests/test_claude_coverup_1.py b/tests/test_claude_coverup_1.py new file mode 100644 index 0000000..dca43bf --- /dev/null +++ b/tests/test_claude_coverup_1.py @@ -0,0 +1,20 @@ +# file src/coverup/llm.py:47-51 +# lines [48, 49, 51] +# branches ['48->49', '48->51'] + +import pytest +from unittest.mock import patch +from coverup.llm import token_rate_limit_for_model + +@pytest.fixture +def mock_model_rate_limits(): + with patch('coverup.llm.MODEL_RATE_LIMITS', {'model_a': {'token': (10, 20)}, 'model_b': {'token': (30, 40)}}): + yield + +def test_token_rate_limit_for_model(mock_model_rate_limits): + # Test case when model_name is in MODEL_RATE_LIMITS + assert token_rate_limit_for_model('model_a') == (10, 20) + assert token_rate_limit_for_model('model_b') == (30, 40) + + # Test case when model_name is not in MODEL_RATE_LIMITS + assert token_rate_limit_for_model('unknown_model') is None diff --git a/tests/test_claude_coverup_2.py b/tests/test_claude_coverup_2.py new file mode 100644 index 0000000..e158a18 --- /dev/null +++ b/tests/test_claude_coverup_2.py @@ -0,0 +1,14 @@ +# file src/coverup/utils.py:49-51 +# lines [50, 51] +# branches ['50->exit', '50->51'] + +import pytest +from coverup.utils import format_branches + +@pytest.fixture +def mock_branches(): + return [(1, 2), (3, 0), (5, 6)] + +def test_format_branches(mock_branches): + formatted_branches = list(format_branches(mock_branches)) + assert formatted_branches == ['1->2', '3->exit', '5->6'] diff --git a/tests/test_claude_coverup_3.py b/tests/test_claude_coverup_3.py new file mode 100644 index 0000000..2ee85b2 --- /dev/null +++ b/tests/test_claude_coverup_3.py @@ -0,0 +1,32 @@ +# file src/coverup/utils.py:6-23 +# lines [9, 10, 11, 14, 15, 17, 18, 21, 22, 23] +# branches ['14->15', '14->17', '22->exit', '22->23'] + +import pytest +from pathlib import Path +from tempfile import TemporaryDirectory +from coverup.utils import TemporaryOverwrite + +@pytest.fixture +def temp_dir(): + with TemporaryDirectory() as tmp_dir: + yield Path(tmp_dir) + +def test_temporary_overwrite(temp_dir, monkeypatch): + # Create a temporary file + file_path = temp_dir / "test_file.txt" + file_path.write_text("Initial content") + + # Mock the Path.exists method + monkeypatch.setattr(Path, "exists", lambda self: True) + + # Test the TemporaryOverwrite context manager + new_content = "New content" + with TemporaryOverwrite(file_path, new_content): + # Verify that the file content was overwritten + assert file_path.read_text() == new_content + + # Verify that the file was restored to its original content + assert file_path.read_text() == "Initial content" + + # Clean up the \ No newline at end of file diff --git a/tests/test_claude_coverup_4.py b/tests/test_claude_coverup_4.py new file mode 100644 index 0000000..2c1a07c --- /dev/null +++ b/tests/test_claude_coverup_4.py @@ -0,0 +1,28 @@ +# file src/coverup/coverup.py:203-222 +# lines [204, 206, 207, 208, 209, 211, 213, 214, 215, 216, 217, 219, 220, 222] +# branches ['213->214', '213->222', '214->215', '214->219', '215->213', '215->216', '216->215', '216->217', '219->213', '219->220'] + +import ast +import pytest +from coverup.coverup import find_imports + +@pytest.fixture +def python_code_with_syntax_error(): + return "invalid python code" + +@pytest.fixture +def python_code_with_imports(): + return """ +import os +import sys +from pathlib import Path +import re +""" + +def test_find_imports_with_syntax_error(python_code_with_syntax_error): + result = find_imports(python_code_with_syntax_error) + assert result == [] + +def test_find_imports_with_valid_code(python_code_with_imports): + result = find_imports(python_code_with_imports) + assert set(result) == {"os", "sys", "pathlib", "re"} diff --git a/tests/test_claude_coverup_5.py b/tests/test_claude_coverup_5.py new file mode 100644 index 0000000..503ed30 --- /dev/null +++ b/tests/test_claude_coverup_5.py @@ -0,0 +1,27 @@ +# file src/coverup/coverup.py:333-338 +# lines [335, 336, 337, 338] +# branches ['336->exit', '336->337'] + +import pytest +from unittest.mock import Mock +from coverup.coverup import State, Progress + +@pytest.fixture +def state(): + return State(initial_coverage=0.0) + +def test_set_progress_bar_with_bar(state): + mock_bar = Mock(spec=Progress) + state.usage = 'some_usage' + state.counters = {'key': 'value'} + + state.set_progress_bar(mock_bar) + + assert state.bar == mock_bar + mock_bar.update_usage.assert_called_once_with('some_usage') + mock_bar.update_counters.assert_called_once_with({'key': 'value'}) + +def test_set_progress_bar_without_bar(state): + state.set_progress_bar(None) + + assert state.bar is None diff --git a/tests/test_claude_coverup_6.py b/tests/test_claude_coverup_6.py new file mode 100644 index 0000000..b7ea1c6 --- /dev/null +++ b/tests/test_claude_coverup_6.py @@ -0,0 +1,23 @@ +# file src/coverup/coverup.py:590-594 +# lines [591, 592, 593, 594] +# branches [] + +import sys +from pathlib import Path +from unittest.mock import patch +import os +from coverup import coverup + +def test_add_to_pythonpath(tmp_path): + source_dir = tmp_path / "source" + source_dir.mkdir() + + with patch.dict('os.environ', {'PYTHONPATH': '/existing/path'}): + coverup.add_to_pythonpath(source_dir) + assert str(source_dir.parent) in sys.path[0] + assert os.environ['PYTHONPATH'] == f"{str(source_dir.parent)}:/existing/path" + + with patch.dict('os.environ', clear=True): + coverup.add_to_pythonpath(source_dir) + assert str(source_dir.parent) in sys.path[0] + assert os.environ['PYTHONPATH'] == str(source_dir.parent) diff --git a/tests/test_claude_coverup_7.py b/tests/test_claude_coverup_7.py new file mode 100644 index 0000000..eefad81 --- /dev/null +++ b/tests/test_claude_coverup_7.py @@ -0,0 +1,17 @@ +# file src/coverup/coverup.py:323-325 +# lines [325] +# branches [] + +import pytest +from unittest.mock import Mock +from coverup.coverup import State + +@pytest.fixture +def state(): + initial_coverage = {"line1": True, "line2": False} + state = State(initial_coverage) + return state + +def test_get_initial_coverage(state): + expected_coverage = {"line1": True, "line2": False} + assert state.get_initial_coverage() == expected_coverage diff --git a/tests/test_claude_coverup_8.py b/tests/test_claude_coverup_8.py new file mode 100644 index 0000000..131b09f --- /dev/null +++ b/tests/test_claude_coverup_8.py @@ -0,0 +1,17 @@ +# file src/coverup/coverup.py:328-330 +# lines [330] +# branches [] + +import pytest +from unittest.mock import Mock +from coverup.coverup import State + +@pytest.fixture +def state(): + initial_coverage = Mock() + return State(initial_coverage) + +def test_set_final_coverage(state): + expected_coverage = {'file1.py': 80, 'file2.py': 90} + state.set_final_coverage(expected_coverage) + assert state.final_coverage == expected_coverage diff --git a/tests/test_claude_coverup_9.py b/tests/test_claude_coverup_9.py new file mode 100644 index 0000000..db7e285 --- /dev/null +++ b/tests/test_claude_coverup_9.py @@ -0,0 +1,23 @@ +# file src/coverup/coverup.py:254-256 +# lines [256] +# branches [] + +import pytest +import typing as T +from unittest.mock import patch, MagicMock +from coverup.coverup import get_required_modules + +@pytest.fixture +def mock_module_available(): + return { + 'module1': 1, + 'module2': 0, + 'module3': 1, + 'module4': 0 + } + +def test_get_required_modules(mock_module_available): + with patch('coverup.coverup.module_available', new=mock_module_available): + result = get_required_modules() + expected = ['module2', 'module4'] + assert sorted(result) == sorted(expected) diff --git a/tests/test_coverup_1.py b/tests/test_openai_coverup_1.py similarity index 100% rename from tests/test_coverup_1.py rename to tests/test_openai_coverup_1.py diff --git a/tests/test_coverup_10.py b/tests/test_openai_coverup_10.py similarity index 100% rename from tests/test_coverup_10.py rename to tests/test_openai_coverup_10.py diff --git a/tests/test_coverup_11.py b/tests/test_openai_coverup_11.py similarity index 100% rename from tests/test_coverup_11.py rename to tests/test_openai_coverup_11.py diff --git a/tests/test_coverup_12.py b/tests/test_openai_coverup_12.py similarity index 100% rename from tests/test_coverup_12.py rename to tests/test_openai_coverup_12.py diff --git a/tests/test_coverup_13.py b/tests/test_openai_coverup_13.py similarity index 100% rename from tests/test_coverup_13.py rename to tests/test_openai_coverup_13.py diff --git a/tests/test_coverup_14.py b/tests/test_openai_coverup_14.py similarity index 100% rename from tests/test_coverup_14.py rename to tests/test_openai_coverup_14.py diff --git a/tests/test_coverup_15.py b/tests/test_openai_coverup_15.py similarity index 100% rename from tests/test_coverup_15.py rename to tests/test_openai_coverup_15.py diff --git a/tests/test_coverup_16.py b/tests/test_openai_coverup_16.py similarity index 100% rename from tests/test_coverup_16.py rename to tests/test_openai_coverup_16.py diff --git a/tests/test_coverup_17.py b/tests/test_openai_coverup_17.py similarity index 100% rename from tests/test_coverup_17.py rename to tests/test_openai_coverup_17.py diff --git a/tests/test_coverup_18.py b/tests/test_openai_coverup_18.py similarity index 100% rename from tests/test_coverup_18.py rename to tests/test_openai_coverup_18.py diff --git a/tests/test_coverup_19.py b/tests/test_openai_coverup_19.py similarity index 100% rename from tests/test_coverup_19.py rename to tests/test_openai_coverup_19.py diff --git a/tests/test_coverup_2.py b/tests/test_openai_coverup_2.py similarity index 100% rename from tests/test_coverup_2.py rename to tests/test_openai_coverup_2.py diff --git a/tests/test_coverup_20.py b/tests/test_openai_coverup_20.py similarity index 100% rename from tests/test_coverup_20.py rename to tests/test_openai_coverup_20.py diff --git a/tests/test_coverup_21.py b/tests/test_openai_coverup_21.py similarity index 100% rename from tests/test_coverup_21.py rename to tests/test_openai_coverup_21.py diff --git a/tests/test_coverup_3.py b/tests/test_openai_coverup_3.py similarity index 100% rename from tests/test_coverup_3.py rename to tests/test_openai_coverup_3.py diff --git a/tests/test_coverup_4.py b/tests/test_openai_coverup_4.py similarity index 100% rename from tests/test_coverup_4.py rename to tests/test_openai_coverup_4.py diff --git a/tests/test_coverup_5.py b/tests/test_openai_coverup_5.py similarity index 100% rename from tests/test_coverup_5.py rename to tests/test_openai_coverup_5.py diff --git a/tests/test_coverup_6.py b/tests/test_openai_coverup_6.py similarity index 100% rename from tests/test_coverup_6.py rename to tests/test_openai_coverup_6.py diff --git a/tests/test_coverup_7.py b/tests/test_openai_coverup_7.py similarity index 100% rename from tests/test_coverup_7.py rename to tests/test_openai_coverup_7.py diff --git a/tests/test_coverup_8.py b/tests/test_openai_coverup_8.py similarity index 100% rename from tests/test_coverup_8.py rename to tests/test_openai_coverup_8.py diff --git a/tests/test_coverup_9.py b/tests/test_openai_coverup_9.py similarity index 100% rename from tests/test_coverup_9.py rename to tests/test_openai_coverup_9.py diff --git a/tests/test_openai_second_coverup_1.py b/tests/test_openai_second_coverup_1.py new file mode 100644 index 0000000..2d17fe2 --- /dev/null +++ b/tests/test_openai_second_coverup_1.py @@ -0,0 +1,24 @@ +# file src/coverup/coverup.py:27-109 +# lines [] +# branches ['37->37', '103->103'] + +import pytest +from pathlib import Path +from unittest.mock import patch +from coverup.coverup import parse_args + +def test_parse_args_with_invalid_dir_and_negative_int(tmp_path): + invalid_dir = tmp_path / "invalid_dir" + invalid_dir_file = tmp_path / "invalid_file.txt" + invalid_dir_file.touch() + + with pytest.raises(SystemExit): + parse_args(['--tests-dir', str(invalid_dir), '--source-dir', str(tmp_path)]) + + with pytest.raises(SystemExit): + parse_args(['--tests-dir', str(tmp_path), '--source-dir', str(invalid_dir_file)]) + + with pytest.raises(SystemExit): + parse_args(['--max-concurrency', '-1']) + + # Cleanup is not necessary as tmp_path is a fixture that automatically handles isolation diff --git a/tests/test_openai_second_coverup_2.py b/tests/test_openai_second_coverup_2.py new file mode 100644 index 0000000..496dc6e --- /dev/null +++ b/tests/test_openai_second_coverup_2.py @@ -0,0 +1,24 @@ +# file src/coverup/utils.py:26-46 +# lines [40] +# branches ['39->40'] + +import pytest +from coverup.utils import format_ranges + +def test_format_ranges_single_line(): + lines = {1, 2, 4} + negative = {3} + expected = "1-2, 4" + assert format_ranges(lines, negative) == expected + +def test_format_ranges_with_negative_gap(): + lines = {1, 2, 4, 5} + negative = {3} + expected = "1-2, 4-5" + assert format_ranges(lines, negative) == expected + +def test_format_ranges_with_negative_gap_yielding_single_line(): + lines = {1, 3, 5} + negative = {2, 4} + expected = "1, 3, 5" + assert format_ranges(lines, negative) == expected diff --git a/tests/test_openai_second_coverup_3.py b/tests/test_openai_second_coverup_3.py new file mode 100644 index 0000000..e1f2162 --- /dev/null +++ b/tests/test_openai_second_coverup_3.py @@ -0,0 +1,31 @@ +# file src/coverup/utils.py:6-23 +# lines [] +# branches ['14->17', '22->exit'] + +import pytest +from pathlib import Path +from coverup.utils import TemporaryOverwrite + +@pytest.fixture +def temp_file(tmp_path): + file = tmp_path / "test.txt" + file.write_text("original content") + return file + +@pytest.fixture +def non_existing_file(tmp_path): + return tmp_path / "non_existing.txt" + +def test_temporary_overwrite_with_existing_file(temp_file): + new_content = "new content" + with TemporaryOverwrite(temp_file, new_content) as overwrite: + assert temp_file.read_text() == new_content + assert temp_file.read_text() == "original content" + assert not (temp_file.parent / (temp_file.name + ".bak")).exists() + +def test_temporary_overwrite_with_non_existing_file(non_existing_file): + new_content = "new content" + with TemporaryOverwrite(non_existing_file, new_content) as overwrite: + assert non_existing_file.read_text() == new_content + assert not non_existing_file.exists() + assert not (non_existing_file.parent / (non_existing_file.name + ".bak")).exists() diff --git a/tests/test_openai_second_coverup_4.py b/tests/test_openai_second_coverup_4.py new file mode 100644 index 0000000..3e3449e --- /dev/null +++ b/tests/test_openai_second_coverup_4.py @@ -0,0 +1,21 @@ +# file src/coverup/delta.py:5-32 +# lines [16] +# branches ['13->16'] + +import pytest +from pathlib import Path +from src.coverup.delta import _compact + +def test_compact_with_path_without_number(tmp_path): + # Create a temporary file without a number in its name + temp_file = tmp_path / "test_file.py" + temp_file.touch() + + # Call the _compact function with a set containing the Path + result = _compact({temp_file}) + + # Assert that the result contains the name of the temporary file + assert temp_file.name in result + + # Clean up the temporary file + temp_file.unlink() diff --git a/tests/test_openai_second_coverup_5.py b/tests/test_openai_second_coverup_5.py new file mode 100644 index 0000000..055ebe6 --- /dev/null +++ b/tests/test_openai_second_coverup_5.py @@ -0,0 +1,38 @@ +# file src/coverup/testrunner.py:86-100 +# lines [] +# branches ['96->91'] + +import pytest +from pathlib import Path +from unittest.mock import MagicMock +from coverup.testrunner import BadTestsFinder + +def test_missing_branch(tmp_path): + # Create a directory structure with files that should and should not be found + tests_dir = tmp_path / "tests" + tests_dir.mkdir() + (tests_dir / "test_included.py").touch() + (tests_dir / "included_test.py").touch() + (tests_dir / "not_a_test.txt").touch() + (tests_dir / "test_not_included.txt").touch() + sub_dir = tests_dir / "subdir" + sub_dir.mkdir() + (sub_dir / "test_included.py").touch() + (sub_dir / "included_test.py").touch() + (sub_dir / "not_a_test.txt").touch() + + # Mock the DeltaDebugger to avoid side effects + with pytest.MonkeyPatch.context() as m: + m.setattr('coverup.testrunner.DeltaDebugger', MagicMock()) + + # Instantiate BadTestsFinder + finder = BadTestsFinder(tests_dir=tests_dir) + + # Assert that only the correct test files are found + expected_files = { + tests_dir / "test_included.py", + tests_dir / "included_test.py", + sub_dir / "test_included.py", + sub_dir / "included_test.py", + } + assert finder.all_tests == expected_files