[py-svn] r62993 - in py/trunk/py/test: . dsession/testing plugin testing

hpk at codespeak.net hpk at codespeak.net
Tue Mar 17 11:29:45 CET 2009


Author: hpk
Date: Tue Mar 17 11:29:45 2009
New Revision: 62993

Modified:
   py/trunk/py/test/config.py
   py/trunk/py/test/dsession/testing/test_functional_dsession.py
   py/trunk/py/test/plugin/pytest_default.py
   py/trunk/py/test/plugin/pytest_pytester.py
   py/trunk/py/test/testing/acceptance_test.py
   py/trunk/py/test/testing/test_config.py
   py/trunk/py/test/testing/test_session.py
Log:
* moving ensuretemp to config object
* adding --basetemp option
* added/rewrote some tests


Modified: py/trunk/py/test/config.py
==============================================================================
--- py/trunk/py/test/config.py	(original)
+++ py/trunk/py/test/config.py	Tue Mar 17 11:29:45 2009
@@ -4,16 +4,11 @@
 from py.__.test import parseopt
 from py.__.misc.warn import APIWARN
 
-# XXX move to Config class
-basetemp = None
 def ensuretemp(string, dir=1): 
     """ return temporary directory path with
         the given string as the trailing part. 
     """ 
-    global basetemp
-    if basetemp is None: 
-        basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
-    return basetemp.ensure(string, dir=dir) 
+    return py.test.config.ensuretemp(string, dir=dir)
   
 class CmdOptions(object):
     """ pure container instance for holding cmdline options 
@@ -29,6 +24,7 @@
     """ central bus for dealing with configuration/initialization data. """ 
     Option = py.compat.optparse.Option # deprecated
     Error = Error
+    basetemp = None
     _sessionclass = None
 
     def __init__(self, pytestplugins=None, topdir=None): 
@@ -123,6 +119,18 @@
         self._preparse(args)
         self.args = args 
 
+    def ensuretemp(self, string, dir=True):
+        if self.basetemp is None: 
+            basetemp = self.option.basetemp 
+            if basetemp:
+                basetemp = py.path.local(basetemp)
+                if not basetemp.check(dir=1):
+                    basetemp.mkdir()
+            else:
+                basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
+            self.basetemp = basetemp 
+        return self.basetemp.ensure(string, dir=dir) 
+
     def getcolitems(self):
         return [self.getfsnode(arg) for arg in self.args]
 

Modified: py/trunk/py/test/dsession/testing/test_functional_dsession.py
==============================================================================
--- py/trunk/py/test/dsession/testing/test_functional_dsession.py	(original)
+++ py/trunk/py/test/dsession/testing/test_functional_dsession.py	Tue Mar 17 11:29:45 2009
@@ -63,38 +63,21 @@
         assert ev.host.address == "popen"
         ev, = eq.geteventargs("testrunfinish")
 
-    def test_distribution_rsync_roots_example(self, testdir):
-        py.test.skip("testing for root rsync needs rework")
-        destdir = py.test.ensuretemp("example_dist_destdir")
-        subdir = "sub_example_dist"
-        sourcedir = self.tmpdir.mkdir("source")
-        sourcedir.ensure(subdir, "conftest.py").write(py.code.Source("""
-            hosts = ["popen:%s"]
-            rsyncdirs = ["%s", "../py"]
-        """ % (destdir, tmpdir.join(subdir), )))
-        tmpdir.ensure(subdir, "__init__.py")
-        tmpdir.ensure(subdir, "test_one.py").write(py.code.Source("""
-            def test_1(): 
-                pass
-            def test_2():
-                assert 0
-            def test_3():
-                raise ValueError(23)
-            def test_4(someargs):
-                pass
-            def test_5():
-                assert __file__ != '%s'
-            #def test_6():
-            #    import py
-            #    assert py.__file__ != '%s'
-        """ % (tmpdir.join(subdir), py.__file__)))
-        destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath())
-
-        sorter = testdir.inline_run(tmpdir.join(subdir))
-        testevents = sorter.getnamed('itemtestreport')
-        assert len([x for x in testevents if x.passed]) == 2
-        assert len([x for x in testevents if x.failed]) == 3
-        assert len([x for x in testevents if x.skipped]) == 0
+    @py.test.mark.xfail("XXX")
+    def test_distribution_rsyncdirs_example(self, testdir):
+        source = testdir.mkdir("source")
+        dest = testdir.mkdir("dest")
+        subdir = source.mkdir("example_pkg")
+        subdir.ensure("__init__.py")
+        p = subdir.join("test_one.py")
+        p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
+        result = testdir.runpytest("-d", "--rsyncdirs=%(subdir)s" % locals(), 
+                                   "--hosts=popen:%(dest)s" % locals())
+        assert result.ret == 0
+        result.stdout.fnmatch_lines([
+            "*1 passed*"
+        ])
+        assert dest.join(subdir.basename).check(dir=1)
 
     def test_nice_level(self, testdir):
         """ Tests if nice level behaviour is ok """

Modified: py/trunk/py/test/plugin/pytest_default.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_default.py	(original)
+++ py/trunk/py/test/plugin/pytest_default.py	Tue Mar 17 11:29:45 2009
@@ -61,7 +61,9 @@
         group._addoption('-s', '--nocapture',
                    action="store_true", dest="nocapture", default=False,
                    help="disable catching of sys.stdout/stderr output."),
-        group._addoption('--boxed',
+        group.addoption('--basetemp', dest="basetemp", default=None, 
+                   help="directory to use for this test run.")
+        group.addoption('--boxed',
                    action="store_true", dest="boxed", default=False,
                    help="box each test run in a separate process"), 
         group._addoption('-f', '--looponfailing',

Modified: py/trunk/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_pytester.py	(original)
+++ py/trunk/py/test/plugin/pytest_pytester.py	Tue Mar 17 11:29:45 2009
@@ -234,6 +234,9 @@
         return self.run(script, *args)
 
     def runpytest(self, *args):
+        p = py.path.local.make_numbered_dir(prefix="runpytest-", 
+            keep=None, rootdir=self.tmpdir)
+        args = ('--basetemp=%s' % p, ) + args 
         return self.runpybin("py.test", *args)
 
 class Event:

Modified: py/trunk/py/test/testing/acceptance_test.py
==============================================================================
--- py/trunk/py/test/testing/acceptance_test.py	(original)
+++ py/trunk/py/test/testing/acceptance_test.py	Tue Mar 17 11:29:45 2009
@@ -16,6 +16,17 @@
         assert result.stderr.fnmatch_lines([
             'config ERROR: hello'
         ])
+
+    def test_basetemp(self, testdir):
+        mytemp = testdir.tmpdir.mkdir("mytemp")
+        p = testdir.makepyfile("""
+            import py
+            def test_1(): 
+                py.test.ensuretemp('xyz')
+        """)
+        result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
+        assert result.ret == 0
+        assert mytemp.join('xyz').check(dir=1)
                 
     def test_assertion_magic(self, testdir):
         p = testdir.makepyfile("""

Modified: py/trunk/py/test/testing/test_config.py
==============================================================================
--- py/trunk/py/test/testing/test_config.py	(original)
+++ py/trunk/py/test/testing/test_config.py	Tue Mar 17 11:29:45 2009
@@ -85,8 +85,9 @@
             yield check_conflict_option, opts
 
 class TestConfigAPI: 
+
     @py.test.mark.issue("ensuretemp should call config.maketemp(basename)")
-    def test_tmpdir(self):
+    def test_ensuretemp(self):
         d1 = py.test.ensuretemp('hello') 
         d2 = py.test.ensuretemp('hello') 
         assert d1 == d2

Modified: py/trunk/py/test/testing/test_session.py
==============================================================================
--- py/trunk/py/test/testing/test_session.py	(original)
+++ py/trunk/py/test/testing/test_session.py	Tue Mar 17 11:29:45 2009
@@ -214,6 +214,7 @@
         assert len(colskipped) == 1
 
     def test_minus_x_import_error(self, testdir):
+        testdir.makepyfile(__init__="")
         testdir.makepyfile(test_one="xxxx", test_two="yyyy")
         sorter = testdir.inline_run("-x", testdir.tmpdir)
         finished = sorter.getnamed("collectionreport")



More information about the pytest-commit mailing list