def test_octave_bands_frequencies(fixture_octave_bands, fraction): fixture_octave_bands['band_frequencies'] = bands.calculate_octave_bands(fraction) analyzer = bands.Bands(**fixture_octave_bands) for a, b in zip(analyzer.frequencies, analyzer.frequencies[1:]): if b[0] < a[2]: raise Exception('Frequencies overlap: {0} {1} (difference: {2})'.format(b[0], a[2], b[0] - a[2]))
def test_analyze(fixture_octave_bands, sample_size, fraction, weighting): fixture_octave_bands['sample_size'] = sample_size fixture_octave_bands['band_frequencies'] = bands.calculate_octave_bands(fraction) fixture_octave_bands['weighting'] = weighting analyzer = bands.Bands(**fixture_octave_bands) with analyzer: pass assert analyzer.exit_success
def test_benchmark(fixture_octave_bands, benchmark, fraction, weighting): fixture_octave_bands['fraction'] = 1 fixture_octave_bands['weighting'] = 'Z' analyzer = bands.Bands(**fixture_octave_bands) def benchmark_func(): for _ in range(0, 1000): analyzer._sample() analyzer._pulseaudio_client.connect() benchmark(benchmark_func) analyzer._pulseaudio_client.disconnect()
def test_octave_bands_indices(fixture_octave_bands, fraction, sample_size): fixture_octave_bands['band_frequencies'] = bands.calculate_octave_bands(fraction) fixture_octave_bands['sample_size'] = sample_size analyzer = bands.Bands(**fixture_octave_bands) a, b = 0, 0 for lower, upper in zip(analyzer._indices_lower, analyzer._indices_upper): if lower == upper: raise Exception('Indices equal, resulting in empty slice: [{0}, {1}]'.format(lower, upper)) if lower <= a or upper <= b: raise Exception('Indices overlap: [{0}, {1}] / [{2}, {3}]'.format(a, b, lower, upper)) a, b = lower, upper
def test_octave_bands_fft_resolution_too_small(fixture_octave_bands, sample_size, fraction): fixture_octave_bands['band_frequencies'] = bands.calculate_octave_bands(fraction) fixture_octave_bands['sample_size'] = sample_size with pytest.raises(PulsevizException): bands.Bands(**fixture_octave_bands)