@@ -334,7 +334,7 @@ def create_fib_autotem_project_data(
334334 autotem_node .append (project_node )
335335
336336 # Save the mock XML file
337- file = visit_dir / "autotem/visit /ProjectData.dat"
337+ file = visit_dir / f "autotem/{ project_name } /ProjectData.dat"
338338 file .parent .mkdir (parents = True , exist_ok = True )
339339 tree = ET .ElementTree (autotem_node )
340340 ET .indent (tree , space = " " )
@@ -379,7 +379,7 @@ def fib_maps_images(visit_dir: Path):
379379 name = "Electron Snapshot"
380380 if i > 0 :
381381 name += f" ({ i + 1 } )"
382- file = visit_dir / "maps/visit /LayersData/Layer" / f"{ name } .tiff"
382+ file = visit_dir / f "maps/{ project_name } /LayersData/Layer" / f"{ name } .tiff"
383383 if not file .exists ():
384384 file .parent .mkdir (parents = True , exist_ok = True )
385385 file .touch ()
@@ -508,10 +508,41 @@ def test_fib_autotem_context_projectdata(
508508 mock_environment = None
509509 if has_environment :
510510 mock_environment = MagicMock ()
511+ mock_environment .visit = visit_name
511512
512513 # Mock the logger to check that specific logs are called
513514 mock_logger = mocker .patch ("murfey.client.contexts.fib.logger" )
514515
516+ # Mock '_get_source'
517+ mock_get_source = mocker .patch ("murfey.client.contexts.fib._get_source" )
518+ mock_get_source .return_value = tmp_path
519+
520+ # Mock '_file_transferred_to'
521+ mock_file_transferred_to = mocker .patch (
522+ "murfey.client.contexts.fib._file_transferred_to"
523+ )
524+ mock_file_transferred_to .return_value = (
525+ tmp_path
526+ / "fib"
527+ / "data"
528+ / "current_year"
529+ / visit_name
530+ / "autotem"
531+ / project_name
532+ / "ProjectData.dat"
533+ )
534+ # Set the expected output directory to be derived from metadata
535+ output_dir = (
536+ tmp_path
537+ / "fib"
538+ / "data"
539+ / "current_year"
540+ / visit_name
541+ / "processed"
542+ / project_name
543+ / "grid_2"
544+ )
545+
515546 # Mock the functions used in 'post_transfer'
516547 mock_capture_post = mocker .patch ("murfey.client.contexts.fib.capture_post" )
517548
@@ -536,13 +567,15 @@ def test_fib_autotem_context_projectdata(
536567 token = "" ,
537568 )
538569 if has_drift_correction_images :
570+ # Add drift correction images
539571 for i in range (num_lamellae ):
540572 context ._drift_correction_images [i + 1 ] = FIBImage (
541573 images = [tmp_path / "dummy.png" ],
542- output_file = tmp_path / "dc_image.gif" ,
574+ output_file = None ,
543575 is_submitted = False ,
544576 )
545577
578+ # Run 'post_transfer' and check for expected calls and outputs
546579 context .post_transfer (mock_projectdata , environment = mock_environment )
547580
548581 # Check the success case
@@ -558,11 +591,15 @@ def test_fib_autotem_context_projectdata(
558591 has_activity_name ,
559592 )
560593 ):
594+ # 'capture_post' should be called once when registering the site
595+ # and again if registering a drift correction image
561596 assert mock_capture_post .call_count == num_lamellae * (
562597 2 if has_drift_correction_images else 1
563598 )
599+ # There should be one dictionary entry for each lamella now
564600 assert len (context ._site_info ) == num_lamellae
565601 for i in range (num_lamellae ):
602+ lamella_number = i + 1
566603 mock_capture_post .assert_any_call (
567604 base_url = mock .ANY ,
568605 router_name = "workflow_fib.router" ,
@@ -572,7 +609,10 @@ def test_fib_autotem_context_projectdata(
572609 data = mock .ANY ,
573610 session_id = mock .ANY ,
574611 )
575- mock_logger .info .assert_any_call (f"Updating metadata for site { i + 1 } " )
612+ mock_logger .info .assert_any_call (
613+ f"Updating metadata for site { lamella_number } "
614+ )
615+
576616 if has_drift_correction_images :
577617 mock_capture_post .assert_any_call (
578618 base_url = mock .ANY ,
@@ -581,9 +621,13 @@ def test_fib_autotem_context_projectdata(
581621 token = mock .ANY ,
582622 instrument_name = mock .ANY ,
583623 data = {
584- "lamella_number" : i + 1 ,
624+ "lamella_number" : lamella_number ,
585625 "images" : [str (tmp_path / "dummy.png" )],
586- "output_file" : str (tmp_path / "dc_image.gif" ),
626+ "output_file" : str (
627+ output_dir
628+ / "drift_correction"
629+ / f"lamella_{ lamella_number } .gif"
630+ ),
587631 },
588632 session_id = mock .ANY ,
589633 )
@@ -612,7 +656,7 @@ def test_fib_autotem_context_projectdata(
612656 )
613657 mock_capture_post .assert_not_called ()
614658 # These fail cases will produce LamellaSiteInfo dicts with default values
615- # "post_transfer " will still be called
659+ # "capture_post " will still be called
616660 elif not has_recipe_name :
617661 mock_logger .warning .assert_any_call ("Recipe doesn't have a name, skipping" )
618662 assert mock_capture_post .call_count == num_lamellae
@@ -734,22 +778,22 @@ def test_fib_autotem_context_drift_correction_images(
734778 mock_logger .warning .assert_called_with (f"No source found for file { file } " )
735779 elif not find_dst :
736780 mock_logger .warning .assert_called_with (
737- f"File { file .name !r} not found on storage system "
781+ f"Could not find destination file path for { file .name !r} "
738782 )
739783 elif not has_site_info :
740784 mock_logger .debug .assert_called_with (
741785 f"No metadata found for site { lamella_num } yet"
742786 )
743787 elif not has_project_name :
744- mock_logger .warning .assert_called_with (
788+ mock_logger .warning .assert_any_call (
745789 f"No project name associated with site { lamella_num } "
746790 )
747791 elif not has_stage_position :
748- mock_logger .warning .assert_called_with (
792+ mock_logger .warning .assert_any_call (
749793 f"No stage position information associated with site { lamella_num } "
750794 )
751795 elif not has_stage_values :
752- mock_logger .warning .assert_called_with (
796+ mock_logger .warning .assert_any_call (
753797 f"Could not determine slot number of site { lamella_num } "
754798 )
755799 else :
0 commit comments