def test_write_anyObj_TypeError(any_obj, tmpdir): """ Check if a TypeError is raised when writing an arbitrary object. """ filename = os.path.join(tmpdir, 'anyObj.far') with pytest.raises(TypeError): io.write(filename, any_obj=any_obj)
def test_write_filterSOS_TypeError(filterSOS, tmpdir): """ FilterIIR Can't be written to disk because objects store user-defined function. """ filename = os.path.join(tmpdir, 'filterSOS.far') with pytest.raises(TypeError): io.write(filename, filterSOS=filterSOS)
def test_write_read_numpy_ndarrays(tmpdir): """ Numpy ndarray Make sure `read` understands the bits written by `write` """ matrix_2d_int = np.arange(0, 24, dtype=np.int).reshape((4, 6)) matrix_2d_float = matrix_2d_int.astype(np.float) matrix_2d_complex = matrix_2d_int.astype(np.complex) matrix_3d_int = np.arange(0, 24, dtype=np.int).reshape((2, 3, 4)) matrix_3d_float = matrix_3d_int.astype(np.float) matrix_3d_complex = matrix_3d_int.astype(np.complex) filename = os.path.join(tmpdir, 'ndarray.far') io.write(filename, matrix_2d_int=matrix_2d_int, matrix_2d_float=matrix_2d_float, matrix_2d_complex=matrix_2d_complex, matrix_3d_int=matrix_3d_int, matrix_3d_float=matrix_3d_float, matrix_3d_complex=matrix_3d_complex) actual = io.read(filename) assert isinstance(actual['matrix_2d_int'], np.ndarray) assert np.allclose(actual['matrix_2d_int'], matrix_2d_int) assert isinstance(actual['matrix_2d_float'], np.ndarray) assert np.allclose(actual['matrix_2d_float'], matrix_2d_float) assert isinstance(actual['matrix_2d_complex'], np.ndarray) assert np.allclose(actual['matrix_2d_complex'], matrix_2d_complex) assert isinstance(actual['matrix_3d_int'], np.ndarray) assert np.allclose(actual['matrix_3d_int'], matrix_3d_int) assert isinstance(actual['matrix_2d_float'], np.ndarray) assert np.allclose(actual['matrix_3d_float'], matrix_3d_float) assert isinstance(actual['matrix_2d_complex'], np.ndarray) assert np.allclose(actual['matrix_3d_complex'], matrix_3d_complex)
def test_write_NoEncode_NotImplemented(no_encode_obj, tmpdir): """ Check if a TypeError is raised when writing an arbitrary object. """ filename = os.path.join(tmpdir, 'no_encode_obj.far') with pytest.raises(NotImplementedError): io.write(filename, no_encode_obj=no_encode_obj)
def test_write_read_multiplePyfarObjectsWithCompression( filter, coordinates, orientations, sphericalvoronoi, timedata, frequencydata, sine_signal, tmpdir): """ Check if multiple different PyFar-objects can be written to disk and read back with zip compression. """ filename = os.path.join(tmpdir, 'multiplePyfarObjects.far') matrix_2d_int = np.arange(0, 24, dtype=np.int).reshape((4, 6)) io.write(filename, compress=True, filter=filter, coordinates=coordinates, orientations=orientations, sphericalvoronoi=sphericalvoronoi, timedata=timedata, frequencydata=frequencydata, signal=sine_signal, matrix_2d_int=matrix_2d_int) actual = io.read(filename) assert isinstance(actual['filter'], fo.Filter) assert actual['filter'] == filter assert isinstance(actual['coordinates'], Coordinates) assert actual['coordinates'] == coordinates assert isinstance(actual['orientations'], Orientations) assert actual['orientations'] == orientations assert isinstance(actual['sphericalvoronoi'], SphericalVoronoi) assert actual['sphericalvoronoi'] == sphericalvoronoi assert isinstance(actual['timedata'], TimeData) assert actual['timedata'] == timedata assert isinstance(actual['frequencydata'], FrequencyData) assert actual['frequencydata'] == frequencydata assert isinstance(actual['signal'], Signal) assert actual['signal'] == sine_signal assert isinstance(actual['matrix_2d_int'], np.ndarray) assert np.allclose(actual['matrix_2d_int'], matrix_2d_int)
def test_write_read_flat_data(tmpdir, flat_data): """ Check if file can be read back after writing without explicitply passing the .far-extension. """ filename = os.path.join(tmpdir, 'write_read_flat_data.far') io.write(filename, flat_data=flat_data) actual = io.read(filename) assert actual['flat_data'] == flat_data
def test_write_read_FlatDataNoDecode_NotImplemented(no_decode_obj, tmpdir): """ Check if a NotImplementedError is raised when writing an arbitrary object. """ filename = os.path.join(tmpdir, 'no_decode_obj.far') io.write(filename, no_decode_obj=no_decode_obj) with pytest.raises(NotImplementedError): io.read(filename)
def test_write_read_coordinates(coordinates, tmpdir): """ Coordinates Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'coordinates.far') io.write(filename, coordinates=coordinates) actual = io.read(filename)['coordinates'] assert isinstance(actual, Coordinates) assert actual == coordinates
def test_write_read_multipleObjects(flat_data, nested_data, tmpdir): """ Check if file can be read back after writing without explicitply passing the .far-extension. """ filename = os.path.join(tmpdir, 'write_read_multipleObjects.far') io.write(filename, any_flat_data=flat_data, any_nested_data=nested_data) actual = io.read(filename) assert actual['any_flat_data'] == flat_data assert actual['any_nested_data'] == nested_data
def test_write_read_sphericalvoronoi(sphericalvoronoi, tmpdir): """ SphericalVoronoi Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'sphericalvoronoi.far') io.write(filename, sphericalvoronoi=sphericalvoronoi) actual = io.read(filename)['sphericalvoronoi'] assert isinstance(actual, SphericalVoronoi) assert actual == sphericalvoronoi
def test_write_read_filter(filter, tmpdir): """ Filter Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'filter.far') io.write(filename, filter=filter) actual = io.read(filename)['filter'] assert isinstance(actual, fo.Filter) assert actual == filter
def test_write_read_frequencydata(frequencydata, tmpdir): """ TimeData Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'frequencydata.far') io.write(filename, frequencydata=frequencydata) actual = io.read(filename)['frequencydata'] assert isinstance(actual, FrequencyData) assert actual == frequencydata
def test_write_read_timedata(timedata, tmpdir): """ TimeData Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'timedata.far') io.write(filename, timedata=timedata) actual = io.read(filename)['timedata'] assert isinstance(actual, TimeData) assert actual == timedata
def test_write_read_signal(sine_signal, tmpdir): """ Signal Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'signal.far') io.write(filename, signal=sine_signal) actual = io.read(filename)['signal'] assert isinstance(actual, Signal) assert actual == sine_signal
def test_write_read_orientations(orientations, tmpdir): """ Orientations Make sure `read` understands the bits written by `write` """ filename = os.path.join(tmpdir, 'orientations.far') io.write(filename, orientations=orientations) actual = io.read(filename)['orientations'] assert isinstance(actual, Orientations) assert actual == orientations
def test_write_read_FlatDataNoPyfarType_TypeError(_, no_decode_obj, tmpdir): """ Check if a TypeError is raised when reading a .far-file that has been created with a different version of Pyfar in which types exist which are not present in the current version. Notes ----- The `42` in `[True] + 42 * [False]` is arbitrary. What matters is, that `_is_pyfar_type` returns True on the first call to enable writing the .far-file which is not compatible with the current version in the first place. """ filename = os.path.join(tmpdir, 'no_decode_obj.far') io.write(filename, no_decode_obj=no_decode_obj) with pytest.raises(TypeError): io.read(filename)
def test_write_read_nested_data(nested_data, flat_data, tmpdir): filename = os.path.join(tmpdir, 'write_nested_flat_data.far') io.write(filename, nested_data=nested_data) actual = io.read(filename) assert actual['nested_data'] == nested_data