12
12
BackgroundRun ,
13
13
Choppers ,
14
14
DetectorData ,
15
+ EmptyBeamRun ,
15
16
Filename ,
16
17
Monitor1 ,
17
18
Monitor2 ,
18
19
Monitor3 ,
19
20
MonitorData ,
21
+ MonitorType ,
20
22
NeXusComponentLocationSpec ,
21
23
NeXusName ,
22
24
NeXusTransformation ,
25
+ RunType ,
23
26
SampleRun ,
24
27
TimeInterval ,
28
+ TransmissionMonitor ,
25
29
)
26
30
from ess .reduce .nexus .workflow import (
27
31
GenericNeXusWorkflow ,
@@ -574,16 +578,11 @@ def test_generic_nexus_workflow_load_analyzers() -> None:
574
578
assert analyzer ['usage' ] == 'Bragg'
575
579
576
580
577
- def test_generic_nexus_workflow_raises_if_monitor_types_but_not_run_types_given () -> (
578
- None
579
- ):
580
- with pytest .raises (ValueError , match = 'run_types' ):
581
- GenericNeXusWorkflow (monitor_types = [Monitor1 ])
582
-
583
-
584
581
def test_generic_nexus_workflow_includes_only_given_run_and_monitor_types () -> None :
585
582
wf = GenericNeXusWorkflow (run_types = [SampleRun ], monitor_types = [Monitor1 , Monitor3 ])
586
583
graph = wf .underlying_graph
584
+
585
+ # Check some examples to avoid relying entirely on complicated loops below.
587
586
assert DetectorData [SampleRun ] in graph
588
587
assert DetectorData [BackgroundRun ] not in graph
589
588
assert MonitorData [SampleRun , Monitor1 ] in graph
@@ -592,7 +591,11 @@ def test_generic_nexus_workflow_includes_only_given_run_and_monitor_types() -> N
592
591
assert MonitorData [BackgroundRun , Monitor1 ] not in graph
593
592
assert MonitorData [BackgroundRun , Monitor2 ] not in graph
594
593
assert MonitorData [BackgroundRun , Monitor3 ] not in graph
595
- # Many other keys are also removed, this is just an example
594
+ assert Choppers [SampleRun ] in graph
595
+ assert Choppers [BackgroundRun ] not in graph
596
+ assert Analyzers [SampleRun ] in graph
597
+ assert Analyzers [BackgroundRun ] not in graph
598
+
596
599
assert NeXusComponentLocationSpec [Monitor1 , SampleRun ] in graph
597
600
assert NeXusComponentLocationSpec [Monitor2 , SampleRun ] not in graph
598
601
assert NeXusComponentLocationSpec [Monitor3 , SampleRun ] in graph
@@ -605,3 +608,66 @@ def test_generic_nexus_workflow_includes_only_given_run_and_monitor_types() -> N
605
608
assert NeXusComponentLocationSpec [snx .NXdetector , BackgroundRun ] not in graph
606
609
assert NeXusComponentLocationSpec [snx .NXsample , BackgroundRun ] not in graph
607
610
assert NeXusComponentLocationSpec [snx .NXsource , BackgroundRun ] not in graph
611
+
612
+ excluded_run_types = set (RunType .__constraints__ ) - {SampleRun }
613
+ excluded_monitor_types = set (MonitorType .__constraints__ ) - {Monitor1 , Monitor3 }
614
+ for node in graph :
615
+ assert_not_contains_type_arg (node , excluded_run_types )
616
+ assert_not_contains_type_arg (node , excluded_monitor_types )
617
+
618
+
619
+ def test_generic_nexus_workflow_includes_only_given_run_types () -> None :
620
+ wf = GenericNeXusWorkflow (run_types = [EmptyBeamRun ])
621
+ graph = wf .underlying_graph
622
+
623
+ # Check some examples to avoid relying entirely on complicated loops below.
624
+ assert DetectorData [EmptyBeamRun ] in graph
625
+ assert DetectorData [SampleRun ] not in graph
626
+ assert MonitorData [EmptyBeamRun , Monitor1 ] in graph
627
+ assert MonitorData [EmptyBeamRun , Monitor2 ] in graph
628
+ assert MonitorData [EmptyBeamRun , Monitor3 ] in graph
629
+ assert MonitorData [SampleRun , Monitor1 ] not in graph
630
+ assert MonitorData [SampleRun , Monitor2 ] not in graph
631
+ assert MonitorData [SampleRun , Monitor3 ] not in graph
632
+ assert Choppers [EmptyBeamRun ] in graph
633
+ assert Choppers [SampleRun ] not in graph
634
+ assert Analyzers [EmptyBeamRun ] in graph
635
+ assert Analyzers [SampleRun ] not in graph
636
+
637
+ excluded_run_types = set (RunType .__constraints__ ) - {EmptyBeamRun }
638
+ for node in graph :
639
+ assert_not_contains_type_arg (node , excluded_run_types )
640
+
641
+
642
+ def test_generic_nexus_workflow_includes_only_given_monitor_types () -> None :
643
+ wf = GenericNeXusWorkflow (monitor_types = [TransmissionMonitor , Monitor1 ])
644
+ graph = wf .underlying_graph
645
+
646
+ # Check some examples to avoid relying entirely on complicated loops below.
647
+ assert DetectorData [SampleRun ] in graph
648
+ assert DetectorData [BackgroundRun ] in graph
649
+ assert MonitorData [SampleRun , TransmissionMonitor ] in graph
650
+ assert MonitorData [SampleRun , Monitor1 ] in graph
651
+ assert MonitorData [SampleRun , Monitor2 ] not in graph
652
+ assert MonitorData [SampleRun , Monitor3 ] not in graph
653
+ assert MonitorData [BackgroundRun , TransmissionMonitor ] in graph
654
+ assert MonitorData [BackgroundRun , Monitor1 ] in graph
655
+ assert MonitorData [BackgroundRun , Monitor2 ] not in graph
656
+ assert MonitorData [BackgroundRun , Monitor3 ] not in graph
657
+ assert Choppers [SampleRun ] in graph
658
+ assert Choppers [BackgroundRun ] in graph
659
+ assert Analyzers [SampleRun ] in graph
660
+ assert Analyzers [BackgroundRun ] in graph
661
+
662
+ excluded_monitor_types = set (MonitorType .__constraints__ ) - {
663
+ Monitor1 ,
664
+ TransmissionMonitor ,
665
+ }
666
+ for node in graph :
667
+ assert_not_contains_type_arg (node , excluded_monitor_types )
668
+
669
+
670
+ def assert_not_contains_type_arg (node : object , excluded : set [type ]) -> None :
671
+ assert not any (
672
+ arg in excluded for arg in getattr (node , "__args__" , ())
673
+ ), f"Node { node } contains one of { excluded !r} "
0 commit comments