Back to index

radiance  4R0+20100331
support.py
Go to the documentation of this file.
00001 
00002 import os
00003 import sys
00004 import string
00005 
00006 import unittest
00007 
00008 def _find_raydir():
00009        if __name__ == '__main__':
00010               thisfile = sys.argv[0]
00011        else: thisfile = sys.modules[__name__].__file__
00012        unit_tools = os.path.abspath(os.path.dirname(thisfile))
00013        py_tests = os.path.dirname(unit_tools)
00014        test = os.path.dirname(py_tests)
00015        raydir = os.path.dirname(test)
00016        return raydir
00017 
00018 RAYDIR = _find_raydir()
00019 DATADIR = os.path.join(RAYDIR, 'test', 'test data')
00020 BINDIR = os.path.join(RAYDIR, 'bin')
00021 
00022 def binfile(fn):
00023        '''return the full path to file in bin dir'''
00024        if os.name == 'nt':
00025               return os.path.normpath(os.path.join(BINDIR, fn + '.exe'))
00026        else: return os.path.normpath(os.path.join(BINDIR, fn))
00027 
00028 def datafile(fn):
00029        '''return the full path to file in data dir'''
00030        return os.path.normpath(os.path.join(DATADIR, fn))
00031 
00032 def run_case(c):
00033        res = unittest.TestResult()
00034        s = unittest.makeSuite(c, 'test')
00035        s.run(res)
00036        if res.errors or res.failures:
00037               print ' failed'
00038               print '-----------------------------'
00039               for e in res.errors:
00040                      print e[1]
00041               for e in res.failures:
00042                      es = string.strip(e[1])
00043                      sl = string.split(es, '\n')
00044                      print sl[-1]
00045               print '-----------------------------'
00046        else:
00047               print ' ok'
00048