def test_GIVEN_group_with_nx_class_as_bytes_WHEN_getting_nx_class_THEN_returns_nx_class_as_str( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") nx_class = b"NXentry" entry.attrs["NX_class"] = nx_class assert get_nx_class(entry) == str(nx_class, encoding="utf-8")
def test_GIVEN_multiple_entry_groups_in_file_WHEN_finding_entry_THEN_signal_is_emitted_with_entry_options( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") # Test with byte string as well as python string. entry.attrs["NX_class"] = b"NXentry" inst_group = entry.create_group("instrument") inst_group.attrs["NX_class"] = "NXinstrument" entry2 = file.create_group("entry2") entry2.attrs["NX_class"] = "NXentry" inst_group2 = entry2.create_group("instrument2") inst_group2.attrs["NX_class"] = "NXinstrument" wrapper = NexusWrapper(filename="test_nw7") wrapper.show_entries_dialog = Mock() wrapper.show_entries_dialog.emit = Mock() wrapper.find_entries_in_file(file) expected_entry_dict = {entry.name: entry, entry2.name: entry2} assert wrapper.show_entries_dialog.emit.called_once_with( expected_entry_dict, file)
def nexus_disk_chopper(): with InMemoryFile("test_disk_chopper") as nexus_file: disk_chopper_group = nexus_file.create_group("Disk Chopper") disk_chopper_group[NAME] = "abc" disk_chopper_group[SLITS_NAME] = N_SLITS disk_chopper_group[SLIT_EDGES_NAME] = RADIANS_EDGES_ARR disk_chopper_group[RADIUS_NAME] = RADIUS_LENGTH disk_chopper_group[SLIT_HEIGHT_NAME] = SLIT_HEIGHT_LENGTH disk_chopper_group[SLIT_EDGES_NAME].attrs["units"] = str.encode("rad") disk_chopper_group[RADIUS_NAME].attrs["units"] = str.encode("m") disk_chopper_group[SLIT_HEIGHT_NAME].attrs["units"] = str.encode("m") yield disk_chopper_group
def test_GIVEN_entry_group_with_one_instrument_group_WHEN_getting_instrument_group_from_entry_THEN_group_is_returned( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") entry.attrs["NX_class"] = "NXentry" inst_group = entry.create_group("instrument") inst_group.attrs["NX_class"] = "NXinstrument" wrapper = NexusWrapper(filename="test_nw") wrapper.load_file(entry, file) assert wrapper.instrument == inst_group assert wrapper.entry == entry assert wrapper.nexus_file == file
def test_GIVEN_single_entry_group_with_instrument_group_WHEN_finding_entry_THEN_file_is_loaded_correctly( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") entry.attrs["NX_class"] = "NXentry" inst_group = entry.create_group("instrument") inst_group.attrs["NX_class"] = "NXinstrument" wrapper = NexusWrapper(filename="test_nw5") wrapper.find_entries_in_file(file) assert wrapper.nexus_file == file assert wrapper.entry == entry assert wrapper.instrument == inst_group
def test_GIVEN_multiple_entry_groups_WHEN_getting_instrument_group_from_entry_THEN_first_group_is_returned_and_others_are_ignored( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") entry.attrs["NX_class"] = "NXentry" inst_group = entry.create_group("instrument") inst_group.attrs["NX_class"] = "NXinstrument" inst_group2 = entry.create_group("instrument2") inst_group2.attrs["NX_class"] = "NXinstrument" wrapper = NexusWrapper(filename="test_nw2") wrapper.load_file(entry, file) assert wrapper.nexus_file == file assert wrapper.entry == entry assert wrapper.instrument == inst_group
def test_GIVEN_group_without_nx_class_WHEN_getting_nx_class_THEN_returns_none( ): with InMemoryFile("test_file") as file: entry = file.create_group("entry") assert get_nx_class(entry) is None