| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import json |
| 17 |
import os |
| 18 |
|
| 19 |
import pytest |
| 20 |
|
| 21 |
|
| 22 |
@pytest.fixture() |
| 23 |
def audiofile(request): |
| 24 |
"""Fixture that provides an AudiofileSpec instance.""" |
| 25 |
spec_path = os.path.join(DATADIR, request.param + '.json') |
| 26 |
with open(spec_path) as f: |
| 27 |
spec = json.load(f) |
| 28 |
result = AudiofileSpec(**spec) |
| 29 |
return result |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
TEST_AUDIOFILES = ['test-1', 'test-2'] |
| 35 |
|
| 36 |
DATADIR = os.path.join(os.path.dirname(__file__), 'data') |
| 37 |
|
| 38 |
|
| 39 |
class AudiofileSpec(): |
| 40 |
"""Defines the expected attributes for a test audiofile.""" |
| 41 |
def __init__(self, filename, duration, channels, samplerate): |
| 42 |
self.path = os.path.join(DATADIR, filename) |
| 43 |
self.duration = duration |
| 44 |
self.channels = channels |
| 45 |
self.samplerate = samplerate |
| 46 |
|
| 47 |
|
| 48 |
def pytest_generate_tests(metafunc): |
| 49 |
"""Parametrize the audiofile() fixture using TEST_AUDIOFILES.""" |
| 50 |
if 'audiofile' in metafunc.fixturenames: |
| 51 |
metafunc.parametrize("audiofile", TEST_AUDIOFILES, indirect=True) |