Debian Codegraph @

test/conftest.py

raw symbols SCIP
1 # This file is part of audioread.
2 # Copyright 2018, Sam Thursfield
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be
13 # included in all copies or substantial portions of the Software.
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 # The audiofiles used for testing live in the data/ directory. They are defined
33 # by .json files and each one must be listed here by name.
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)