From 6ba1122bf295edb8d49a0b9bdcb0cfda0301c89b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:35:45 +0000 Subject: [PATCH 1/2] Initial plan From af7f239eb0a267905bdb0891c0638c1585756332 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:40:11 +0000 Subject: [PATCH 2/2] fix(tests): resolve ruff F821 errors by importing DuplicateTest at module level Co-authored-by: jacobdadams <38168030+jacobdadams@users.noreply.github.com> Agent-Logs-Url: https://github.com/agrc/sweeper/sessions/ba6f55df-5b0c-43fd-a7dd-25596cf24014 --- tests/test_duplicates.py | 67 +++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/tests/test_duplicates.py b/tests/test_duplicates.py index 1012bef..e3acb88 100644 --- a/tests/test_duplicates.py +++ b/tests/test_duplicates.py @@ -3,46 +3,41 @@ import pytest -#: Mock arcpy before importing the module under test +# ruff: isort: off +#: Mock arcpy and its submodules before importing the module under test arcpy_mock = MagicMock() +_MOCK_MODULE_NAMES = [ + "arcpy", + "arcpy.da", + "arcpy._mp", + "arcpy.typing", + "arcpy.typing.gp", + "xxhash", +] +_originals = {name: sys.modules.get(name) for name in _MOCK_MODULE_NAMES} +sys.modules["arcpy"] = arcpy_mock +sys.modules["arcpy.da"] = arcpy_mock.da +sys.modules["arcpy._mp"] = arcpy_mock._mp +sys.modules["arcpy.typing"] = arcpy_mock.typing +sys.modules["arcpy.typing.gp"] = arcpy_mock.typing.gp +sys.modules["xxhash"] = MagicMock() + +from sweeper.sweepers.duplicates import DuplicateTest # noqa: E402 + +# ruff: isort: on @pytest.fixture(autouse=True, scope="module") -def _mock_arcpy_and_xxhash(): - """Mock arcpy (and submodules) and xxhash for this test module only.""" - # Save original modules so we can restore them after the tests run. - module_names = [ - "arcpy", - "arcpy.da", - "arcpy._mp", - "arcpy.typing", - "arcpy.typing.gp", - "xxhash", - ] - originals = {name: sys.modules.get(name) for name in module_names} - - # Install mocks into sys.modules for the duration of this module's tests. - sys.modules["arcpy"] = arcpy_mock - sys.modules["arcpy.da"] = arcpy_mock.da - sys.modules["arcpy._mp"] = arcpy_mock._mp - sys.modules["arcpy.typing"] = arcpy_mock.typing - sys.modules["arcpy.typing.gp"] = arcpy_mock.typing.gp - sys.modules["xxhash"] = MagicMock() - - from sweeper.sweepers.duplicates import DuplicateTest as _DuplicateTest # noqa: E402 - - # Expose DuplicateTest at module level so existing tests continue to work. - globals()["DuplicateTest"] = _DuplicateTest - - try: - yield - finally: - # Restore the original sys.modules entries. - for name, original in originals.items(): - if original is None: - sys.modules.pop(name, None) - else: - sys.modules[name] = original +def _restore_sys_modules(): + """Restore sys.modules entries modified by this module after all tests complete.""" + yield + for name, original in _originals.items(): + if original is None: + sys.modules.pop(name, None) + else: + sys.modules[name] = original + + class TestChunkOidList: def test_chunk_oid_list_small_list_returns_single_chunk(self): lst = [1, 2, 3]