]> rtime.felk.cvut.cz Git - wvtest.git/commitdiff
Update wvtest.py to the new version that does os.chdir().
authorAvery Pennarun <apenwarr@gmail.com>
Sat, 26 Jun 2010 04:48:11 +0000 (00:48 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sat, 26 Jun 2010 04:58:12 +0000 (00:58 -0400)
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.

python/t/testfile.txt [new file with mode: 0644]
python/t/twvtest.py
python/wvtest.py

diff --git a/python/t/testfile.txt b/python/t/testfile.txt
new file mode 100644 (file)
index 0000000..3b18e51
--- /dev/null
@@ -0,0 +1 @@
+hello world
index 6574656d62f63ce2e7733bffbc573c05656e982a..cc825f346991176ecd81fc0e792752dea1b8ab8e 100644 (file)
@@ -32,3 +32,7 @@ def booga1():
     WVPASSEQ(last, 'booga2')
     last='booga1'
 
+
+@wvtest
+def chdir_test():
+    WVPASS(open('testfile.txt')) # will fail if chdir is wrong
index 51a66b889e3bf22585ab0c649c405ac1b15f1671..09403ca8dfad3652530c1deab785b856a0ad5fce 100755 (executable)
@@ -137,11 +137,20 @@ else:  # we're the main program
             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)