pyfar.testing.stub_utils#

Contains tools to easily generate stubs for the most common pyfar Classes.

Stubs are used instead of pyfar objects for testing functions that have pyfar objects as input arguments. This makes testing such functions independent from the pyfar objects themselves and helps to find bugs.

Classes:

AnyClass([x])

Placeholder class.

FlatData([m])

Class only containing flat data and methods.

NestedData(n, comment, matrix, subobj, ...)

Class containing nested data such as lists, dicts and other objects as well as methods.

NoDecodeClass([x])

Placeholder class to Raise NotImplementedError for _decode.

NoEncodeClass([x])

Placeholder class to Raise NotImplementedError for _encode.

Functions:

any_ndarray()

Return an arbitrary ndarray for testing purposes.

dict_of_builtins()

Return a dictionary that contains all builtin types that can be written to and read from disk.

frequency_data_stub(freq, frequencies)

Function to generate stub of pyfar FrequencyData class based onMagicMock.

impulse_func(delay, n_samples, fft_norm, cshape)

Generate time and frequency data of delta impulse.

noise_func(sigma, n_samples, cshape)

Generate time and frequency data of zero-mean, gaussian white noise, RMS FFT normalization.

signal_stub(time, freq, sampling_rate, fft_norm)

Function to generate stub of pyfar Signal class based on MagicMock.

sine_func(frequency, sampling_rate, ...)

Generate time and frequency data of sine signal.

stub_is_pyfar_type()

Stubs _codec._is_pyfar_type for tests that use general data structures.

stub_str_to_type()

Stubs _codec.str_to_type for tests that use general data structures.

time_data_stub(time, times)

Function to generate stub of pyfar TimeData class based on MagicMock.

class pyfar.testing.stub_utils.AnyClass(x=42)[source]#

Bases: object

Placeholder class.

class pyfar.testing.stub_utils.FlatData(m=49)[source]#

Bases: object

Class only containing flat data and methods.

Methods:

copy()

Return a deep copy of the Orientations object.

copy()[source]#

Return a deep copy of the Orientations object.

class pyfar.testing.stub_utils.NestedData(n, comment, matrix, subobj, mylist, mydict)[source]#

Bases: object

Class containing nested data such as lists, dicts and other objects as well as methods. The purpose of this class is, to define and test general requirements for the encoding and decoding process.

Methods:

copy()

Return a deep copy of the Orientations object.

create()

Create a NestedData object with arbitrary data.

copy()[source]#

Return a deep copy of the Orientations object.

classmethod create()[source]#

Create a NestedData object with arbitrary data.

class pyfar.testing.stub_utils.NoDecodeClass(x=42)[source]#

Bases: object

Placeholder class to Raise NotImplementedError for _decode.

Methods:

copy()

Return a deep copy of the Orientations object.

copy()[source]#

Return a deep copy of the Orientations object.

class pyfar.testing.stub_utils.NoEncodeClass(x=42)[source]#

Bases: object

Placeholder class to Raise NotImplementedError for _encode.

pyfar.testing.stub_utils.any_ndarray()[source]#

Return an arbitrary ndarray for testing purposes.

pyfar.testing.stub_utils.dict_of_builtins()[source]#

Return a dictionary that contains all builtin types that can be written to and read from disk.

pyfar.testing.stub_utils.frequency_data_stub(freq, frequencies)[source]#

Function to generate stub of pyfar FrequencyData class based onMagicMock. The properties of the signal are set without any further check.

Parameters:
  • freq (ndarray) – Frequency data

  • frequencies (ndarray) – Frequencies of freq in Hz

Returns:

stub of pyfar FrequencyData class

Return type:

frequency_data

pyfar.testing.stub_utils.impulse_func(delay, n_samples, fft_norm, cshape)[source]#

Generate time and frequency data of delta impulse.

Parameters:
  • delay (ndarray, int) – Delay in samples

  • n_samples (int) – Number of samples

  • fft_norm ('none', 'rms') – See documentation of pyfar.fft.normalization.

  • cshape (tuple) – Channel shape

Returns:

  • time (ndarray, float) – time vector

  • freq (ndarray, complex) – Spectrum

pyfar.testing.stub_utils.noise_func(sigma, n_samples, cshape)[source]#

Generate time and frequency data of zero-mean, gaussian white noise, RMS FFT normalization.

Parameters:
  • sigma (float) – Standard deviation

  • n_samples (int) – Number of samples

  • cshape (tuple) – Channel shape

Returns:

  • time (ndarray, float) – time vector

  • freq (ndarray, complex) – Spectrum

pyfar.testing.stub_utils.signal_stub(time, freq, sampling_rate, fft_norm, is_complex=False)[source]#

Function to generate stub of pyfar Signal class based on MagicMock. The properties of the signal are set without any further check.

Parameters:
  • time (ndarray) – Time data

  • freq (ndarray) – Frequency data

  • sampling_rate (float) – Sampling rate

  • fft_norm ('unitary', 'amplitude', 'rms', 'power', 'psd') – See documentation of pyfar.fft.normalization.

  • is_complex (bool) – Specifies if the underlying time domain data are complex real-valued.

Returns:

stub of pyfar Signal class

Return type:

signal

pyfar.testing.stub_utils.sine_func(frequency, sampling_rate, n_samples, fft_norm, cshape)[source]#

Generate time and frequency data of sine signal. The frequency is adjusted resulting in a fully periodic signal in the given time interval.

Parameters:
  • frequency (float) – Frequency of sine

  • sampling_rate (float) – Sampling rate

  • n_samples (int) – Number of samples

  • fft_norm ('none', 'rms') – See documentation of pyfar.fft.normalization.

  • cshape (tuple) – Channel shape

Returns:

  • time (ndarray, float) – time vector

  • freq (ndarray, complex) – frequency vector

  • frequency (float) – adjusted frequency

pyfar.testing.stub_utils.stub_is_pyfar_type()[source]#

Stubs _codec._is_pyfar_type for tests that use general data structures.

pyfar.testing.stub_utils.stub_str_to_type()[source]#

Stubs _codec.str_to_type for tests that use general data structures.

pyfar.testing.stub_utils.time_data_stub(time, times)[source]#

Function to generate stub of pyfar TimeData class based on MagicMock. The properties of the signal are set without any further check.

Parameters:
  • time (ndarray) – Time data

  • times (ndarray) – Times of time in second

Returns:

stub of pyfar TimeData class

Return type:

time_data