def test_there_are_duplicated_names(): seg1 = Segment("name1", "", "") seg2 = Segment("name2", "", "") elements = ["elem1", "elem2"] assert not segment_by_segment._there_are_duplicated_names([seg1, seg2], elements) elements = ["elem1", "name2"] assert segment_by_segment._there_are_duplicated_names([seg1, seg2], elements)
def test_segment_models_returns_properly(_segment_models_dir): seg = Segment("IP1", "", "") seg_mdls = SegmentModels(_segment_models_dir, seg) seg_mdls.front.BETX seg_mdls.back.BETX seg_mdls.front_corrected.BETX seg_mdls.back_corrected.BETX
def test_improve_segment_raises_on_all_bad(_test_df_just_names): seg = Segment("IP1", "BPM3", "BPM4") with pytest.raises(SbsDefinitionError): segment_by_segment.improve_segment( seg, _test_df_just_names, _test_df_just_names, # All BPMs are bad: lambda name, _: False)
def test_improve_segment_removes_and_wraps(_test_df_just_names): seg = Segment("IP1", "BPM3", "BPM4") new_seg = segment_by_segment.improve_segment( seg, _test_df_just_names, _test_df_just_names, lambda name, _: name not in ("BPM1", "BPM2", "BPM3")) assert new_seg.name == seg.name # BPMs 1, 2 or 3 are wrong so it should wrap around to BPM6: assert new_seg.start == "BPM6" assert new_seg.end == seg.end
def test_improve_segment_removes_backwards(_test_df_just_names): seg = Segment("IP1", "BPM3", "BPM4") new_seg = segment_by_segment.improve_segment( seg, _test_df_just_names, _test_df_just_names, lambda name, _: name != "BPM3") assert new_seg.name == seg.name # BPM3 is wrong so it should jump it: assert new_seg.start == "BPM2" assert new_seg.end == seg.end
def test_improve_segment_for_elements(): seg = Segment("element", "element", "element") test_mdl = pd.DataFrame( {"NAME": ["BPM1", "BPM2", "BPM3", "element", "BPM4", "BPM5", "BPM6"]}) new_seg = segment_by_segment.improve_segment( seg, test_mdl, None, lambda name, _: name.startswith("BPM")) assert new_seg.name == seg.name assert new_seg.element == seg.element assert new_seg.start == "BPM3" assert new_seg.end == "BPM4"
def test_improve_segment_same_if_all_good(_test_df_just_names): seg = Segment("IP1", "BPM3", "BPM4") new_seg = segment_by_segment.improve_segment( seg, _test_df_just_names, _test_df_just_names, # All BPMs are good: lambda name, _: True) assert new_seg.name == seg.name assert new_seg.start == seg.start assert new_seg.end == seg.end
def test_segment_models_empty_dir(): seg = Segment("IP1", "", "") seg_mdls = SegmentModels(os.path.join(CURRENT_DIR, "meas_dir_empty"), seg) with pytest.raises(IOError): seg_mdls.front