def test_sdds_write_read_str_input(self, _sdds_file_str, tmp_file): original = read_sdds(_sdds_file_str) write_sdds(original, tmp_file) new = read_sdds(tmp_file) for definition, value in original: new_def, new_val = new[definition.name] assert new_def.name == definition.name assert new_def.type == definition.type assert np.all(value == new_val)
def test_sdds_write_read_write_little_endian(self, _sdds_file_little_endian, tmp_file): original = read_sdds(_sdds_file_little_endian) write_sdds(original, tmp_file) # written as big-endian new = read_sdds(tmp_file) # read as big-endian for definition, value in original: new_def, new_val = new[definition.name] assert new_def.name == definition.name assert new_def.type == definition.type assert np.all(value == new_val)
def template_ascii_read_write_read(self, filepath, output): original = read_sdds(filepath) write_sdds(original, output) new = read_sdds(output) for definition, value in original: new_def, new_val = new[definition.name] assert new_def.name == definition.name assert new_def.type == definition.type if not isinstance(value, np.ndarray): values_equal = np.isclose(value, new_val, atol=0.0001) elif isinstance(value[0], np.str_): values_equal = all([a == b for a, b in zip(value, new_val)]) else: values_equal = np.isclose(value, new_val, atol=0.0001).all() print(values_equal) assert values_equal
def test_sdds_read_little_endian_as_big_endian(self, _sdds_file_little_endian): with pytest.raises(struct.error) as e: read_sdds(_sdds_file_little_endian, endianness='big') assert "buffer" in str(e)
def test_sdds_read_big_endian_as_little_endian(self, _sdds_file_pathlib): with pytest.raises(ValueError) as e: read_sdds(_sdds_file_pathlib, endianness='little') assert "buffer size" in str(e)
def test_sdds_read_big_endian(self, _sdds_file_pathlib): read_sdds(_sdds_file_pathlib)
def test_sdds_read_little_endian(self, _sdds_file_little_endian): read_sdds(_sdds_file_little_endian)