this file is part of audioread 2018 sam thursfield permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the software to deal in the software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense andor sell copies of the software and to permit persons to whom the software is furnished to do so subject to the following conditions the above notice and this permission notice shall be included in all copies or substantial portions of the software fixture that provides an audiofilespec instance specpath os path joindatadir request param json with openspecpath as f spec json loadf result audiofilespecspec return result the audiofiles used for testing live in the data directory they are defined by json files and each one must be listed here by name testaudiofiles test1 test2 datadir os path joinos path dirnamefile data class audiofilespec parametrize the audiofile fixture using testaudiofiles if audiofile in metafunc fixturenames metafunc parametrizeaudiofile testaudiofiles indirecttrue this file is part of audioread 2018 sam thursfield permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the software to deal in the software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense and or sell copies of the software and to permit persons to whom the software is furnished to do so subject to the following conditions the above notice and this permission notice shall be included in all copies or substantial portions of the software fixture that provides an audiofilespec instance the audiofiles used for testing live in the data directory they are defined by json files and each one must be listed here by name defines the expected attributes for a test audiofile parametrize the audiofile fixture using test_audiofiles
import json
import os

import pytest


@pytest.fixture()
def audiofile(request):
    
    spec_path = os.path.join(DATADIR, request.param + '.json')
    with open(spec_path) as f:
        spec = json.load(f)
    result = AudiofileSpec(**spec)
    return result




TEST_AUDIOFILES = ['test-1', 'test-2']

DATADIR = os.path.join(os.path.dirname(__file__), 'data')


class AudiofileSpec():
    
    def __init__(self, filename, duration, channels, samplerate):
        self.path = os.path.join(DATADIR, filename)
        self.duration = duration
        self.channels = channels
        self.samplerate = samplerate


def pytest_generate_tests(metafunc):
    
    if 'audiofile' in metafunc.fixturenames:
        metafunc.parametrize("audiofile", TEST_AUDIOFILES, indirect=True)