It was too annoying to test submodules, because if any of them opened a
file, they always had to mention the full path from the wvtest.py (which was
usually at the root of the whole project) to the data file (which was
usually in the t/ subdir of the submodule). So if you extracted a submodule
into its own project, all the paths would be wrong.
Now wvtest.py does os.chdir() into the t/ subdir being tested. If you don't
like that, you can always chdir into a parent directory.
WVPASSEQ(last, 'booga2')
last='booga1'
WVPASSEQ(last, 'booga2')
last='booga1'
+
+@wvtest
+def chdir_test():
+ WVPASS(open('testfile.txt')) # will fail if chdir is wrong
modname = modname[:-3]
print 'Importing: %s' % modname
wvtest._registered = []
modname = modname[:-3]
print 'Importing: %s' % modname
wvtest._registered = []
- mod = __import__(modname.replace('/', '.'), None, None, [])
-
- for t in wvtest._registered:
- _runtest(modname, t.func_name, t)
- print
+ oldwd = os.getcwd()
+ oldpath = sys.path
+ try:
+ modpath = os.path.abspath(modname).split('/')[:-1]
+ os.chdir('/'.join(modpath))
+ sys.path += ['/'.join(modpath),
+ '/'.join(modpath[:-1])]
+ mod = __import__(modname.replace('/', '.'), None, None, [])
+ for t in wvtest._registered:
+ _runtest(modname, t.func_name, t)
+ print
+ finally:
+ os.chdir(oldwd)
+ sys.path = oldpath
print
print 'WvTest: %d tests, %d failures.' % (wvtest._tests, wvtest._fails)
print
print 'WvTest: %d tests, %d failures.' % (wvtest._tests, wvtest._fails)