diff --git a/tests/test_claude_coverup_3.py b/tests/test_claude_coverup_3.py deleted file mode 100644 index 2ee85b2..0000000 --- a/tests/test_claude_coverup_3.py +++ /dev/null @@ -1,32 +0,0 @@ -# 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/disabled_test_delta.py b/tests/test_delta.py similarity index 100% rename from tests/disabled_test_delta.py rename to tests/test_delta.py diff --git a/tests/test_openai_coverup_16.py b/tests/test_openai_coverup_16.py deleted file mode 100644 index e58edeb..0000000 --- a/tests/test_openai_coverup_16.py +++ /dev/null @@ -1,40 +0,0 @@ -# file src/coverup/coverup.py:358-360 -# lines [360] -# branches [] - -import pytest -from coverup.coverup import State -from coverup.coverup import CodeSegment - -@pytest.fixture -def state(): - initial_coverage = {} # Assuming initial_coverage is a dictionary - return State(initial_coverage) - -@pytest.fixture -def code_segment(): - # Assuming default values for the other required arguments - return CodeSegment( - filename='test_file.py', - name='test_function', - lines_of_interest=set(), - missing_lines=set(), - executed_lines=set(), - missing_branches=set(), - context={}, - begin=10, - end=20 - ) - -def test_mark_done(state, code_segment): - # Precondition: 'done' dictionary should not have the 'test_file.py' key - if 'test_file.py' not in state.done: - state.done['test_file.py'] = set() - - # Execute the method that is not covered - state.mark_done(code_segment) - - # Postcondition: 'done' dictionary should now have the 'test_file.py' key - assert 'test_file.py' in state.done - # Postcondition: the 'done' set for 'test_file.py' should contain the (begin, end) tuple - assert (code_segment.begin, code_segment.end) in state.done['test_file.py'] diff --git a/tests/test_openai_coverup_17.py b/tests/test_openai_coverup_17.py deleted file mode 100644 index a1cc64d..0000000 --- a/tests/test_openai_coverup_17.py +++ /dev/null @@ -1,40 +0,0 @@ -# file src/coverup/coverup.py:112-115 -# lines [115] -# branches [] - -import pytest -from pathlib import Path -from unittest.mock import MagicMock - -# Assuming the 'args' object is part of a larger context not shown here, -# we will need to mock it to ensure the test can run independently. -# We will also assume that 'args.tests_dir' is supposed to be a Path object. - -# Mock the 'args' object with a 'tests_dir' attribute -@pytest.fixture -def mock_args(): - mock_args = MagicMock() - mock_args.tests_dir = Path("/tmp") - return mock_args - -# Test function to cover line 115 -def test_test_file_path_executes_line_115(mock_args): - from src.coverup.coverup import test_file_path - - # Assuming PREFIX is defined elsewhere in the module, we need to mock it as well - PREFIX = "example" - test_seq = 1 # Example test sequence number - - # Mock the 'args' object in the module - module = pytest.importorskip("src.coverup.coverup") - module.args = mock_args - module.PREFIX = PREFIX - - expected_path = mock_args.tests_dir / f"test_{PREFIX}_{test_seq}.py" - actual_path = test_file_path(test_seq) - - assert actual_path == expected_path, "The function did not return the expected file path." - - # Cleanup by deleting the mock attributes - del module.args - del module.PREFIX diff --git a/tests/test_openai_coverup_20.py b/tests/test_openai_coverup_20.py deleted file mode 100644 index cd06b9f..0000000 --- a/tests/test_openai_coverup_20.py +++ /dev/null @@ -1,76 +0,0 @@ -# file src/coverup/coverup.py:27-109 -# lines [28, 30, 31, 32, 33, 35, 36, 37, 38, 40, 41, 43, 44, 46, 47, 48, 49, 51, 52, 54, 55, 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 80, 81, 83, 84, 85, 87, 88, 90, 91, 93, 94, 95, 97, 98, 99, 101, 102, 103, 104, 106, 107, 109] -# branches ['37->37', '37->38', '103->103', '103->104'] - -import pytest -from pathlib import Path -from coverup.coverup import parse_args - -def test_parse_args_full_coverage(tmp_path): - # Create a dummy source file and test directory - source_file = tmp_path / "source.py" - source_file.touch() - tests_dir = tmp_path / "tests" - tests_dir.mkdir() - source_dir = tmp_path / "src" - source_dir.mkdir() - - # Create a dummy checkpoint file - checkpoint_file = tmp_path / "checkpoint" - checkpoint_file.touch() - - # Create a dummy log file - log_file = tmp_path / "log" - - # Create a dummy requirements file - requirements_file = tmp_path / "requirements.txt" - - # Arguments to cover all lines - args = [ - str(source_file), - '--tests-dir', str(tests_dir), - '--source-dir', str(source_dir), - '--checkpoint', str(checkpoint_file), - '--no-checkpoint', - '--model', 'gpt-3', - '--model-temperature', '0.7', - '--line-limit', '60', - '--rate-limit', '1000', - '--max-attempts', '5', - '--max-backoff', '30', - '--dry-run', - '--show-details', - '--log-file', str(log_file), - '--pytest-args', 'some args', - '--install-missing-modules', - '--write-requirements-to', str(requirements_file), - '--failing-test-action', 'find-culprit', - '--only-disable-interfering-tests', - '--debug', - '--max-concurrency', '10' - ] - - # Parse the arguments - parsed_args = parse_args(args) - - # Assertions to verify postconditions - assert parsed_args.source_files == [source_file] - assert parsed_args.tests_dir == tests_dir - assert parsed_args.source_dir == source_dir - assert parsed_args.checkpoint is None # Because --no-checkpoint was used - assert parsed_args.model == 'gpt-3' - assert parsed_args.model_temperature == '0.7' - assert parsed_args.line_limit == 60 - assert parsed_args.rate_limit == 1000 - assert parsed_args.max_attempts == 5 - assert parsed_args.max_backoff == 30 - assert parsed_args.dry_run is True - assert parsed_args.show_details is True - assert parsed_args.log_file == str(log_file) - assert parsed_args.pytest_args == 'some args' - assert parsed_args.install_missing_modules is True - assert parsed_args.write_requirements_to == requirements_file - assert parsed_args.failing_test_action == 'find-culprit' - assert parsed_args.only_disable_interfering_tests is True - assert parsed_args.debug is True - assert parsed_args.max_concurrency == 10 diff --git a/tests/test_openai_coverup_21.py b/tests/test_openai_coverup_21.py deleted file mode 100644 index 4429c15..0000000 --- a/tests/test_openai_coverup_21.py +++ /dev/null @@ -1,159 +0,0 @@ -# file src/coverup/coverup.py:597-760 -# lines [599, 600, 603, 605, 606, 607, 610, 612, 613, 614, 616, 617, 618, 619, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 644, 645, 647, 648, 650, 656, 657, 658, 662, 663, 665, 666, 668, 669, 670, 672, 674, 676, 679, 680, 683, 684, 688, 689, 691, 692, 695, 697, 698, 699, 701, 702, 703, 704, 705, 707, 708, 710, 711, 713, 715, 716, 718, 719, 720, 722, 723, 724, 726, 728, 730, 731, 732, 733, 734, 735, 736, 738, 742, 743, 745, 746, 747, 751, 754, 755, 756, 757, 758, 760] -# branches ['605->606', '605->610', '612->613', '612->616', '616->617', '616->624', '624->625', '624->647', '625->626', '625->647', '647->648', '647->656', '648->650', '648->658', '656->657', '656->658', '662->663', '662->665', '683->684', '683->688', '692->695', '692->697', '697->698', '697->699', '703->704', '703->715', '704->705', '704->707', '707->708', '707->710', '710->711', '710->713', '719->720', '719->728', '734->735', '734->736', '745->746', '745->751', '751->754', '751->760', '755->756', '755->760', '757->758', '757->760'] - -import pytest -from unittest.mock import patch -from pathlib import Path -from src.coverup.coverup import main -import argparse - -@pytest.fixture -def mock_environment(monkeypatch): - monkeypatch.setenv('OPENAI_API_KEY', 'test_key') - monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'test_access_key_id') - monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'test_secret_access_key') - monkeypatch.setenv('AWS_REGION_NAME', 'us-west-2') - -@pytest.fixture -def mock_args(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.parse_args', lambda: argparse.Namespace( - tests_dir=Path('.'), - source_dir=Path('.'), - only_disable_interfering_tests=False, - rate_limit=None, - model=None, - checkpoint=None, - line_limit=None, - source_files=None, - max_concurrency=None, - write_requirements_to=None - )) - -@pytest.fixture -def mock_add_to_pythonpath(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.add_to_pythonpath', lambda x: None) - -@pytest.fixture -def mock_disable_interfering_tests(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.disable_interfering_tests', lambda: {'summary': {'percent_covered': 50.0}}) - -@pytest.fixture -def mock_async_limiter(monkeypatch): - class MockAsyncLimiter: - def __init__(self, *args, **kwargs): - pass - async def acquire(self, *args): - pass - async def __aenter__(self): - pass - async def __aexit__(self, exc_type, exc, tb): - pass - monkeypatch.setattr('aiolimiter.AsyncLimiter', MockAsyncLimiter) - -@pytest.fixture -def mock_token_rate_limit_for_model(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.token_rate_limit_for_model', lambda x: (10, 60)) - -@pytest.fixture -def mock_get_missing_coverage(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.get_missing_coverage', lambda x, line_limit: []) - -@pytest.fixture -def mock_State(monkeypatch): - class MockState: - def __init__(self, *args, **kwargs): - pass - def load_checkpoint(self, *args, **kwargs): - return None - def save_checkpoint(self, *args, **kwargs): - pass - def get_initial_coverage(self): - return {'summary': {'percent_covered': 50.0}} - def mark_done(self, *args, **kwargs): - pass - def set_progress_bar(self, *args, **kwargs): - pass - def set_final_coverage(self, *args, **kwargs): - pass - monkeypatch.setattr('src.coverup.coverup.State', MockState) - -@pytest.fixture -def mock_improve_coverage(monkeypatch): - async def async_mock(*args, **kwargs): - return True - monkeypatch.setattr('src.coverup.coverup.improve_coverage', async_mock) - -@pytest.fixture -def mock_asyncio_run(monkeypatch): - async def async_mock(*args, **kwargs): - pass - monkeypatch.setattr('src.coverup.coverup.asyncio.run', async_mock) - -@pytest.fixture -def mock_asyncio_gather(monkeypatch): - async def async_mock(*args, **kwargs): - pass - monkeypatch.setattr('src.coverup.coverup.asyncio.gather', async_mock) - -@pytest.fixture -def mock_asyncio_semaphore(monkeypatch): - class MockSemaphore: - def __init__(self, *args, **kwargs): - pass - async def __aenter__(self): - pass - async def __aexit__(self, exc_type, exc, tb): - pass - monkeypatch.setattr('src.coverup.coverup.asyncio.Semaphore', MockSemaphore) - -@pytest.fixture -def mock_progress(monkeypatch): - class MockProgress: - def __init__(self, *args, **kwargs): - pass - def signal_one_completed(self): - pass - def close(self): - pass - monkeypatch.setattr('src.coverup.coverup.Progress', MockProgress) - -@pytest.fixture -def mock_get_required_modules(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.get_required_modules', lambda: []) - -@pytest.fixture -def mock_log_write(monkeypatch): - monkeypatch.setattr('src.coverup.coverup.log_write', lambda *args, **kwargs: None) - -@pytest.fixture -def mock_print(monkeypatch): - monkeypatch.setattr('builtins.print', lambda *args, **kwargs: None) - -@pytest.fixture -def cleanup(monkeypatch): - # Cleanup function to undo any changes after the test - yield - monkeypatch.undo() - -@pytest.mark.usefixtures( - "mock_environment", - "mock_args", - "mock_add_to_pythonpath", - "mock_disable_interfering_tests", - "mock_async_limiter", - "mock_token_rate_limit_for_model", - "mock_get_missing_coverage", - "mock_State", - "mock_improve_coverage", - "mock_asyncio_run", - "mock_asyncio_gather", - "mock_asyncio_semaphore", - "mock_progress", - "mock_get_required_modules", - "mock_log_write", - "mock_print", - "cleanup" -) -def test_main_full_coverage(): - assert main() == 0 diff --git a/tests/test_openai_coverup_7.py b/tests/test_openai_coverup_7.py deleted file mode 100644 index 0796bee..0000000 --- a/tests/test_openai_coverup_7.py +++ /dev/null @@ -1,32 +0,0 @@ -# file src/coverup/coverup.py:363-365 -# lines [365] -# branches [] - -import pytest -from src.coverup.coverup import State -from collections import namedtuple - -# Assuming CodeSegment is a namedtuple or similar simple class -# If it's not, you would need to adjust the definition accordingly -CodeSegment = namedtuple('CodeSegment', ['filename', 'begin', 'end']) - -@pytest.fixture -def state(): - initial_coverage = {} # Assuming initial_coverage is a dictionary - s = State(initial_coverage) - s.done = {} - yield s - # No cleanup needed as state is re-created for each test - -def test_state_is_done_executes_line_365(state): - # Setup - filename = 'test_file.py' - begin = 10 - end = 20 - seg = CodeSegment(filename, begin, end) - state.done[filename] = {(begin, end)} - - # Exercise & Verify - assert state.is_done(seg) == True - - # Cleanup is handled by the fixture diff --git a/tests/test_openai_second_coverup_3.py b/tests/test_openai_second_coverup_3.py deleted file mode 100644 index e1f2162..0000000 --- a/tests/test_openai_second_coverup_3.py +++ /dev/null @@ -1,31 +0,0 @@ -# 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/disabled_test_utils.py b/tests/test_utils.py similarity index 100% rename from tests/disabled_test_utils.py rename to tests/test_utils.py