diff --git a/src/murfey/client/analyser.py b/src/murfey/client/analyser.py index 6af37d52..c088e1a1 100644 --- a/src/murfey/client/analyser.py +++ b/src/murfey/client/analyser.py @@ -145,7 +145,12 @@ def _find_context(self, file_path: Path) -> bool: ) ) ): - self._context = CLEMContext("leica", self._basepath, self._token) + self._context = CLEMContext( + "leica", + self._basepath, + self._murfey_config, + self._token, + ) return True # ----------------------------------------------------------------------------- @@ -161,7 +166,12 @@ def _find_context(self, file_path: Path) -> bool: and "Sites" in file_path.parts ) ): - self._context = FIBContext("autotem", self._basepath, self._token) + self._context = FIBContext( + "autotem", + self._basepath, + self._murfey_config, + self._token, + ) return True # Determine if it's from Maps @@ -173,7 +183,12 @@ def _find_context(self, file_path: Path) -> bool: all(path in file_path.parts for path in ("LayersData", "Layer")) ) ): - self._context = FIBContext("maps", self._basepath, self._token) + self._context = FIBContext( + "maps", + self._basepath, + self._murfey_config, + self._token, + ) return True # Determine if it's from Meteor @@ -181,14 +196,24 @@ def _find_context(self, file_path: Path) -> bool: # Image metadata stored in "features.json" file file_path.name == "features.json" or () ): - self._context = FIBContext("meteor", self._basepath, self._token) + self._context = FIBContext( + "meteor", + self._basepath, + self._murfey_config, + self._token, + ) return True # ----------------------------------------------------------------------------- # SXT workflow checks # ----------------------------------------------------------------------------- if file_path.suffix in (".txrm", ".xrm"): - self._context = SXTContext("zeiss", self._basepath, self._token) + self._context = SXTContext( + "zeiss", + self._basepath, + self._murfey_config, + self._token, + ) return True # ----------------------------------------------------------------------------- @@ -196,12 +221,20 @@ def _find_context(self, file_path: Path) -> bool: # ----------------------------------------------------------------------------- if "atlas" in file_path.parts: self._context = AtlasContext( - "serialem" if self._serialem else "epu", self._basepath, self._token + "serialem" if self._serialem else "epu", + self._basepath, + self._murfey_config, + self._token, ) return True if "Metadata" in file_path.parts or file_path.name == "EpuSession.dm": - self._context = SPAMetadataContext("epu", self._basepath, self._token) + self._context = SPAMetadataContext( + "epu", + self._basepath, + self._murfey_config, + self._token, + ) return True elif ( "Batch" in file_path.parts @@ -210,7 +243,10 @@ def _find_context(self, file_path: Path) -> bool: or file_path.name == "Session.dm" ): self._context = TomographyMetadataContext( - "tomo", self._basepath, self._token + "tomo", + self._basepath, + self._murfey_config, + self._token, ) return True @@ -228,7 +264,10 @@ def _find_context(self, file_path: Path) -> bool: if not self._context: logger.info("Acquisition software: EPU") self._context = SPAModularContext( - "epu", self._basepath, self._token + "epu", + self._basepath, + self._murfey_config, + self._token, ) self.parameters_model = ProcessingParametersSPA return True @@ -244,7 +283,10 @@ def _find_context(self, file_path: Path) -> bool: if not self._context: logger.info("Acquisition software: tomo") self._context = TomographyContext( - "tomo", self._basepath, self._token + "tomo", + self._basepath, + self._murfey_config, + self._token, ) self.parameters_model = ProcessingParametersTomo return True @@ -281,7 +323,10 @@ def _analyse(self): and not self._context ): self._context = SPAMetadataContext( - "epu", self._basepath, self._token + "epu", + self._basepath, + self._murfey_config, + self._token, ) elif ( "Batch" in transferred_file.parts @@ -290,7 +335,10 @@ def _analyse(self): and not self._context ): self._context = TomographyMetadataContext( - "tomo", self._basepath, self._token + "tomo", + self._basepath, + self._murfey_config, + self._token, ) self.post_transfer(transferred_file) else: diff --git a/src/murfey/client/context.py b/src/murfey/client/context.py index 296c1012..1aa4653a 100644 --- a/src/murfey/client/context.py +++ b/src/murfey/client/context.py @@ -8,27 +8,25 @@ import xmltodict from murfey.client.instance_environment import MurfeyInstanceEnvironment, SampleInfo -from murfey.util.client import capture_post, get_machine_config_client +from murfey.util.client import capture_post logger = logging.getLogger("murfey.client.context") def _file_transferred_to( - environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str + environment: MurfeyInstanceEnvironment, + source: Path, + file_path: Path, + rsync_basepath: Path, ): - machine_config = get_machine_config_client( - str(environment.url.geturl()), - token, - instrument_name=environment.instrument_name, - ) if environment.visit in environment.default_destinations[source]: return ( - Path(machine_config.get("rsync_basepath", "")) + rsync_basepath / Path(environment.default_destinations[source]) / file_path.relative_to(source) # need to strip out the rsync_module name ) return ( - Path(machine_config.get("rsync_basepath", "")) + rsync_basepath / Path(environment.default_destinations[source]) / environment.visit / file_path.relative_to(source) @@ -52,22 +50,19 @@ def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path def _atlas_destination( - environment: MurfeyInstanceEnvironment, source: Path, token: str + environment: MurfeyInstanceEnvironment, + source: Path, + rsync_basepath: Path, ) -> Path: - machine_config = get_machine_config_client( - str(environment.url.geturl()), - token, - instrument_name=environment.instrument_name, - ) for i, destination_part in enumerate( Path(environment.default_destinations[source]).parts ): if destination_part == environment.visit: - return Path(machine_config.get("rsync_basepath", "")) / "/".join( + return rsync_basepath / "/".join( Path(environment.default_destinations[source]).parent.parts[: i + 1] ) return ( - Path(machine_config.get("rsync_basepath", "")) + rsync_basepath / Path(environment.default_destinations[source]).parent / environment.visit ) @@ -77,6 +72,7 @@ def ensure_dcg_exists( collection_type: str, metadata_source: Path, environment: MurfeyInstanceEnvironment, + machine_config: dict, token: str, ) -> str | None: """Create a data collection group""" @@ -183,7 +179,11 @@ def ensure_dcg_exists( "experiment_type_id": experiment_type_id, "tag": dcg_tag, "atlas": str( - _atlas_destination(environment, session_file.parent, token) + _atlas_destination( + environment, + session_file.parent, + Path(machine_config.get("rsync_basepath", "")), + ) / environment.samples[metadata_source].atlas.parent / atlas_xml_path.with_suffix(".jpg").name ).replace("//", "/"), diff --git a/src/murfey/client/contexts/atlas.py b/src/murfey/client/contexts/atlas.py index 86426b38..f4a8f514 100644 --- a/src/murfey/client/contexts/atlas.py +++ b/src/murfey/client/contexts/atlas.py @@ -12,9 +12,16 @@ class AtlasContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("Atlas", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config def post_transfer( self, @@ -69,7 +76,9 @@ def post_transfer_epu( source = _get_source(transferred_file, environment) if source: transferred_atlas_name = _atlas_destination( - environment, source, self._token + environment, + source, + Path(self._machine_config.get("rsync_basepath", "")), ) / transferred_file.relative_to(source.parent) capture_post( base_url=str(environment.url.geturl()), @@ -91,7 +100,9 @@ def post_transfer_epu( if source: atlas_mrc = transferred_file.with_suffix(".mrc") transferred_atlas_jpg = _atlas_destination( - environment, source, self._token + environment, + source, + Path(self._machine_config.get("rsync_basepath", "")), ) / atlas_mrc.relative_to(source.parent).with_suffix(".jpg") with open(transferred_file, "rb") as atlas_xml: diff --git a/src/murfey/client/contexts/clem.py b/src/murfey/client/contexts/clem.py index 4b55fffa..0d789156 100644 --- a/src/murfey/client/contexts/clem.py +++ b/src/murfey/client/contexts/clem.py @@ -12,28 +12,23 @@ from murfey.client.context import Context from murfey.client.instance_environment import MurfeyInstanceEnvironment -from murfey.util.client import capture_post, get_machine_config_client +from murfey.util.client import capture_post # Create logger object logger = logging.getLogger("murfey.client.contexts.clem") def _file_transferred_to( - environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str + environment: MurfeyInstanceEnvironment, + source: Path, + file_path: Path, + rsync_basepath: Path, ) -> Optional[Path]: """ Returns the Path of the transferred file on the DLS file system. """ - machine_config = get_machine_config_client( - str(environment.url.geturl()), - token, - instrument_name=environment.instrument_name, - ) - # Construct destination path - base_destination = Path(machine_config.get("rsync_basepath", "")) / Path( - environment.default_destinations[source] - ) + base_destination = rsync_basepath / Path(environment.default_destinations[source]) # Add visit number to the path if it's not present in default destination if environment.visit not in environment.default_destinations[source]: base_destination = base_destination / environment.visit @@ -87,9 +82,16 @@ def _find_elements_recursively( class CLEMContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("CLEM", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config # CLEM contexts for "auto-save" acquisition mode self._tiff_series: Dict[str, List[str]] = {} # {Series name : TIFF path list} self._series_metadata: Dict[str, str] = {} # {Series name : Metadata file path} @@ -125,7 +127,7 @@ def post_transfer( environment=environment, source=source, file_path=transferred_file, - token=self._token, + rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")), ) if not destination_file: logger.warning( @@ -301,7 +303,7 @@ def post_transfer( environment=environment, source=source, file_path=transferred_file, - token=self._token, + rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")), ) if not destination_file: logger.warning( diff --git a/src/murfey/client/contexts/fib.py b/src/murfey/client/contexts/fib.py index af9e72b0..453ceaec 100644 --- a/src/murfey/client/contexts/fib.py +++ b/src/murfey/client/contexts/fib.py @@ -12,7 +12,7 @@ from murfey.client.context import Context from murfey.client.instance_environment import MurfeyInstanceEnvironment -from murfey.util.client import capture_post, get_machine_config_client +from murfey.util.client import capture_post logger = logging.getLogger("murfey.client.contexts.fib") @@ -72,21 +72,16 @@ def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path def _file_transferred_to( - environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str + environment: MurfeyInstanceEnvironment, + source: Path, + file_path: Path, + rsync_basepath: Path, ) -> Path | None: """ Returns the Path of the transferred file on the DLS file system. """ - machine_config = get_machine_config_client( - str(environment.url.geturl()), - token, - instrument_name=environment.instrument_name, - ) - # Construct destination path - base_destination = Path(machine_config.get("rsync_basepath", "")) / Path( - environment.default_destinations[source] - ) + base_destination = rsync_basepath / Path(environment.default_destinations[source]) # Add visit number to the path if it's not present in default destination if environment.visit not in environment.default_destinations[source]: base_destination = base_destination / environment.visit @@ -161,9 +156,16 @@ def _parse_electron_snapshot_metadata(xml_file: Path): class FIBContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("FIB", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config self._milling: dict[int, list[MillingProgress]] = {} self._lamellae: dict[int, Lamella] = {} self._electron_snapshots: dict[str, Path] = {} @@ -302,7 +304,9 @@ def post_transfer( environment=environment, source=source, file_path=transferred_file, - token=self._token, + rsync_basepath=Path( + self._machine_config.get("rsync_basepath", "") + ), ) ): logger.warning( diff --git a/src/murfey/client/contexts/spa.py b/src/murfey/client/contexts/spa.py index 94c71ce7..2a482cbc 100644 --- a/src/murfey/client/contexts/spa.py +++ b/src/murfey/client/contexts/spa.py @@ -19,7 +19,7 @@ MurfeyID, MurfeyInstanceEnvironment, ) -from murfey.util.client import capture_get, capture_post, get_machine_config_client +from murfey.util.client import capture_get, capture_post from murfey.util.spa_metadata import ( foil_hole_data, foil_hole_from_file, @@ -75,9 +75,16 @@ class SPAModularContext(Context): ProcessingParameter("motion_corr_binning", "Motion Correction Binning"), ] - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("SPA", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config self._processing_job_stash: dict = {} self._foil_holes: dict[int, list[int]] = {} @@ -306,7 +313,10 @@ def _position_analysis( ) image_path = ( _file_transferred_to( - environment, metadata_source, Path(gs.image), self._token + environment, + metadata_source, + Path(gs.image), + Path(self._machine_config.get("rsync_basepath", "")), ) if gs.image else "" @@ -355,7 +365,10 @@ def _position_analysis( ) image_path = ( _file_transferred_to( - environment, metadata_source, Path(fh.image), self._token + environment, + metadata_source, + Path(fh.image), + Path(self._machine_config.get("rsync_basepath", "")), ) if fh.image else "" @@ -414,16 +427,8 @@ def post_transfer( if "gain" not in transferred_file.name: if transferred_file.suffix in data_suffixes: if self._acquisition_software == "epu": - if environment: - machine_config = get_machine_config_client( - str(environment.url.geturl()), - self._token, - instrument_name=environment.instrument_name, - ) - else: - machine_config = {} required_strings = ( - machine_config.get("data_required_substrings", {}) + self._machine_config.get("data_required_substrings", {}) .get("epu", {}) .get(transferred_file.suffix, ["fractions"]) ) @@ -443,7 +448,10 @@ def post_transfer( if environment: file_transferred_to = _file_transferred_to( - environment, source, transferred_file, self._token + environment, + source, + transferred_file, + Path(self._machine_config.get("rsync_basepath", "")), ) if not environment.movie_counters.get(str(source)): movie_counts_get = capture_get( @@ -489,7 +497,10 @@ def post_transfer( try: foil_hole: Optional[int] = self._position_analysis( - transferred_file, environment, source, machine_config + transferred_file, + environment, + source, + self._machine_config, ) except Exception as e: # try to continue if position information gathering fails so that movie is processed anyway diff --git a/src/murfey/client/contexts/spa_metadata.py b/src/murfey/client/contexts/spa_metadata.py index 2cbe9595..68d72889 100644 --- a/src/murfey/client/contexts/spa_metadata.py +++ b/src/murfey/client/contexts/spa_metadata.py @@ -74,9 +74,16 @@ def _foil_hole_positions(xml_path: Path, grid_square: int) -> Dict[str, FoilHole class SPAMetadataContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("SPA_metadata", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config def post_transfer( self, @@ -121,6 +128,7 @@ def post_transfer( collection_type="spa", metadata_source=images_disc, environment=environment, + machine_config=self._machine_config, token=self._token, ) for gs, pos_data in gs_pix_positions.items(): @@ -160,6 +168,7 @@ def post_transfer( collection_type="spa", metadata_source=images_disc, environment=environment, + machine_config=self._machine_config, token=self._token, ) @@ -191,7 +200,10 @@ def post_transfer( ) image_path = ( _file_transferred_to( - environment, source, Path(gs_info.image), self._token + environment, + source, + Path(gs_info.image), + Path(self._machine_config.get("rsync_basepath", "")), ) if gs_info.image else "" diff --git a/src/murfey/client/contexts/sxt.py b/src/murfey/client/contexts/sxt.py index 63b0f583..2bbb4370 100644 --- a/src/murfey/client/contexts/sxt.py +++ b/src/murfey/client/contexts/sxt.py @@ -21,9 +21,16 @@ class SXTContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("SXT", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config def register_sxt_data_collection( self, @@ -46,6 +53,7 @@ def register_sxt_data_collection( collection_type="sxt", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) @@ -203,7 +211,10 @@ def post_transfer( f"The following tilt series will be processed: {transferred_file.stem}" ) file_transferred_to = _file_transferred_to( - environment, source, transferred_file, self._token + environment, + source, + transferred_file, + Path(self._machine_config.get("rsync_basepath", "")), ) capture_post( base_url=str(environment.url.geturl()), diff --git a/src/murfey/client/contexts/tomo.py b/src/murfey/client/contexts/tomo.py index 17edf099..130f1f00 100644 --- a/src/murfey/client/contexts/tomo.py +++ b/src/murfey/client/contexts/tomo.py @@ -15,7 +15,7 @@ MurfeyID, MurfeyInstanceEnvironment, ) -from murfey.util.client import capture_get, capture_post, get_machine_config_client +from murfey.util.client import capture_get, capture_post from murfey.util.mdoc import get_block, get_global_data, get_num_blocks logger = logging.getLogger("murfey.client.contexts.tomo") @@ -77,9 +77,16 @@ class TomographyContext(Context): ProcessingParameter("num_eer_frames", "Number of EER Frames"), ] - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("Tomography", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config self._tilt_series: Dict[str, List[Path]] = {} self._tilt_series_with_pjids: List[str] = [] self._tilt_series_sizes: Dict[str, int] = {} @@ -108,6 +115,7 @@ def register_tomography_data_collections( collection_type="tomo", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) @@ -185,21 +193,20 @@ def register_tomography_data_collections( logger.error(f"ERROR {e}, {self.data_collection_parameters}", exc_info=True) def _file_transferred_to( - self, environment: MurfeyInstanceEnvironment, source: Path, file_path: Path + self, + environment: MurfeyInstanceEnvironment, + source: Path, + file_path: Path, + rsync_basepath: Path, ): - machine_config = get_machine_config_client( - str(environment.url.geturl()), - self._token, - instrument_name=environment.instrument_name, - ) if environment.visit in environment.default_destinations[source]: return ( - Path(machine_config.get("rsync_basepath", "")) + rsync_basepath / Path(environment.default_destinations[source]) / file_path.name ) return ( - Path(machine_config.get("rsync_basepath", "")) + rsync_basepath / Path(environment.default_destinations[source]) / environment.visit / file_path.name @@ -249,7 +256,10 @@ def _add_tilt( if environment: file_transferred_to = self._file_transferred_to( - environment, source, file_path + environment, + source, + file_path, + Path(self._machine_config.get("rsync_basepath", "")), ) environment.movies[file_transferred_to] = MovieTracker( movie_number=next(MovieID), @@ -459,16 +469,8 @@ def post_transfer( if "gain" not in transferred_file.name: if transferred_file.suffix in data_suffixes: if self._acquisition_software == "tomo": - if environment: - machine_config = get_machine_config_client( - str(environment.url.geturl()), - self._token, - instrument_name=environment.instrument_name, - ) - else: - machine_config = {} required_strings = ( - machine_config.get("data_required_substrings", {}) + self._machine_config.get("data_required_substrings", {}) .get("tomo", {}) .get(transferred_file.suffix, ["fractions"]) ) diff --git a/src/murfey/client/contexts/tomo_metadata.py b/src/murfey/client/contexts/tomo_metadata.py index e0d85d16..bd70d672 100644 --- a/src/murfey/client/contexts/tomo_metadata.py +++ b/src/murfey/client/contexts/tomo_metadata.py @@ -19,9 +19,16 @@ class TomographyMetadataContext(Context): - def __init__(self, acquisition_software: str, basepath: Path, token: str): + def __init__( + self, + acquisition_software: str, + basepath: Path, + machine_config: dict, + token: str, + ): super().__init__("Tomography_metadata", acquisition_software, token) self._basepath = basepath + self._machine_config = machine_config def post_transfer( self, @@ -50,6 +57,7 @@ def post_transfer( collection_type="tomo", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) @@ -60,6 +68,7 @@ def post_transfer( collection_type="tomo", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) with open(transferred_file, "r") as sm_xml: @@ -135,7 +144,7 @@ def post_transfer( environment, source, transferred_file.parent / "SearchMap.jpg", - self._token, + Path(self._machine_config.get("rsync_basepath", "")), ) if source else "" @@ -167,6 +176,7 @@ def post_transfer( collection_type="tomo", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) with open(transferred_file, "r") as sm_xml: @@ -223,6 +233,7 @@ def post_transfer( collection_type="tomo", metadata_source=metadata_source, environment=environment, + machine_config=self._machine_config, token=self._token, ) with open(transferred_file) as xml: diff --git a/src/murfey/client/multigrid_control.py b/src/murfey/client/multigrid_control.py index 6bebbdfa..dae25fef 100644 --- a/src/murfey/client/multigrid_control.py +++ b/src/murfey/client/multigrid_control.py @@ -575,6 +575,7 @@ def _start_dc(self, metadata_json): collection_type="spa", metadata_source=metadata_source, environment=self._environment, + machine_config=self._machine_config, token=self.token, ) except Exception as e: diff --git a/tests/client/contexts/test_atlas.py b/tests/client/contexts/test_atlas.py index b56f0162..08c1d9d4 100644 --- a/tests/client/contexts/test_atlas.py +++ b/tests/client/contexts/test_atlas.py @@ -6,10 +6,11 @@ def test_atlas_context_initialisation(tmp_path): - context = AtlasContext("tomo", tmp_path, "token") + context = AtlasContext("tomo", tmp_path, {}, "token") assert context.name == "Atlas" assert context._acquisition_software == "tomo" assert context._basepath == tmp_path + assert context._machine_config == {} assert context._token == "token" @@ -26,7 +27,7 @@ def test_atlas_context_mrc(mock_capture_post, tmp_path): visit="cm12345-6", murfey_session=1, ) - context = AtlasContext("tomo", tmp_path, "token") + context = AtlasContext("tomo", tmp_path, {}, "token") atlas_mrc = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas_1.mrc" atlas_mrc.parent.mkdir(parents=True) @@ -59,7 +60,7 @@ def test_atlas_context_xml(mock_capture_post, tmp_path): visit="cm12345-6", murfey_session=1, ) - context = AtlasContext("tomo", tmp_path, "token") + context = AtlasContext("tomo", tmp_path, {}, "token") atlas_pixel_size = 4.6 atlas_xml = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas_1.xml" diff --git a/tests/client/contexts/test_fib.py b/tests/client/contexts/test_fib.py index 4b009238..035453a4 100644 --- a/tests/client/contexts/test_fib.py +++ b/tests/client/contexts/test_fib.py @@ -243,19 +243,12 @@ def test_get_source( def test_file_transferred_to( - mocker: MockerFixture, tmp_path: Path, visit_dir: Path, fib_maps_images: list[Path], fib_maps_metadata_file: Path, ): - # Mock the machine config and environment - mock_get_machine_config = mocker.patch( - "murfey.client.contexts.fib.get_machine_config_client" - ) - mock_get_machine_config.return_value = { - "rsync_basepath": tmp_path / "fib" / "data", - } + # Mock the environment mock_environment = MagicMock() mock_environment.default_destinations = {visit_dir: "current_year"} mock_environment.visit = "visit" @@ -268,7 +261,7 @@ def test_file_transferred_to( environment=mock_environment, source=visit_dir, file_path=file, - token="", + rsync_basepath=tmp_path / "fib" / "data", ) == destination_dir / file.relative_to(visit_dir) @@ -300,6 +293,7 @@ def test_fib_maps_context( context = FIBContext( acquisition_software="maps", basepath=basepath, + machine_config={}, token="", ) # Assert that its initial state is correct diff --git a/tests/client/contexts/test_sxt.py b/tests/client/contexts/test_sxt.py index f309bc46..c50e18ab 100644 --- a/tests/client/contexts/test_sxt.py +++ b/tests/client/contexts/test_sxt.py @@ -6,8 +6,9 @@ def test_sxt_context_initialisation(tmp_path): - context = SXTContext("zeiss", tmp_path, "") + context = SXTContext("zeiss", tmp_path, {}, "") assert context._acquisition_software == "zeiss" + assert context._machine_config == {} assert context._basepath == tmp_path @@ -23,7 +24,7 @@ def test_sxt_context_xrm(mock_post, tmp_path): visit="test", murfey_session=1, ) - context = SXTContext("zeiss", tmp_path, "") + context = SXTContext("zeiss", tmp_path, {}, "") return_value = context.post_transfer( tmp_path / "example.xrm", required_position_files=[], @@ -61,7 +62,7 @@ def test_sxt_context_txrm( visit="test", murfey_session=1, ) - context = SXTContext("zeiss", tmp_path, "") + context = SXTContext("zeiss", tmp_path, {}, "") context.post_transfer( tmp_path / "example.txrm", required_position_files=[], diff --git a/tests/client/contexts/test_tomo.py b/tests/client/contexts/test_tomo.py index 07713618..611a282a 100644 --- a/tests/client/contexts/test_tomo.py +++ b/tests/client/contexts/test_tomo.py @@ -9,9 +9,10 @@ def test_tomography_context_initialisation_for_tomo(tmp_path): - context = TomographyContext("tomo", tmp_path, "") + context = TomographyContext("tomo", tmp_path, {}, "") assert not context._completed_tilt_series assert context._acquisition_software == "tomo" + assert context._machine_config == {} @patch("requests.get") @@ -28,7 +29,7 @@ def test_tomography_context_add_tomo_tilt(mock_post, mock_get, tmp_path): visit="test", murfey_session=1, ) - context = TomographyContext("tomo", tmp_path, "") + context = TomographyContext("tomo", tmp_path, {}, "") (tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff").touch() context.post_transfer( tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff", @@ -85,7 +86,7 @@ def test_tomography_context_add_tomo_tilt_out_of_order(mock_post, mock_get, tmp_ visit="test", murfey_session=1, ) - context = TomographyContext("tomo", tmp_path, "") + context = TomographyContext("tomo", tmp_path, {}, "") (tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff").touch() context.post_transfer( tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff", @@ -170,7 +171,7 @@ def test_tomography_context_add_tomo_tilt_delayed_tilt(mock_post, mock_get, tmp_ visit="test", murfey_session=1, ) - context = TomographyContext("tomo", tmp_path, "") + context = TomographyContext("tomo", tmp_path, {}, "") (tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff").touch() context.post_transfer( tmp_path / "Position_1_001_[30.0]_date_time_fractions.tiff", @@ -214,7 +215,7 @@ def test_tomography_context_add_tomo_tilt_delayed_tilt(mock_post, mock_get, tmp_ def test_tomography_context_initialisation_for_serialem(tmp_path): - context = TomographyContext("serialem", tmp_path, "") + context = TomographyContext("serialem", tmp_path, {}, "") assert not context._completed_tilt_series assert context._acquisition_software == "serialem" @@ -235,7 +236,7 @@ def test_setting_tilt_series_size_and_completion_from_mdoc_parsing( visit="test", murfey_session=1, ) - context = TomographyContext("tomo", tmp_path, "") + context = TomographyContext("tomo", tmp_path, {}, "") assert len(context._tilt_series_sizes) == 0 context.post_transfer( Path(__file__).parent.parent.parent / "util" / "test_1.mdoc", diff --git a/tests/client/test_context.py b/tests/client/test_context.py index 732ec0f1..1620e563 100644 --- a/tests/client/test_context.py +++ b/tests/client/test_context.py @@ -41,6 +41,7 @@ def test_ensure_dcg_exists_tomo(mock_capture_post, tmp_path): collection_type="tomo", metadata_source=metadata_source, environment=env, + machine_config={}, token="token", ) @@ -101,6 +102,7 @@ def test_ensure_dcg_exists_spa(mock_capture_post, tmp_path): collection_type="spa", metadata_source=metadata_source / "Images-Disc1", environment=env, + machine_config={}, token="token", ) @@ -139,6 +141,7 @@ def test_ensure_dcg_exists_spa_missing_xml(mock_capture_post, tmp_path): collection_type="spa", metadata_source=metadata_source, environment=env, + machine_config={}, token="token", )