[py-svn] r37112 - in py/branch/config/py/test: . testing

hpk at codespeak.net hpk at codespeak.net
Mon Jan 22 01:07:11 CET 2007


Author: hpk
Date: Mon Jan 22 01:07:09 2007
New Revision: 37112

Modified:
   py/branch/config/py/test/collect.py
   py/branch/config/py/test/config.py
   py/branch/config/py/test/testing/test_config.py
Log:
* moving towards a common rootdir/root collector 
* adding an xxxed test 


Modified: py/branch/config/py/test/collect.py
==============================================================================
--- py/branch/config/py/test/collect.py	(original)
+++ py/branch/config/py/test/collect.py	Mon Jan 22 01:07:09 2007
@@ -165,9 +165,10 @@
             namelist = namelist.split("/")
         cur = self
         for name in namelist:
-            next = cur.join(name)
-            assert next is not None, (cur, name, namelist)
-            cur = next
+            if name:
+                next = cur.join(name)
+                assert next is not None, (cur, name, namelist)
+                cur = next
         return cur
 
     def haskeyword(self, keyword): 

Modified: py/branch/config/py/test/config.py
==============================================================================
--- py/branch/config/py/test/config.py	(original)
+++ py/branch/config/py/test/config.py	Mon Jan 22 01:07:09 2007
@@ -63,17 +63,18 @@
 
     def _getcollector(self, path):
         assert path.check(), "%s: path does not exist" %(path,)
+        rootcol = self._getrootcollector(path)
+        return rootcol.getitembynames(
+            path.relto(rootcol.fspath).split(path.sep))
+
+    def _getrootcollector(self, path):
         pkgpath = path.pypkgpath()
         if pkgpath is None:
             pkgpath = path.check(file=1) and path.dirpath() or path
         col = self.conftest.rget("Directory", pkgpath)(pkgpath)
         col.config = self
-        for name in path.relto(pkgpath).split(path.sep):
-            if name:
-                col = col.join(name)
-                assert col is not None, (
-                    "joining %r to collector %s resulted in None"  %(name, col))
         return col 
+
              
     def addoptions(self, groupname, *specs): 
         """ add a named group of options to the current testing session. 

Modified: py/branch/config/py/test/testing/test_config.py
==============================================================================
--- py/branch/config/py/test/testing/test_config.py	(original)
+++ py/branch/config/py/test/testing/test_config.py	Mon Jan 22 01:07:09 2007
@@ -83,6 +83,32 @@
     config = py.test.config._reparse([str(o)])
     assert config.getvalue('x') == 1
 
+def XXXtest_config_init_direct():
+    tmp = py.test.ensuretemp("reprconfig1")
+    tmp.ensure("__init__.py")
+    tmp.ensure("conftest.py").write("x=1 ; y=2")
+    hello = tmp.ensure("test_hello.py")
+    config = py.test.config._reparse([hello])
+    repr = config.repr_direct(conftestnames='x,y') 
+    config2 = py.test.config._reparse([tmp.dirpath()])
+    config2.init_direct(repr, basedir=tmp.dirpath())
+    for x,y in zip(config.args, config2.args):
+        assert x == y
+    py.test.raises(AssertionError, "config2.init_direct(repr, basedir=None)")
+    config3 = py.test.config._reparse([tmp.dirpath()])
+    col = config3._getcollector(hello)
+    config3.init_direct(repr, basedir=tmp.dirpath(), 
+        collectspecs=[col.gettrail()])
+    assert config3.getvalue('x') == 1
+    assert config3.getvalue('y') == 2
+    cols = config.getcolitems()
+    assert len(cols) == 1
+    col = cols[0]
+    assert col.name == 'test_hello.py'
+    assert col.parent.name == 'reprconfig1'
+    assert col.parent.parent.name == tmp.dirpath().basename 
+    assert col.parent.parent.parent is None
+
 def test_config_make_and_merge_repr():
     tmp = py.test.ensuretemp("reprconfig1")
     tmp.ensure("__init__.py")



More information about the pytest-commit mailing list