Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 31 additions & 36 deletions tests/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down