From: Thomas Fillon Date: Thu, 20 Mar 2014 17:42:43 +0000 (+0100) Subject: Doctest: Handle alias fixture for test data files X-Git-Tag: 0.5.5~3^2^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=253f221a030dd58a2f1a99a6c3f2e042836ac30a;p=timeside.git Doctest: Handle alias fixture for test data files Add a way to define alias for test data files to preserve readability of the doctest e.g. 'wavfile = 'test/data/file.wav') but the executed code will use 'wavfile=/home/user/real_path/test/data/file.wav'. --- diff --git a/tests/test_run_all_doctests.py b/tests/test_run_all_doctests.py index 8e5e6e1..2ca5f4f 100755 --- a/tests/test_run_all_doctests.py +++ b/tests/test_run_all_doctests.py @@ -38,7 +38,13 @@ def load_tests(loader, tests, ignore): onerror=lambda x: None)] for module in modules_list: - tests.addTests(doctest.DocTestSuite(module, test_finder=finder)) + _tmp = __import__(module, fromlist=['DOCTEST_ALIAS']) + try: + DOCTEST_ALIAS = _tmp.DOCTEST_ALIAS + except AttributeError: + DOCTEST_ALIAS = {} + tests.addTests(doctest.DocTestSuite(module, extraglobs=DOCTEST_ALIAS, + test_finder=finder)) return tests diff --git a/timeside/decoder/utils.py b/timeside/decoder/utils.py index 50e9a71..cf9e214 100644 --- a/timeside/decoder/utils.py +++ b/timeside/decoder/utils.py @@ -174,7 +174,8 @@ def sha1sum_file(filename): ''' Return the secure hash digest with sha1 algorithm for a given file - >>> print sha1sum_file('../../tests/samples/guitar.wav') + >>> wav_file = '../../tests/samples/guitar.wav' # doctest: +SKIP + >>> print sha1sum_file(wav_file) 08301c3f9a8d60926f31e253825cc74263e52ad1 ''' import hashlib @@ -195,7 +196,8 @@ def sha1sum_url(url): >>> url = 'https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav' >>> print sha1sum_url(url) 08301c3f9a8d60926f31e253825cc74263e52ad1 - >>> uri = get_uri('../../tests/samples/guitar.wav') + >>> wav_file = '../../tests/samples/guitar.wav' # doctest: +SKIP + >>> uri = get_uri(wav_file) >>> print sha1sum_url(uri) 08301c3f9a8d60926f31e253825cc74263e52ad1 @@ -227,7 +229,11 @@ def sha1sum_numpy(np_array): import hashlib return hashlib.sha1(np_array.view(np.uint8)).hexdigest() +import os +DOCTEST_ALIAS = {'wav_file': os.path.join(os.path.dirname(__file__), + '../../tests/samples/guitar.wav')} if __name__ == "__main__": import doctest - doctest.testmod() + + doctest.testmod(extraglobs=DOCTEST_ALIAS)