From: Thomas Fillon Date: Fri, 10 Jan 2014 14:32:52 +0000 (+0100) Subject: New implementation for doctest bugfix again for systems without any display already... X-Git-Tag: 0.5.3~22^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5f5a1877c7fa2ac539da21acbeba0141ebe49fc3;p=timeside.git New implementation for doctest bugfix again for systems without any display already fixed in f41a113131 @yomguy could you please check if this new fix is realy ok for systems without any display --- diff --git a/tests/run_all_tests b/tests/run_all_tests index 810a2ba..34da6c2 100755 --- a/tests/run_all_tests +++ b/tests/run_all_tests @@ -1,21 +1,27 @@ #! /usr/bin/env python +import os +import sys -if __name__ == '__main__': - import os, sys, unittest - from unit_timeside import * - def load_test(): + +def load_test(): # get relevant files curdir = os.path.dirname(sys.argv[0]) - if curdir == '': curdir = '.' + if curdir == '': + curdir = '.' files = os.listdir(curdir) - modfiles = filter (lambda y: y.endswith('.py'), files) - modfiles = filter (lambda f: f.startswith('test_'), modfiles) + modfiles = filter(lambda y: y.endswith('.py'), files) + modfiles = filter(lambda f: f.startswith('test_'), modfiles) # get module names - modnames = map (lambda x: os.path.splitext(x)[0], modfiles) + modnames = map(lambda x: os.path.splitext(x)[0], modfiles) # import them - modules = map (__import__, modnames) + modules = map(__import__, modnames) # create a test suites from the imported module load_from_module = unittest.defaultTestLoader.loadTestsFromModule tests = map(load_from_module, modules) return unittest.TestSuite(tests) - unittest.main(defaultTest = 'load_test', testRunner=TestRunner()) + +if __name__ == '__main__': + import unittest + from unit_timeside import TestRunner + + unittest.main(defaultTest='load_test', testRunner=TestRunner()) diff --git a/tests/test_run_all_doctests.py b/tests/test_run_all_doctests.py index 8873b12..8e5e6e1 100755 --- a/tests/test_run_all_doctests.py +++ b/tests/test_run_all_doctests.py @@ -20,7 +20,8 @@ # Authors: # Thomas Fillon -from unit_timeside import * +import unittest +from unit_timeside import TestRunner import doctest import timeside import pkgutil @@ -43,4 +44,7 @@ def load_tests(loader, tests, ignore): if __name__ == '__main__': - unittest.main(testRunner=TestRunner()) + import os + # Do not run doctest for environment without a display (e.g. server) + if 'DISPLAY' in os.environ: + unittest.main(testRunner=TestRunner()) diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 44b5f46..defe49e 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -29,13 +29,6 @@ import numpy from collections import OrderedDict import h5py import h5tools -import os - -if os.environ.has_key('DISPLAY'): - doctest_option = '+SKIP' -else: - doctest_option = '+ELLIPSIS' - numpy_data_types = [ #'float128', @@ -796,12 +789,13 @@ class AnalyzerResultContainer(dict): >>> d = timeside.decoder.FileDecoder(wavFile, start=1) >>> a = timeside.analyzer.Analyzer() - >>> (d|a).run() #doctest: %s - >>> a.new_result() #doctest: %s + >>> (d|a).run() + >>> a.new_result() #doctest: +ELLIPSIS FrameValueResult(id_metadata=IdMetadata(id='analyzer', name='Generic analyzer', unit='', description='', date='...', version='...', author='TimeSide', uuid='...'), data_object=DataObject(value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='http://...', start=1.0, duration=7..., is_segment=True, channels=None, channelsManagement=''), frame_metadata=FrameMetadata(samplerate=44100, blocksize=8192, stepsize=8192), parameters={}) >>> resContainer = timeside.analyzer.core.AnalyzerResultContainer() - ''' % (doctest_option, doctest_option) + ''' + def __init__(self, analyzer_results=None): super(AnalyzerResultContainer, self).__init__() @@ -1054,5 +1048,9 @@ class Analyzer(Processor): if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file + # Run doctest from __main__ and unittest from tests + from tests.unit_timeside import run_test_module + # load corresponding tests + from tests import test_AnalyzerResult + + run_test_module([test_AnalyzerResult])