From 8238ae4ab16106e053fa668cb42798978d8f19df Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Mon, 24 Mar 2014 14:50:36 +0100 Subject: [PATCH] Doctest: Fix path issue for local test data Use doctest.tesmod() `extraglobs` parameter to pass absolute data path to the doctest module. This works from both module directory or tests directory --- timeside/analyzer/core.py | 10 +++++++--- timeside/decoder/utils.py | 6 ++++-- timeside/encoder/audiosink.py | 12 +++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 8d71572..6ba2b90 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -857,8 +857,8 @@ class AnalyzerResultContainer(dict): ''' >>> import timeside - >>> wavFile = 'http://github.com/yomguy/timeside-samples/raw/master/samples/sweep.mp3' - >>> d = timeside.decoder.FileDecoder(wavFile) + >>> wav_file = 'tests/samples/sweep.mp3' # doctest: +SKIP + >>> d = timeside.decoder.FileDecoder(wav_file) >>> a = timeside.analyzer.Analyzer() >>> (d|a).run() @@ -1118,7 +1118,11 @@ class Analyzer(Processor): return result +import os +DOCTEST_ALIAS = {'wav_file': os.path.join(os.path.dirname(__file__), + '../../tests/samples/sweep.mp3')} + if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(extraglobs=DOCTEST_ALIAS) diff --git a/timeside/decoder/utils.py b/timeside/decoder/utils.py index a776e15..cb8c418 100644 --- a/timeside/decoder/utils.py +++ b/timeside/decoder/utils.py @@ -174,7 +174,7 @@ def sha1sum_file(filename): ''' Return the secure hash digest with sha1 algorithm for a given file - >>> wav_file = '../../tests/samples/guitar.wav' # doctest: +SKIP + >>> wav_file = 'tests/samples/guitar.wav' # doctest: +SKIP >>> print sha1sum_file(wav_file) 08301c3f9a8d60926f31e253825cc74263e52ad1 ''' @@ -196,7 +196,7 @@ def sha1sum_url(url): >>> url = 'https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav' >>> print sha1sum_url(url) 08301c3f9a8d60926f31e253825cc74263e52ad1 - >>> wav_file = '../../tests/samples/guitar.wav' # doctest: +SKIP + >>> wav_file = 'tests/samples/guitar.wav' # doctest: +SKIP >>> uri = get_uri(wav_file) >>> print sha1sum_url(uri) 08301c3f9a8d60926f31e253825cc74263e52ad1 @@ -229,6 +229,8 @@ def sha1sum_numpy(np_array): import hashlib return hashlib.sha1(np_array.view(np.uint8)).hexdigest() + +# Define global variables for use with doctest import os DOCTEST_ALIAS = {'wav_file': os.path.join(os.path.dirname(__file__), '../../tests/samples/guitar.wav')} diff --git a/timeside/encoder/audiosink.py b/timeside/encoder/audiosink.py index 611f51a..b7e6531 100644 --- a/timeside/encoder/audiosink.py +++ b/timeside/encoder/audiosink.py @@ -32,8 +32,8 @@ class AudioSink(GstEncoder): >>> import timeside - >>> wavfile = 'https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav' - >>> d = timeside.decoder.FileDecoder(wavfile) + >>> wav_file = 'tests/samples/guitar.wav' # doctest: +SKIP + >>> d = timeside.decoder.FileDecoder(wav_file) >>> e = timeside.encoder.AudioSink() >>> (d|e).run() # doctest: +SKIP """ @@ -95,6 +95,12 @@ class AudioSink(GstEncoder): self.metadata = metadata +# Define global variables for use with doctest +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) -- 2.39.5