ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/test/py_tests/unit_tools/support.py
Revision: 1.1
Committed: Sun Dec 7 20:40:51 2003 UTC (22 years, 1 month ago) by schorsch
Content type: text/x-python
Branch: MAIN
Log Message:
First attempt at testing framework.

File Contents

# Content
1
2 import os
3 import string
4
5 import unittest
6
7 def _find_raydir():
8 try: thisfile = __file__
9 except NameError:
10 import support
11 thisfile = support.__file__
12 sdirn = string.count(thisfile, os.sep)
13 if sdirn in [0, 1]:
14 raydir = os.path.join('..','..')
15 elif sdirn == 2:
16 raydir = os.path.join('..')
17 elif sdirn == 3:
18 raydir = '.'
19 else:
20 unit_tools = os.path.split(thisfile)[0]
21 py_tests = os.path.split(unit_tools)[0]
22 test = os.path.split(py_tests)[0]
23 raydir = os.path.split(test)[0]
24 return raydir
25
26 RAYDIR = _find_raydir()
27 DATADIR = os.path.join(RAYDIR, 'test', 'test data')
28 BINDIR = os.path.join(RAYDIR, 'bin')
29
30 def binfile(fn):
31 '''return the full/relative path to file in bin dir'''
32 if os.name == 'nt':
33 return os.path.normpath(os.path.join(BINDIR, fn + '.exe'))
34 else: return os.path.normpath(os.path.join(BINDIR, fn))
35
36 def datafile(fn):
37 '''return the full/relative path to file in data dir'''
38 return os.path.normpath(os.path.join(DATADIR, fn))
39
40 def run_case(c):
41 res = unittest.TestResult()
42 s = unittest.makeSuite(c, 'test')
43 s.run(res)
44 if res.errors or res.failures:
45 print ' failed'
46 print '-----------------------------'
47 for e in res.errors:
48 print e[1]
49 for e in res.failures:
50 es = string.strip(e[1])
51 sl = string.split(es, '\n')
52 print sl[-1]
53 print '-----------------------------'
54 else:
55 print ' ok'
56