]> git.parisson.com Git - timeside.git/commitdiff
New implementation for doctest bugfix again for systems without any display already...
authorThomas Fillon <thomas@parisson.com>
Fri, 10 Jan 2014 14:32:52 +0000 (15:32 +0100)
committerThomas Fillon <thomas@parisson.com>
Fri, 10 Jan 2014 14:32:52 +0000 (15:32 +0100)
@yomguy could you please check if this new fix is realy ok for systems without any display

tests/run_all_tests
tests/test_run_all_doctests.py
timeside/analyzer/core.py

index 810a2bafe72d8c94d5798287ced177d855b93748..34da6c2b9e3635ee2bab37c21acff77b57dffc7a 100755 (executable)
@@ -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())
index 8873b12d9d5ad0465771ca2c5e6402204b269aa1..8e5e6e1eb32c80e646ccfeaf7b300e2efb056e7f 100755 (executable)
@@ -20,7 +20,8 @@
 
 # Authors:
 #   Thomas Fillon <thomas  at parisson.com>
-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())
index 44b5f466d2d5039700b4c732f3d853618e9fc232..defe49eecc06ec2b68d03bc72e88e9ebec6e293f 100644 (file)
@@ -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])