Skip to content
Snippets Groups Projects
Verified Commit e4423b01 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Fix mocking pathlib in python < 3.13

parent 52c53ec2
Branches
Tags
1 merge request!73Fix tests
Pipeline #1708353 waiting for manual action
......@@ -1677,13 +1677,12 @@ def _load_spectrum(file: _pathT) -> Dict[str, Any]:
# Patch modules for data saved before move to separate package
renamed_modules = {'qutil.measurement.spectrometer.daq.settings': daq_settings}
target = 'pathlib._local' if sys.version_info >= (3, 13) else 'pathlib'
PATHTYPE = type(Path())
with (
mock.patch.dict(sys.modules, renamed_modules),
mock.patch.multiple('pathlib', WindowsPath=PATHTYPE, PosixPath=PATHTYPE),
mock.patch.multiple('pathlib._local', WindowsPath=PATHTYPE, PosixPath=PATHTYPE,
create=True), # backwards compatibility
mock.patch.multiple(target, WindowsPath=PATHTYPE, PosixPath=PATHTYPE),
np.load(file, allow_pickle=True) as fp,
monkey_patched_io()
):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment