[py-svn] r62077 - py/branch/pytestplugin/py/test/testing

hpk at codespeak.net hpk at codespeak.net
Sat Feb 21 18:05:45 CET 2009


Author: hpk
Date: Sat Feb 21 18:05:43 2009
New Revision: 62077

Added:
   py/branch/pytestplugin/py/test/testing/test_collect_pickle.py   (contents, props changed)
      - copied, changed from r62008, py/branch/pytestplugin/py/test/testing/test_collect.py
   py/branch/pytestplugin/py/test/testing/test_pycollect.py   (contents, props changed)
      - copied, changed from r62008, py/branch/pytestplugin/py/test/testing/test_collect.py
Modified:
   py/branch/pytestplugin/py/test/testing/test_collect.py
Log:
regroup collection tests using the newly obtained flexibility 
from the dynamic funcarg setup. 


Modified: py/branch/pytestplugin/py/test/testing/test_collect.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_collect.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_collect.py	Sat Feb 21 18:05:43 2009
@@ -1,59 +1,69 @@
-from __future__ import generators
 import py
-from py.__.test import event, outcome 
-from py.__.test.conftesthandle import Conftest
-from py.__.test.collect import SetupState
-from py.__.test.pycollect import DoctestFileContent
 
+class TestCollector:
+    def test_collect_versus_item(self):
+        from py.__.test.collect import Collector, Item
+        assert not issubclass(Collector, Item)
+        assert not issubclass(Item, Collector)
+
+    def test_check_equality_and_cmp_basic(self, testdir):
+        modcol = testdir.getmodulecol("""
+            def test_pass(): pass
+            def test_fail(): assert 0
+        """)
+        fn1 = modcol.collect_by_name("test_pass")
+        assert isinstance(fn1, py.test.collect.Function)
+        fn2 = modcol.collect_by_name("test_pass")
+        assert isinstance(fn2, py.test.collect.Function)
 
+        assert fn1 == fn2
+        assert fn1 != modcol 
+        assert cmp(fn1, fn2) == 0
+        assert hash(fn1) == hash(fn2) 
+
+        fn3 = modcol.collect_by_name("test_fail")
+        assert isinstance(fn3, py.test.collect.Function)
+        assert not (fn1 == fn3) 
+        assert fn1 != fn3
+        assert cmp(fn1, fn3) == -1
+
+        assert cmp(fn1, 10) == -1 
+        assert cmp(fn2, 10) == -1 
+        assert cmp(fn3, 10) == -1 
+        for fn in fn1,fn2,fn3:
+            assert fn != 3
+            assert fn != modcol
+            assert fn != [1,2,3]
+            assert [1,2,3] != fn
+            assert modcol != fn
 
-class DummyConfig:
-    def __init__(self):
-        self._conftest = Conftest()
-        self._setupstate = SetupState()
-        self.args = []
-        class dummyoption:
-            nomagic = False
-        self.option = dummyoption
-    def getvalue(self, name, fspath):
-        return self._conftest.rget(name, fspath)
-
-def setup_module(mod):
-    mod.dummyconfig = DummyConfig()
-
-def test_collect_versus_item():
-    from py.__.test.collect import Collector, Item
-    assert not issubclass(Collector, Item)
-    assert not issubclass(Item, Collector)
-
-def test_ignored_certain_directories(tmpdir): 
-    tmpdir.ensure("_darcs", 'test_notfound.py')
-    tmpdir.ensure("CVS", 'test_notfound.py')
-    tmpdir.ensure("{arch}", 'test_notfound.py')
-    tmpdir.ensure(".whatever", 'test_notfound.py')
-    tmpdir.ensure(".bzr", 'test_notfound.py')
-    tmpdir.ensure("normal", 'test_found.py')
-    tmpdir.ensure('test_found.py')
-
-    col = py.test.collect.Directory(tmpdir, config=dummyconfig) 
-    items = col.collect()
-    names = [x.name for x in items]
-    assert len(items) == 2
-    assert 'normal' in names
-    assert 'test_found.py' in names
-
-class TestCollect:
-    def test_failing_import(self, testdir):
-        modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
-        py.test.raises(ImportError, modcol.collect)
-        py.test.raises(ImportError, modcol.collect)
-        py.test.raises(ImportError, modcol.run)
-
-    def test_syntax_error_in_module(self, testdir):
-        modcol = testdir.getmodulecol("this is a syntax error") 
-        py.test.raises(SyntaxError, modcol.collect)
-        py.test.raises(SyntaxError, modcol.collect)
-        py.test.raises(SyntaxError, modcol.run)
+    def test_totrail_and_back(self, tmpdir):
+        a = tmpdir.ensure("a", dir=1)
+        tmpdir.ensure("a", "__init__.py")
+        x = tmpdir.ensure("a", "trail.py")
+        config = py.test.config._reparse([x])
+        col = config.getfsnode(x)
+        trail = col._totrail()
+        assert len(trail) == 2
+        assert trail[0] == a.relto(config.topdir)
+        assert trail[1] == ('trail.py',)
+        col2 = py.test.collect.Collector._fromtrail(trail, config)
+        assert col2.listnames() == col.listnames()
+       
+    def test_totrail_topdir_and_beyond(self, tmpdir):
+        config = py.test.config._reparse([tmpdir])
+        col = config.getfsnode(config.topdir)
+        trail = col._totrail()
+        assert len(trail) == 2
+        assert trail[0] == '.'
+        assert trail[1] == ()
+        col2 = py.test.collect.Collector._fromtrail(trail, config)
+        assert col2.fspath == config.topdir
+        assert len(col2.listchain()) == 1
+        col3 = config.getfsnode(config.topdir.dirpath())
+        py.test.raises(ValueError, 
+              "col3._totrail()")
+        
 
     def test_listnames_and__getitembynames(self, testdir):
         modcol = testdir.getmodulecol("pass", withinit=True)
@@ -84,166 +94,32 @@
         node = dircol._getitembynames(names)
         assert isinstance(node, py.test.collect.File)
 
+class TestCollectFS:
+    def test_ignored_certain_directories(self, testdir): 
+        tmpdir = testdir.tmpdir
+        tmpdir.ensure("_darcs", 'test_notfound.py')
+        tmpdir.ensure("CVS", 'test_notfound.py')
+        tmpdir.ensure("{arch}", 'test_notfound.py')
+        tmpdir.ensure(".whatever", 'test_notfound.py')
+        tmpdir.ensure(".bzr", 'test_notfound.py')
+        tmpdir.ensure("normal", 'test_found.py')
+        tmpdir.ensure('test_found.py')
+
+        col = testdir.parseconfig(tmpdir).getfsnode(tmpdir)
+        items = col.collect()
+        names = [x.name for x in items]
+        assert len(items) == 2
+        assert 'normal' in names
+        assert 'test_found.py' in names
+
     def test_found_certain_testfiles(self, testdir): 
         p1 = testdir.makepyfile(test_found = "pass", found_test="pass")
-        col = py.test.collect.Directory(p1.dirpath(), config=dummyconfig) 
+        col = testdir.parseconfig(p1).getfsnode(p1.dirpath())
         items = col.collect() # Directory collect returns files sorted by name
         assert len(items) == 2
         assert items[1].name == 'test_found.py'
         assert items[0].name == 'found_test.py'
 
-    def test_disabled_class(self, testdir):
-        modcol = testdir.getmodulecol("""
-            class TestClass:
-                disabled = True
-                def test_method(self):
-                    pass
-        """)
-        l = modcol.collect()
-        assert len(l) == 1
-        modcol = l[0]
-        assert isinstance(modcol, py.test.collect.Class)
-        assert not modcol.collect() 
-
-    def test_disabled_module(self, testdir):
-        modcol = testdir.getmodulecol("""
-            disabled = True
-            def setup_module(mod):
-                raise ValueError
-        """)
-        assert not modcol.collect() 
-        assert not modcol.run() 
-
-    def test_generative_functions(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-
-            def test_gen(): 
-                yield func1, 17, 3*5
-                yield func1, 42, 6*7
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 1
-        gencol = colitems[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == '[0]'
-        assert gencolitems[0].obj.func_name == 'func1'
-
-    def test_generative_methods(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-            class TestGenMethods: 
-                def test_gen(self): 
-                    yield func1, 17, 3*5
-                    yield func1, 42, 6*7
-        """)
-        gencol = modcol.collect()[0].collect()[0].collect()[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == '[0]'
-        assert gencolitems[0].obj.func_name == 'func1'
-
-    def test_generative_functions_with_explicit_names(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-
-            def test_gen(): 
-                yield "seventeen", func1, 17, 3*5
-                yield "fortytwo", func1, 42, 6*7
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 1
-        gencol = colitems[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == "['seventeen']"
-        assert gencolitems[0].obj.func_name == 'func1'
-        assert gencolitems[1].name == "['fortytwo']"
-        assert gencolitems[1].obj.func_name == 'func1'        
-
-    def test_generative_methods_with_explicit_names(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-            class TestGenMethods: 
-                def test_gen(self): 
-                    yield "m1", func1, 17, 3*5
-                    yield "m2", func1, 42, 6*7
-        """)
-        gencol = modcol.collect()[0].collect()[0].collect()[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == "['m1']"
-        assert gencolitems[0].obj.func_name == 'func1'
-        assert gencolitems[1].name == "['m2']"
-        assert gencolitems[1].obj.func_name == 'func1'        
-
-    def test_module_assertion_setup(self, testdir):
-        modcol = testdir.getmodulecol("pass")
-        from py.__.magic import assertion
-        l = []
-        py.magic.patch(assertion, "invoke", lambda: l.append(None))
-        try:
-            modcol.setup()
-        finally:
-            py.magic.revert(assertion, "invoke")
-        x = l.pop()
-        assert x is None
-        py.magic.patch(assertion, "revoke", lambda: l.append(None))
-        try:
-            modcol.teardown()
-        finally:
-            py.magic.revert(assertion, "revoke")
-        x = l.pop()
-        assert x is None
-
-    def test_check_equality_and_cmp_basic(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def test_pass(): pass
-            def test_fail(): assert 0
-        """)
-        fn1 = modcol.collect_by_name("test_pass")
-        assert isinstance(fn1, py.test.collect.Function)
-        fn2 = modcol.collect_by_name("test_pass")
-        assert isinstance(fn2, py.test.collect.Function)
-
-        assert fn1 == fn2
-        assert fn1 != modcol 
-        assert cmp(fn1, fn2) == 0
-        assert hash(fn1) == hash(fn2) 
-
-        fn3 = modcol.collect_by_name("test_fail")
-        assert isinstance(fn3, py.test.collect.Function)
-        assert not (fn1 == fn3) 
-        assert fn1 != fn3
-        assert cmp(fn1, fn3) == -1
-
-        assert cmp(fn1, 10) == -1 
-        assert cmp(fn2, 10) == -1 
-        assert cmp(fn3, 10) == -1 
-        for fn in fn1,fn2,fn3:
-            assert fn != 3
-            assert fn != modcol
-            assert fn != [1,2,3]
-            assert [1,2,3] != fn
-            assert modcol != fn
-
     def test_directory_file_sorting(self, testdir):
         p1 = testdir.makepyfile(test_one="hello")
         p1.dirpath().mkdir("x")
@@ -261,78 +137,7 @@
         res2 = modcol.collect()
         assert res1 == [x.name for x in res2]
 
-    def test_allow_sane_sorting_for_decorators(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def dec(f):
-                g = lambda: f(2)
-                g.place_as = f
-                return g
-
-
-            def test_a(y):
-                pass
-            test_a = dec(test_a)
-
-            def test_b(y):
-                pass
-            test_b = dec(test_b)
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 2
-        f1, f2 = colitems
-        assert cmp(f2, f1) > 0
-
-
 class TestCustomConftests:
-    def test_extra_python_files_and_functions(self, testdir):
-        testdir.makepyfile(conftest="""
-            import py
-            class MyFunction(py.test.collect.Function):
-                pass
-            class Directory(py.test.collect.Directory):
-                def consider_file(self, path):
-                    if path.check(fnmatch="check_*.py"):
-                        return self.Module(path, parent=self)
-                    return super(Directory, self).consider_file(path)
-            class myfuncmixin: 
-                Function = MyFunction
-                def funcnamefilter(self, name): 
-                    return name.startswith('check_') 
-            class Module(myfuncmixin, py.test.collect.Module):
-                def classnamefilter(self, name): 
-                    return name.startswith('CustomTestClass') 
-            class Instance(myfuncmixin, py.test.collect.Instance):
-                pass 
-        """)
-        checkfile = testdir.makepyfile(check_file="""
-            def check_func():
-                assert 42 == 42
-            class CustomTestClass:
-                def check_method(self):
-                    assert 23 == 23
-        """)
-        # check that directory collects "check_" files 
-        config = testdir.parseconfig()
-        col = config.getfsnode(checkfile.dirpath())
-        colitems = col.collect()
-        assert len(colitems) == 1
-        assert isinstance(colitems[0], py.test.collect.Module)
-
-        # check that module collects "check_" functions and methods
-        config = testdir.parseconfig(checkfile)
-        col = config.getfsnode(checkfile)
-        assert isinstance(col, py.test.collect.Module)
-        colitems = col.collect()
-        assert len(colitems) == 2
-        funccol = colitems[0]
-        assert isinstance(funccol, py.test.collect.Function)
-        assert funccol.name == "check_func"
-        clscol = colitems[1]
-        assert isinstance(clscol, py.test.collect.Class)
-        colitems = clscol.collect()[0].collect()
-        assert len(colitems) == 1
-        assert colitems[0].name == "check_method"
-
     def test_non_python_files(self, testdir):
         testdir.makepyfile(conftest="""
             import py
@@ -358,188 +163,6 @@
         assert item.name == "hello.xxx"
         assert item.__class__.__name__ == "CustomItem"
 
-def test_module_file_not_found(tmpdir):
-    fn = tmpdir.join('nada','no')
-    col = py.test.collect.Module(fn, config=dummyconfig) 
-    py.test.raises(py.error.ENOENT, col.collect) 
-
-
-def test_order_of_execution_generator_same_codeline(testdir, tmpdir):
-    o = testdir.makepyfile("""
-        def test_generative_order_of_execution():
-            test_list = []
-            expected_list = range(6)
-
-            def list_append(item):
-                test_list.append(item)
-                
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-            
-            for i in expected_list:
-                yield list_append, i
-            yield assert_order_of_execution
-    """)
-    sorter = testdir.inline_run(o)
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 7
-    assert not skipped and not failed 
-
-def test_order_of_execution_generator_different_codeline(testdir):
-    o = testdir.makepyfile("""
-        def test_generative_tests_different_codeline():
-            test_list = []
-            expected_list = range(3)
-
-            def list_append_2():
-                test_list.append(2)
-
-            def list_append_1():
-                test_list.append(1)
-
-            def list_append_0():
-                test_list.append(0)
-
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-                
-            yield list_append_0
-            yield list_append_1
-            yield list_append_2
-            yield assert_order_of_execution   
-    """)
-    sorter = testdir.inline_run(o) # .events_from_cmdline([o])
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 4
-    assert not skipped and not failed 
-
-def test_function_equality(tmpdir):
-    config = py.test.config._reparse([tmpdir])
-    f1 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    f2 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=callable)
-    assert not f1 == f2
-    assert f1 != f2
-    f3 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,2), callobj=callable)
-    assert not f3 == f2
-    assert f3 != f2
-
-    assert not f3 == f1
-    assert f3 != f1
-
-    f1_b = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    assert f1 == f1_b
-    assert not f1 != f1_b
-    
-class Testgenitems: 
-    def test_check_collect_hashes(self, testdir):
-        p = testdir.makepyfile("""
-            def test_1():
-                pass
-
-            def test_2():
-                pass
-        """)
-        p.copy(p.dirpath(p.purebasename + "2" + ".py"))
-        items, events = testdir.inline_genitems(p.dirpath())
-        assert len(items) == 4
-        for numi, i in enumerate(items):
-            for numj, j in enumerate(items):
-                if numj != numi:
-                    assert hash(i) != hash(j)
-                    assert i != j
-       
-    def test_root_conftest_syntax_error(self, testdir):
-        # do we want to unify behaviour with
-        # test_subdir_conftest_error? 
-        p = testdir.makepyfile(conftest="raise SyntaxError\n")
-        py.test.raises(SyntaxError, testdir.inline_genitems, p.dirpath())
-       
-    def test_subdir_conftest_error(self, testdir):
-        tmp = testdir.tmpdir
-        tmp.ensure("sub", "conftest.py").write("raise SyntaxError\n")
-        items, events = testdir.inline_genitems(tmp)
-        collectionfailures = events.getfailedcollections()
-        assert len(collectionfailures) == 1
-        ev = collectionfailures[0] 
-        assert ev.longrepr.reprcrash.message.startswith("SyntaxError")
-
-    def test_example_items1(self, testdir):
-        p = testdir.makepyfile('''
-            def testone():
-                pass
-
-            class TestX:
-                def testmethod_one(self):
-                    pass
-
-            class TestY(TestX):
-                pass
-        ''')
-        items, events = testdir.inline_genitems(p)
-        assert len(items) == 3
-        assert items[0].name == 'testone'
-        assert items[1].name == 'testmethod_one'
-        assert items[2].name == 'testmethod_one'
-
-        # let's also test getmodpath here
-        assert items[0].getmodpath() == "testone"
-        assert items[1].getmodpath() == "TestX.testmethod_one"
-        assert items[2].getmodpath() == "TestY.testmethod_one"
-
-        s = items[0].getmodpath(stopatmodule=False)
-        assert s.endswith("test_example_items1.testone")
-        print s
-
-    def test_collect_doctest_files_with_test_prefix(self, testdir):
-        testdir.maketxtfile(whatever="")
-        checkfile = testdir.maketxtfile(test_something="""
-            alskdjalsdk
-            >>> i = 5
-            >>> i-1
-            4
-        """)
-        for x in (testdir.tmpdir, checkfile): 
-            #print "checking that %s returns custom items" % (x,) 
-            items, events = testdir.inline_genitems(x)
-            assert len(items) == 1
-            assert isinstance(items[0], DoctestFileContent)
-
-class TestCollector:
-    def test_totrail_and_back(self, tmpdir):
-        a = tmpdir.ensure("a", dir=1)
-        tmpdir.ensure("a", "__init__.py")
-        x = tmpdir.ensure("a", "trail.py")
-        config = py.test.config._reparse([x])
-        col = config.getfsnode(x)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == a.relto(config.topdir)
-        assert trail[1] == ('trail.py',)
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.listnames() == col.listnames()
-       
-    def test_totrail_topdir_and_beyond(self, tmpdir):
-        config = py.test.config._reparse([tmpdir])
-        col = config.getfsnode(config.topdir)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == '.'
-        assert trail[1] == ()
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.fspath == config.topdir
-        assert len(col2.listchain()) == 1
-        col3 = config.getfsnode(config.topdir.dirpath())
-        py.test.raises(ValueError, 
-              "col3._totrail()")
-        
 class TestCollectorReprs:
     def test_repr_metainfo_basic_item(self, testdir):
         modcol = testdir.getmodulecol("")
@@ -599,55 +222,3 @@
                 def test_method(self):
                     pass
        """
-
-from py.__.test.dsession.mypickle import ImmutablePickler
-class PickleTransport:
-    def __init__(self):
-        self.p1 = ImmutablePickler(uneven=0)
-        self.p2 = ImmutablePickler(uneven=1)
-
-    def p1_to_p2(self, obj):
-        return self.p2.loads(self.p1.dumps(obj))
-
-    def p2_to_p1(self, obj):
-        return self.p1.loads(self.p2.dumps(obj))
-
-class TestPickling:
-    def setup_method(self, method):
-        pt = PickleTransport()
-        self.p1_to_p2 = pt.p1_to_p2
-        self.p2_to_p1 = pt.p2_to_p1
-
-    def unifyconfig(self, config):
-        p2config = self.p1_to_p2(config)
-        p2config._initafterpickle(config.topdir)
-        return p2config
-
-    def test_pickle_config(self):
-        config1 = py.test.config._reparse([])
-        p2config = self.unifyconfig(config1)
-        assert p2config.topdir == config1.topdir
-        config_back = self.p2_to_p1(p2config)
-        assert config_back is config1
-
-    def test_pickle_module(self, testdir):
-        modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
-
-        modcol2a = self.p1_to_p2(modcol1)
-        modcol2b = self.p1_to_p2(modcol1)
-        assert modcol2a is modcol2b
-
-        modcol1_back = self.p2_to_p1(modcol2a)
-        assert modcol1_back
-
-    def test_pickle_func(self, testdir):
-        modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
-        item = modcol1.collect_by_name("test_one")
-        item2a = self.p1_to_p2(item)
-        assert item is not item2a # of course
-        assert item2a.name == item.name
-        modback = self.p2_to_p1(item2a.parent)
-        assert modback is modcol1
-

Copied: py/branch/pytestplugin/py/test/testing/test_collect_pickle.py (from r62008, py/branch/pytestplugin/py/test/testing/test_collect.py)
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_collect.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_collect_pickle.py	Sat Feb 21 18:05:43 2009
@@ -1,608 +1,9 @@
-from __future__ import generators
 import py
-from py.__.test import event, outcome 
-from py.__.test.conftesthandle import Conftest
-from py.__.test.collect import SetupState
-from py.__.test.pycollect import DoctestFileContent
 
 
-
-class DummyConfig:
-    def __init__(self):
-        self._conftest = Conftest()
-        self._setupstate = SetupState()
-        self.args = []
-        class dummyoption:
-            nomagic = False
-        self.option = dummyoption
-    def getvalue(self, name, fspath):
-        return self._conftest.rget(name, fspath)
-
-def setup_module(mod):
-    mod.dummyconfig = DummyConfig()
-
-def test_collect_versus_item():
-    from py.__.test.collect import Collector, Item
-    assert not issubclass(Collector, Item)
-    assert not issubclass(Item, Collector)
-
-def test_ignored_certain_directories(tmpdir): 
-    tmpdir.ensure("_darcs", 'test_notfound.py')
-    tmpdir.ensure("CVS", 'test_notfound.py')
-    tmpdir.ensure("{arch}", 'test_notfound.py')
-    tmpdir.ensure(".whatever", 'test_notfound.py')
-    tmpdir.ensure(".bzr", 'test_notfound.py')
-    tmpdir.ensure("normal", 'test_found.py')
-    tmpdir.ensure('test_found.py')
-
-    col = py.test.collect.Directory(tmpdir, config=dummyconfig) 
-    items = col.collect()
-    names = [x.name for x in items]
-    assert len(items) == 2
-    assert 'normal' in names
-    assert 'test_found.py' in names
-
-class TestCollect:
-    def test_failing_import(self, testdir):
-        modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
-        py.test.raises(ImportError, modcol.collect)
-        py.test.raises(ImportError, modcol.collect)
-        py.test.raises(ImportError, modcol.run)
-
-    def test_syntax_error_in_module(self, testdir):
-        modcol = testdir.getmodulecol("this is a syntax error") 
-        py.test.raises(SyntaxError, modcol.collect)
-        py.test.raises(SyntaxError, modcol.collect)
-        py.test.raises(SyntaxError, modcol.run)
-
-    def test_listnames_and__getitembynames(self, testdir):
-        modcol = testdir.getmodulecol("pass", withinit=True)
-        names = modcol.listnames()
-        print names
-        dircol = modcol._config.getfsnode(modcol._config.topdir)
-        x = dircol._getitembynames(names)
-        assert modcol.name == x.name 
-        assert modcol.name == x.name 
-
-    def test_listnames_getitembynames_custom(self, testdir):
-        hello = testdir.makefile(".xxx", hello="world")
-        testdir.makepyfile(conftest="""
-            import py
-            class CustomFile(py.test.collect.File):
-                pass
-            class MyDirectory(py.test.collect.Directory):
-                def collect(self):
-                    return [CustomFile(self.fspath.join("hello.xxx"), parent=self)]
-            Directory = MyDirectory
-        """)
-        config = testdir.parseconfig(hello)
-        node = config.getfsnode(hello)
-        assert isinstance(node, py.test.collect.File)
-        assert node.name == "hello.xxx"
-        names = node.listnames()[1:]
-        dircol = config.getfsnode(config.topdir) 
-        node = dircol._getitembynames(names)
-        assert isinstance(node, py.test.collect.File)
-
-    def test_found_certain_testfiles(self, testdir): 
-        p1 = testdir.makepyfile(test_found = "pass", found_test="pass")
-        col = py.test.collect.Directory(p1.dirpath(), config=dummyconfig) 
-        items = col.collect() # Directory collect returns files sorted by name
-        assert len(items) == 2
-        assert items[1].name == 'test_found.py'
-        assert items[0].name == 'found_test.py'
-
-    def test_disabled_class(self, testdir):
-        modcol = testdir.getmodulecol("""
-            class TestClass:
-                disabled = True
-                def test_method(self):
-                    pass
-        """)
-        l = modcol.collect()
-        assert len(l) == 1
-        modcol = l[0]
-        assert isinstance(modcol, py.test.collect.Class)
-        assert not modcol.collect() 
-
-    def test_disabled_module(self, testdir):
-        modcol = testdir.getmodulecol("""
-            disabled = True
-            def setup_module(mod):
-                raise ValueError
-        """)
-        assert not modcol.collect() 
-        assert not modcol.run() 
-
-    def test_generative_functions(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-
-            def test_gen(): 
-                yield func1, 17, 3*5
-                yield func1, 42, 6*7
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 1
-        gencol = colitems[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == '[0]'
-        assert gencolitems[0].obj.func_name == 'func1'
-
-    def test_generative_methods(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-            class TestGenMethods: 
-                def test_gen(self): 
-                    yield func1, 17, 3*5
-                    yield func1, 42, 6*7
-        """)
-        gencol = modcol.collect()[0].collect()[0].collect()[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == '[0]'
-        assert gencolitems[0].obj.func_name == 'func1'
-
-    def test_generative_functions_with_explicit_names(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-
-            def test_gen(): 
-                yield "seventeen", func1, 17, 3*5
-                yield "fortytwo", func1, 42, 6*7
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 1
-        gencol = colitems[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == "['seventeen']"
-        assert gencolitems[0].obj.func_name == 'func1'
-        assert gencolitems[1].name == "['fortytwo']"
-        assert gencolitems[1].obj.func_name == 'func1'        
-
-    def test_generative_methods_with_explicit_names(self, testdir): 
-        modcol = testdir.getmodulecol("""
-            def func1(arg, arg2): 
-                assert arg == arg2 
-            class TestGenMethods: 
-                def test_gen(self): 
-                    yield "m1", func1, 17, 3*5
-                    yield "m2", func1, 42, 6*7
-        """)
-        gencol = modcol.collect()[0].collect()[0].collect()[0]
-        assert isinstance(gencol, py.test.collect.Generator)
-        gencolitems = gencol.collect()
-        assert len(gencolitems) == 2
-        assert isinstance(gencolitems[0], py.test.collect.Function)
-        assert isinstance(gencolitems[1], py.test.collect.Function)
-        assert gencolitems[0].name == "['m1']"
-        assert gencolitems[0].obj.func_name == 'func1'
-        assert gencolitems[1].name == "['m2']"
-        assert gencolitems[1].obj.func_name == 'func1'        
-
-    def test_module_assertion_setup(self, testdir):
-        modcol = testdir.getmodulecol("pass")
-        from py.__.magic import assertion
-        l = []
-        py.magic.patch(assertion, "invoke", lambda: l.append(None))
-        try:
-            modcol.setup()
-        finally:
-            py.magic.revert(assertion, "invoke")
-        x = l.pop()
-        assert x is None
-        py.magic.patch(assertion, "revoke", lambda: l.append(None))
-        try:
-            modcol.teardown()
-        finally:
-            py.magic.revert(assertion, "revoke")
-        x = l.pop()
-        assert x is None
-
-    def test_check_equality_and_cmp_basic(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def test_pass(): pass
-            def test_fail(): assert 0
-        """)
-        fn1 = modcol.collect_by_name("test_pass")
-        assert isinstance(fn1, py.test.collect.Function)
-        fn2 = modcol.collect_by_name("test_pass")
-        assert isinstance(fn2, py.test.collect.Function)
-
-        assert fn1 == fn2
-        assert fn1 != modcol 
-        assert cmp(fn1, fn2) == 0
-        assert hash(fn1) == hash(fn2) 
-
-        fn3 = modcol.collect_by_name("test_fail")
-        assert isinstance(fn3, py.test.collect.Function)
-        assert not (fn1 == fn3) 
-        assert fn1 != fn3
-        assert cmp(fn1, fn3) == -1
-
-        assert cmp(fn1, 10) == -1 
-        assert cmp(fn2, 10) == -1 
-        assert cmp(fn3, 10) == -1 
-        for fn in fn1,fn2,fn3:
-            assert fn != 3
-            assert fn != modcol
-            assert fn != [1,2,3]
-            assert [1,2,3] != fn
-            assert modcol != fn
-
-    def test_directory_file_sorting(self, testdir):
-        p1 = testdir.makepyfile(test_one="hello")
-        p1.dirpath().mkdir("x")
-        p1.dirpath().mkdir("dir1")
-        testdir.makepyfile(test_two="hello")
-        p1.dirpath().mkdir("dir2")
-        config = testdir.parseconfig()
-        col = config.getfsnode(p1.dirpath())
-        names = [x.name for x in col.collect()]
-        assert names == ["dir1", "dir2", "test_one.py", "test_two.py", "x"]
-
-    def test_collector_deprecated_run_method(self, testdir):
-        modcol = testdir.getmodulecol("pass")
-        res1 = py.test.deprecated_call(modcol.run)
-        res2 = modcol.collect()
-        assert res1 == [x.name for x in res2]
-
-    def test_allow_sane_sorting_for_decorators(self, testdir):
-        modcol = testdir.getmodulecol("""
-            def dec(f):
-                g = lambda: f(2)
-                g.place_as = f
-                return g
-
-
-            def test_a(y):
-                pass
-            test_a = dec(test_a)
-
-            def test_b(y):
-                pass
-            test_b = dec(test_b)
-        """)
-        colitems = modcol.collect()
-        assert len(colitems) == 2
-        f1, f2 = colitems
-        assert cmp(f2, f1) > 0
-
-
-class TestCustomConftests:
-    def test_extra_python_files_and_functions(self, testdir):
-        testdir.makepyfile(conftest="""
-            import py
-            class MyFunction(py.test.collect.Function):
-                pass
-            class Directory(py.test.collect.Directory):
-                def consider_file(self, path):
-                    if path.check(fnmatch="check_*.py"):
-                        return self.Module(path, parent=self)
-                    return super(Directory, self).consider_file(path)
-            class myfuncmixin: 
-                Function = MyFunction
-                def funcnamefilter(self, name): 
-                    return name.startswith('check_') 
-            class Module(myfuncmixin, py.test.collect.Module):
-                def classnamefilter(self, name): 
-                    return name.startswith('CustomTestClass') 
-            class Instance(myfuncmixin, py.test.collect.Instance):
-                pass 
-        """)
-        checkfile = testdir.makepyfile(check_file="""
-            def check_func():
-                assert 42 == 42
-            class CustomTestClass:
-                def check_method(self):
-                    assert 23 == 23
-        """)
-        # check that directory collects "check_" files 
-        config = testdir.parseconfig()
-        col = config.getfsnode(checkfile.dirpath())
-        colitems = col.collect()
-        assert len(colitems) == 1
-        assert isinstance(colitems[0], py.test.collect.Module)
-
-        # check that module collects "check_" functions and methods
-        config = testdir.parseconfig(checkfile)
-        col = config.getfsnode(checkfile)
-        assert isinstance(col, py.test.collect.Module)
-        colitems = col.collect()
-        assert len(colitems) == 2
-        funccol = colitems[0]
-        assert isinstance(funccol, py.test.collect.Function)
-        assert funccol.name == "check_func"
-        clscol = colitems[1]
-        assert isinstance(clscol, py.test.collect.Class)
-        colitems = clscol.collect()[0].collect()
-        assert len(colitems) == 1
-        assert colitems[0].name == "check_method"
-
-    def test_non_python_files(self, testdir):
-        testdir.makepyfile(conftest="""
-            import py
-            class CustomItem(py.test.collect.Item): 
-                def run(self):
-                    pass
-            class Directory(py.test.collect.Directory):
-                def consider_file(self, fspath):
-                    if fspath.ext == ".xxx":
-                        return CustomItem(fspath.basename, parent=self)
-        """)
-        checkfile = testdir.makefile(ext="xxx", hello="world")
-        testdir.makepyfile(x="")
-        testdir.maketxtfile(x="")
-        config = testdir.parseconfig()
-        dircol = config.getfsnode(checkfile.dirpath())
-        colitems = dircol.collect()
-        assert len(colitems) == 1
-        assert colitems[0].name == "hello.xxx"
-        assert colitems[0].__class__.__name__ == "CustomItem"
-
-        item = config.getfsnode(checkfile)
-        assert item.name == "hello.xxx"
-        assert item.__class__.__name__ == "CustomItem"
-
-def test_module_file_not_found(tmpdir):
-    fn = tmpdir.join('nada','no')
-    col = py.test.collect.Module(fn, config=dummyconfig) 
-    py.test.raises(py.error.ENOENT, col.collect) 
-
-
-def test_order_of_execution_generator_same_codeline(testdir, tmpdir):
-    o = testdir.makepyfile("""
-        def test_generative_order_of_execution():
-            test_list = []
-            expected_list = range(6)
-
-            def list_append(item):
-                test_list.append(item)
-                
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-            
-            for i in expected_list:
-                yield list_append, i
-            yield assert_order_of_execution
-    """)
-    sorter = testdir.inline_run(o)
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 7
-    assert not skipped and not failed 
-
-def test_order_of_execution_generator_different_codeline(testdir):
-    o = testdir.makepyfile("""
-        def test_generative_tests_different_codeline():
-            test_list = []
-            expected_list = range(3)
-
-            def list_append_2():
-                test_list.append(2)
-
-            def list_append_1():
-                test_list.append(1)
-
-            def list_append_0():
-                test_list.append(0)
-
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-                
-            yield list_append_0
-            yield list_append_1
-            yield list_append_2
-            yield assert_order_of_execution   
-    """)
-    sorter = testdir.inline_run(o) # .events_from_cmdline([o])
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 4
-    assert not skipped and not failed 
-
-def test_function_equality(tmpdir):
-    config = py.test.config._reparse([tmpdir])
-    f1 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    f2 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=callable)
-    assert not f1 == f2
-    assert f1 != f2
-    f3 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,2), callobj=callable)
-    assert not f3 == f2
-    assert f3 != f2
-
-    assert not f3 == f1
-    assert f3 != f1
-
-    f1_b = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    assert f1 == f1_b
-    assert not f1 != f1_b
-    
-class Testgenitems: 
-    def test_check_collect_hashes(self, testdir):
-        p = testdir.makepyfile("""
-            def test_1():
-                pass
-
-            def test_2():
-                pass
-        """)
-        p.copy(p.dirpath(p.purebasename + "2" + ".py"))
-        items, events = testdir.inline_genitems(p.dirpath())
-        assert len(items) == 4
-        for numi, i in enumerate(items):
-            for numj, j in enumerate(items):
-                if numj != numi:
-                    assert hash(i) != hash(j)
-                    assert i != j
-       
-    def test_root_conftest_syntax_error(self, testdir):
-        # do we want to unify behaviour with
-        # test_subdir_conftest_error? 
-        p = testdir.makepyfile(conftest="raise SyntaxError\n")
-        py.test.raises(SyntaxError, testdir.inline_genitems, p.dirpath())
-       
-    def test_subdir_conftest_error(self, testdir):
-        tmp = testdir.tmpdir
-        tmp.ensure("sub", "conftest.py").write("raise SyntaxError\n")
-        items, events = testdir.inline_genitems(tmp)
-        collectionfailures = events.getfailedcollections()
-        assert len(collectionfailures) == 1
-        ev = collectionfailures[0] 
-        assert ev.longrepr.reprcrash.message.startswith("SyntaxError")
-
-    def test_example_items1(self, testdir):
-        p = testdir.makepyfile('''
-            def testone():
-                pass
-
-            class TestX:
-                def testmethod_one(self):
-                    pass
-
-            class TestY(TestX):
-                pass
-        ''')
-        items, events = testdir.inline_genitems(p)
-        assert len(items) == 3
-        assert items[0].name == 'testone'
-        assert items[1].name == 'testmethod_one'
-        assert items[2].name == 'testmethod_one'
-
-        # let's also test getmodpath here
-        assert items[0].getmodpath() == "testone"
-        assert items[1].getmodpath() == "TestX.testmethod_one"
-        assert items[2].getmodpath() == "TestY.testmethod_one"
-
-        s = items[0].getmodpath(stopatmodule=False)
-        assert s.endswith("test_example_items1.testone")
-        print s
-
-    def test_collect_doctest_files_with_test_prefix(self, testdir):
-        testdir.maketxtfile(whatever="")
-        checkfile = testdir.maketxtfile(test_something="""
-            alskdjalsdk
-            >>> i = 5
-            >>> i-1
-            4
-        """)
-        for x in (testdir.tmpdir, checkfile): 
-            #print "checking that %s returns custom items" % (x,) 
-            items, events = testdir.inline_genitems(x)
-            assert len(items) == 1
-            assert isinstance(items[0], DoctestFileContent)
-
-class TestCollector:
-    def test_totrail_and_back(self, tmpdir):
-        a = tmpdir.ensure("a", dir=1)
-        tmpdir.ensure("a", "__init__.py")
-        x = tmpdir.ensure("a", "trail.py")
-        config = py.test.config._reparse([x])
-        col = config.getfsnode(x)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == a.relto(config.topdir)
-        assert trail[1] == ('trail.py',)
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.listnames() == col.listnames()
-       
-    def test_totrail_topdir_and_beyond(self, tmpdir):
-        config = py.test.config._reparse([tmpdir])
-        col = config.getfsnode(config.topdir)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == '.'
-        assert trail[1] == ()
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.fspath == config.topdir
-        assert len(col2.listchain()) == 1
-        col3 = config.getfsnode(config.topdir.dirpath())
-        py.test.raises(ValueError, 
-              "col3._totrail()")
-        
-class TestCollectorReprs:
-    def test_repr_metainfo_basic_item(self, testdir):
-        modcol = testdir.getmodulecol("")
-        Item = py.test.collect.Item
-        item = Item("virtual", parent=modcol)
-        info = item.repr_metainfo() 
-        assert info.fspath == modcol.fspath
-        assert not info.lineno
-        assert info.modpath == "Item"
-        
-    def test_repr_metainfo_func(self, testdir):
-        item = testdir.getitem("def test_func(): pass")
-        info = item.repr_metainfo()
-        assert info.fspath == item.fspath 
-        assert info.lineno == 0
-        assert info.modpath == "test_func"
-
-    def test_repr_metainfo_class(self, testdir):
-        modcol = testdir.getmodulecol("""
-            # lineno 0
-            class TestClass:
-                def test_hello(self): pass
-        """)
-        classcol = modcol.collect_by_name("TestClass")
-        info = classcol.repr_metainfo()
-        assert info.fspath == modcol.fspath 
-        assert info.lineno == 1
-        assert info.modpath == "TestClass"
-
-    def test_repr_metainfo_generator(self, testdir):
-        modcol = testdir.getmodulecol("""
-            # lineno 0
-            def test_gen(): 
-                def check(x): 
-                    assert x
-                yield check, 3
-        """)
-        gencol = modcol.collect_by_name("test_gen")
-        info = gencol.repr_metainfo()
-        assert info.fspath == modcol.fspath
-        assert info.lineno == 1
-        assert info.modpath == "test_gen"
-
-        genitem = gencol.collect()[0]
-        info = genitem.repr_metainfo()
-        assert info.fspath == modcol.fspath
-        assert info.lineno == 2
-        assert info.modpath == "test_gen[0]"
-        """
-            def test_func():
-                pass
-            def test_genfunc():
-                def check(x):
-                    pass
-                yield check, 3
-            class TestClass:
-                def test_method(self):
-                    pass
-       """
-
-from py.__.test.dsession.mypickle import ImmutablePickler
 class PickleTransport:
     def __init__(self):
+        from py.__.test.dsession.mypickle import ImmutablePickler
         self.p1 = ImmutablePickler(uneven=0)
         self.p2 = ImmutablePickler(uneven=1)
 
@@ -612,42 +13,42 @@
     def p2_to_p1(self, obj):
         return self.p1.loads(self.p2.dumps(obj))
 
-class TestPickling:
-    def setup_method(self, method):
-        pt = PickleTransport()
-        self.p1_to_p2 = pt.p1_to_p2
-        self.p2_to_p1 = pt.p2_to_p1
-
     def unifyconfig(self, config):
         p2config = self.p1_to_p2(config)
         p2config._initafterpickle(config.topdir)
         return p2config
 
-    def test_pickle_config(self):
+class TestPickling:
+    def pytest_pyfunc_arg(self, pyfuncitem, argname):
+        if argname == "pickletransport":
+            pt = PickleTransport()
+            return pt, None
+
+    def test_pickle_config(self, pickletransport):
         config1 = py.test.config._reparse([])
-        p2config = self.unifyconfig(config1)
+        p2config = pickletransport.unifyconfig(config1)
         assert p2config.topdir == config1.topdir
-        config_back = self.p2_to_p1(p2config)
+        config_back = pickletransport.p2_to_p1(p2config)
         assert config_back is config1
 
-    def test_pickle_module(self, testdir):
+    def test_pickle_module(self, testdir, pickletransport):
         modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
+        pickletransport.unifyconfig(modcol1._config) 
 
-        modcol2a = self.p1_to_p2(modcol1)
-        modcol2b = self.p1_to_p2(modcol1)
+        modcol2a = pickletransport.p1_to_p2(modcol1)
+        modcol2b = pickletransport.p1_to_p2(modcol1)
         assert modcol2a is modcol2b
 
-        modcol1_back = self.p2_to_p1(modcol2a)
+        modcol1_back = pickletransport.p2_to_p1(modcol2a)
         assert modcol1_back
 
-    def test_pickle_func(self, testdir):
+    def test_pickle_func(self, testdir, pickletransport):
         modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
+        pickletransport.unifyconfig(modcol1._config) 
         item = modcol1.collect_by_name("test_one")
-        item2a = self.p1_to_p2(item)
+        item2a = pickletransport.p1_to_p2(item)
         assert item is not item2a # of course
         assert item2a.name == item.name
-        modback = self.p2_to_p1(item2a.parent)
+        modback = pickletransport.p2_to_p1(item2a.parent)
         assert modback is modcol1
 

Copied: py/branch/pytestplugin/py/test/testing/test_pycollect.py (from r62008, py/branch/pytestplugin/py/test/testing/test_collect.py)
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_collect.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_pycollect.py	Sat Feb 21 18:05:43 2009
@@ -1,48 +1,12 @@
-from __future__ import generators
 import py
-from py.__.test import event, outcome 
-from py.__.test.conftesthandle import Conftest
-from py.__.test.collect import SetupState
-from py.__.test.pycollect import DoctestFileContent
 
+class TestModule:
+    def test_module_file_not_found(self, testdir):
+        tmpdir = testdir.tmpdir
+        fn = tmpdir.join('nada','no')
+        col = py.test.collect.Module(fn, config=testdir.parseconfig(tmpdir))
+        py.test.raises(py.error.ENOENT, col.collect) 
 
-
-class DummyConfig:
-    def __init__(self):
-        self._conftest = Conftest()
-        self._setupstate = SetupState()
-        self.args = []
-        class dummyoption:
-            nomagic = False
-        self.option = dummyoption
-    def getvalue(self, name, fspath):
-        return self._conftest.rget(name, fspath)
-
-def setup_module(mod):
-    mod.dummyconfig = DummyConfig()
-
-def test_collect_versus_item():
-    from py.__.test.collect import Collector, Item
-    assert not issubclass(Collector, Item)
-    assert not issubclass(Item, Collector)
-
-def test_ignored_certain_directories(tmpdir): 
-    tmpdir.ensure("_darcs", 'test_notfound.py')
-    tmpdir.ensure("CVS", 'test_notfound.py')
-    tmpdir.ensure("{arch}", 'test_notfound.py')
-    tmpdir.ensure(".whatever", 'test_notfound.py')
-    tmpdir.ensure(".bzr", 'test_notfound.py')
-    tmpdir.ensure("normal", 'test_found.py')
-    tmpdir.ensure('test_found.py')
-
-    col = py.test.collect.Directory(tmpdir, config=dummyconfig) 
-    items = col.collect()
-    names = [x.name for x in items]
-    assert len(items) == 2
-    assert 'normal' in names
-    assert 'test_found.py' in names
-
-class TestCollect:
     def test_failing_import(self, testdir):
         modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
         py.test.raises(ImportError, modcol.collect)
@@ -55,43 +19,35 @@
         py.test.raises(SyntaxError, modcol.collect)
         py.test.raises(SyntaxError, modcol.run)
 
-    def test_listnames_and__getitembynames(self, testdir):
-        modcol = testdir.getmodulecol("pass", withinit=True)
-        names = modcol.listnames()
-        print names
-        dircol = modcol._config.getfsnode(modcol._config.topdir)
-        x = dircol._getitembynames(names)
-        assert modcol.name == x.name 
-        assert modcol.name == x.name 
+    def test_module_assertion_setup(self, testdir):
+        modcol = testdir.getmodulecol("pass")
+        from py.__.magic import assertion
+        l = []
+        py.magic.patch(assertion, "invoke", lambda: l.append(None))
+        try:
+            modcol.setup()
+        finally:
+            py.magic.revert(assertion, "invoke")
+        x = l.pop()
+        assert x is None
+        py.magic.patch(assertion, "revoke", lambda: l.append(None))
+        try:
+            modcol.teardown()
+        finally:
+            py.magic.revert(assertion, "revoke")
+        x = l.pop()
+        assert x is None
 
-    def test_listnames_getitembynames_custom(self, testdir):
-        hello = testdir.makefile(".xxx", hello="world")
-        testdir.makepyfile(conftest="""
-            import py
-            class CustomFile(py.test.collect.File):
-                pass
-            class MyDirectory(py.test.collect.Directory):
-                def collect(self):
-                    return [CustomFile(self.fspath.join("hello.xxx"), parent=self)]
-            Directory = MyDirectory
-        """)
-        config = testdir.parseconfig(hello)
-        node = config.getfsnode(hello)
-        assert isinstance(node, py.test.collect.File)
-        assert node.name == "hello.xxx"
-        names = node.listnames()[1:]
-        dircol = config.getfsnode(config.topdir) 
-        node = dircol._getitembynames(names)
-        assert isinstance(node, py.test.collect.File)
-
-    def test_found_certain_testfiles(self, testdir): 
-        p1 = testdir.makepyfile(test_found = "pass", found_test="pass")
-        col = py.test.collect.Directory(p1.dirpath(), config=dummyconfig) 
-        items = col.collect() # Directory collect returns files sorted by name
-        assert len(items) == 2
-        assert items[1].name == 'test_found.py'
-        assert items[0].name == 'found_test.py'
+    def test_disabled_module(self, testdir):
+        modcol = testdir.getmodulecol("""
+            disabled = True
+            def setup_module(mod):
+                raise ValueError
+        """)
+        assert not modcol.collect() 
+        assert not modcol.run() 
 
+class TestClass:
     def test_disabled_class(self, testdir):
         modcol = testdir.getmodulecol("""
             class TestClass:
@@ -105,15 +61,7 @@
         assert isinstance(modcol, py.test.collect.Class)
         assert not modcol.collect() 
 
-    def test_disabled_module(self, testdir):
-        modcol = testdir.getmodulecol("""
-            disabled = True
-            def setup_module(mod):
-                raise ValueError
-        """)
-        assert not modcol.collect() 
-        assert not modcol.run() 
-
+class TestGenerator:
     def test_generative_functions(self, testdir): 
         modcol = testdir.getmodulecol("""
             def func1(arg, arg2): 
@@ -194,25 +142,82 @@
         assert gencolitems[1].name == "['m2']"
         assert gencolitems[1].obj.func_name == 'func1'        
 
-    def test_module_assertion_setup(self, testdir):
-        modcol = testdir.getmodulecol("pass")
-        from py.__.magic import assertion
-        l = []
-        py.magic.patch(assertion, "invoke", lambda: l.append(None))
-        try:
-            modcol.setup()
-        finally:
-            py.magic.revert(assertion, "invoke")
-        x = l.pop()
-        assert x is None
-        py.magic.patch(assertion, "revoke", lambda: l.append(None))
-        try:
-            modcol.teardown()
-        finally:
-            py.magic.revert(assertion, "revoke")
-        x = l.pop()
-        assert x is None
+    def test_order_of_execution_generator_same_codeline(self, testdir, tmpdir):
+        o = testdir.makepyfile("""
+            def test_generative_order_of_execution():
+                test_list = []
+                expected_list = range(6)
+
+                def list_append(item):
+                    test_list.append(item)
+                    
+                def assert_order_of_execution():
+                    print 'expected order', expected_list
+                    print 'but got       ', test_list
+                    assert test_list == expected_list
+                
+                for i in expected_list:
+                    yield list_append, i
+                yield assert_order_of_execution
+        """)
+        sorter = testdir.inline_run(o)
+        passed, skipped, failed = sorter.countoutcomes() 
+        assert passed == 7
+        assert not skipped and not failed 
+
+    def test_order_of_execution_generator_different_codeline(self, testdir):
+        o = testdir.makepyfile("""
+            def test_generative_tests_different_codeline():
+                test_list = []
+                expected_list = range(3)
+
+                def list_append_2():
+                    test_list.append(2)
+
+                def list_append_1():
+                    test_list.append(1)
+
+                def list_append_0():
+                    test_list.append(0)
+
+                def assert_order_of_execution():
+                    print 'expected order', expected_list
+                    print 'but got       ', test_list
+                    assert test_list == expected_list
+                    
+                yield list_append_0
+                yield list_append_1
+                yield list_append_2
+                yield assert_order_of_execution   
+        """)
+        sorter = testdir.inline_run(o) # .events_from_cmdline([o])
+        passed, skipped, failed = sorter.countoutcomes() 
+        assert passed == 4
+        assert not skipped and not failed 
+
+class TestFunction:
+    def test_function_equality(tmpdir):
+        config = py.test.config._reparse([tmpdir])
+        f1 = py.test.collect.Function(name="name", config=config, 
+                                      args=(1,), callobj=isinstance)
+        f2 = py.test.collect.Function(name="name", config=config, 
+                                      args=(1,), callobj=callable)
+        assert not f1 == f2
+        assert f1 != f2
+        f3 = py.test.collect.Function(name="name", config=config, 
+                                      args=(1,2), callobj=callable)
+        assert not f3 == f2
+        assert f3 != f2
+
+        assert not f3 == f1
+        assert f3 != f1
+
+        f1_b = py.test.collect.Function(name="name", config=config, 
+                                      args=(1,), callobj=isinstance)
+        assert f1 == f1_b
+        assert not f1 != f1_b
 
+class TestSorting:
     def test_check_equality_and_cmp_basic(self, testdir):
         modcol = testdir.getmodulecol("""
             def test_pass(): pass
@@ -244,23 +249,6 @@
             assert [1,2,3] != fn
             assert modcol != fn
 
-    def test_directory_file_sorting(self, testdir):
-        p1 = testdir.makepyfile(test_one="hello")
-        p1.dirpath().mkdir("x")
-        p1.dirpath().mkdir("dir1")
-        testdir.makepyfile(test_two="hello")
-        p1.dirpath().mkdir("dir2")
-        config = testdir.parseconfig()
-        col = config.getfsnode(p1.dirpath())
-        names = [x.name for x in col.collect()]
-        assert names == ["dir1", "dir2", "test_one.py", "test_two.py", "x"]
-
-    def test_collector_deprecated_run_method(self, testdir):
-        modcol = testdir.getmodulecol("pass")
-        res1 = py.test.deprecated_call(modcol.run)
-        res2 = modcol.collect()
-        assert res1 == [x.name for x in res2]
-
     def test_allow_sane_sorting_for_decorators(self, testdir):
         modcol = testdir.getmodulecol("""
             def dec(f):
@@ -282,8 +270,7 @@
         f1, f2 = colitems
         assert cmp(f2, f1) > 0
 
-
-class TestCustomConftests:
+class TestCustomConftest:
     def test_extra_python_files_and_functions(self, testdir):
         testdir.makepyfile(conftest="""
             import py
@@ -333,321 +320,3 @@
         assert len(colitems) == 1
         assert colitems[0].name == "check_method"
 
-    def test_non_python_files(self, testdir):
-        testdir.makepyfile(conftest="""
-            import py
-            class CustomItem(py.test.collect.Item): 
-                def run(self):
-                    pass
-            class Directory(py.test.collect.Directory):
-                def consider_file(self, fspath):
-                    if fspath.ext == ".xxx":
-                        return CustomItem(fspath.basename, parent=self)
-        """)
-        checkfile = testdir.makefile(ext="xxx", hello="world")
-        testdir.makepyfile(x="")
-        testdir.maketxtfile(x="")
-        config = testdir.parseconfig()
-        dircol = config.getfsnode(checkfile.dirpath())
-        colitems = dircol.collect()
-        assert len(colitems) == 1
-        assert colitems[0].name == "hello.xxx"
-        assert colitems[0].__class__.__name__ == "CustomItem"
-
-        item = config.getfsnode(checkfile)
-        assert item.name == "hello.xxx"
-        assert item.__class__.__name__ == "CustomItem"
-
-def test_module_file_not_found(tmpdir):
-    fn = tmpdir.join('nada','no')
-    col = py.test.collect.Module(fn, config=dummyconfig) 
-    py.test.raises(py.error.ENOENT, col.collect) 
-
-
-def test_order_of_execution_generator_same_codeline(testdir, tmpdir):
-    o = testdir.makepyfile("""
-        def test_generative_order_of_execution():
-            test_list = []
-            expected_list = range(6)
-
-            def list_append(item):
-                test_list.append(item)
-                
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-            
-            for i in expected_list:
-                yield list_append, i
-            yield assert_order_of_execution
-    """)
-    sorter = testdir.inline_run(o)
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 7
-    assert not skipped and not failed 
-
-def test_order_of_execution_generator_different_codeline(testdir):
-    o = testdir.makepyfile("""
-        def test_generative_tests_different_codeline():
-            test_list = []
-            expected_list = range(3)
-
-            def list_append_2():
-                test_list.append(2)
-
-            def list_append_1():
-                test_list.append(1)
-
-            def list_append_0():
-                test_list.append(0)
-
-            def assert_order_of_execution():
-                print 'expected order', expected_list
-                print 'but got       ', test_list
-                assert test_list == expected_list
-                
-            yield list_append_0
-            yield list_append_1
-            yield list_append_2
-            yield assert_order_of_execution   
-    """)
-    sorter = testdir.inline_run(o) # .events_from_cmdline([o])
-    passed, skipped, failed = sorter.countoutcomes() 
-    assert passed == 4
-    assert not skipped and not failed 
-
-def test_function_equality(tmpdir):
-    config = py.test.config._reparse([tmpdir])
-    f1 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    f2 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=callable)
-    assert not f1 == f2
-    assert f1 != f2
-    f3 = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,2), callobj=callable)
-    assert not f3 == f2
-    assert f3 != f2
-
-    assert not f3 == f1
-    assert f3 != f1
-
-    f1_b = py.test.collect.Function(name="name", config=config, 
-                                  args=(1,), callobj=isinstance)
-    assert f1 == f1_b
-    assert not f1 != f1_b
-    
-class Testgenitems: 
-    def test_check_collect_hashes(self, testdir):
-        p = testdir.makepyfile("""
-            def test_1():
-                pass
-
-            def test_2():
-                pass
-        """)
-        p.copy(p.dirpath(p.purebasename + "2" + ".py"))
-        items, events = testdir.inline_genitems(p.dirpath())
-        assert len(items) == 4
-        for numi, i in enumerate(items):
-            for numj, j in enumerate(items):
-                if numj != numi:
-                    assert hash(i) != hash(j)
-                    assert i != j
-       
-    def test_root_conftest_syntax_error(self, testdir):
-        # do we want to unify behaviour with
-        # test_subdir_conftest_error? 
-        p = testdir.makepyfile(conftest="raise SyntaxError\n")
-        py.test.raises(SyntaxError, testdir.inline_genitems, p.dirpath())
-       
-    def test_subdir_conftest_error(self, testdir):
-        tmp = testdir.tmpdir
-        tmp.ensure("sub", "conftest.py").write("raise SyntaxError\n")
-        items, events = testdir.inline_genitems(tmp)
-        collectionfailures = events.getfailedcollections()
-        assert len(collectionfailures) == 1
-        ev = collectionfailures[0] 
-        assert ev.longrepr.reprcrash.message.startswith("SyntaxError")
-
-    def test_example_items1(self, testdir):
-        p = testdir.makepyfile('''
-            def testone():
-                pass
-
-            class TestX:
-                def testmethod_one(self):
-                    pass
-
-            class TestY(TestX):
-                pass
-        ''')
-        items, events = testdir.inline_genitems(p)
-        assert len(items) == 3
-        assert items[0].name == 'testone'
-        assert items[1].name == 'testmethod_one'
-        assert items[2].name == 'testmethod_one'
-
-        # let's also test getmodpath here
-        assert items[0].getmodpath() == "testone"
-        assert items[1].getmodpath() == "TestX.testmethod_one"
-        assert items[2].getmodpath() == "TestY.testmethod_one"
-
-        s = items[0].getmodpath(stopatmodule=False)
-        assert s.endswith("test_example_items1.testone")
-        print s
-
-    def test_collect_doctest_files_with_test_prefix(self, testdir):
-        testdir.maketxtfile(whatever="")
-        checkfile = testdir.maketxtfile(test_something="""
-            alskdjalsdk
-            >>> i = 5
-            >>> i-1
-            4
-        """)
-        for x in (testdir.tmpdir, checkfile): 
-            #print "checking that %s returns custom items" % (x,) 
-            items, events = testdir.inline_genitems(x)
-            assert len(items) == 1
-            assert isinstance(items[0], DoctestFileContent)
-
-class TestCollector:
-    def test_totrail_and_back(self, tmpdir):
-        a = tmpdir.ensure("a", dir=1)
-        tmpdir.ensure("a", "__init__.py")
-        x = tmpdir.ensure("a", "trail.py")
-        config = py.test.config._reparse([x])
-        col = config.getfsnode(x)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == a.relto(config.topdir)
-        assert trail[1] == ('trail.py',)
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.listnames() == col.listnames()
-       
-    def test_totrail_topdir_and_beyond(self, tmpdir):
-        config = py.test.config._reparse([tmpdir])
-        col = config.getfsnode(config.topdir)
-        trail = col._totrail()
-        assert len(trail) == 2
-        assert trail[0] == '.'
-        assert trail[1] == ()
-        col2 = py.test.collect.Collector._fromtrail(trail, config)
-        assert col2.fspath == config.topdir
-        assert len(col2.listchain()) == 1
-        col3 = config.getfsnode(config.topdir.dirpath())
-        py.test.raises(ValueError, 
-              "col3._totrail()")
-        
-class TestCollectorReprs:
-    def test_repr_metainfo_basic_item(self, testdir):
-        modcol = testdir.getmodulecol("")
-        Item = py.test.collect.Item
-        item = Item("virtual", parent=modcol)
-        info = item.repr_metainfo() 
-        assert info.fspath == modcol.fspath
-        assert not info.lineno
-        assert info.modpath == "Item"
-        
-    def test_repr_metainfo_func(self, testdir):
-        item = testdir.getitem("def test_func(): pass")
-        info = item.repr_metainfo()
-        assert info.fspath == item.fspath 
-        assert info.lineno == 0
-        assert info.modpath == "test_func"
-
-    def test_repr_metainfo_class(self, testdir):
-        modcol = testdir.getmodulecol("""
-            # lineno 0
-            class TestClass:
-                def test_hello(self): pass
-        """)
-        classcol = modcol.collect_by_name("TestClass")
-        info = classcol.repr_metainfo()
-        assert info.fspath == modcol.fspath 
-        assert info.lineno == 1
-        assert info.modpath == "TestClass"
-
-    def test_repr_metainfo_generator(self, testdir):
-        modcol = testdir.getmodulecol("""
-            # lineno 0
-            def test_gen(): 
-                def check(x): 
-                    assert x
-                yield check, 3
-        """)
-        gencol = modcol.collect_by_name("test_gen")
-        info = gencol.repr_metainfo()
-        assert info.fspath == modcol.fspath
-        assert info.lineno == 1
-        assert info.modpath == "test_gen"
-
-        genitem = gencol.collect()[0]
-        info = genitem.repr_metainfo()
-        assert info.fspath == modcol.fspath
-        assert info.lineno == 2
-        assert info.modpath == "test_gen[0]"
-        """
-            def test_func():
-                pass
-            def test_genfunc():
-                def check(x):
-                    pass
-                yield check, 3
-            class TestClass:
-                def test_method(self):
-                    pass
-       """
-
-from py.__.test.dsession.mypickle import ImmutablePickler
-class PickleTransport:
-    def __init__(self):
-        self.p1 = ImmutablePickler(uneven=0)
-        self.p2 = ImmutablePickler(uneven=1)
-
-    def p1_to_p2(self, obj):
-        return self.p2.loads(self.p1.dumps(obj))
-
-    def p2_to_p1(self, obj):
-        return self.p1.loads(self.p2.dumps(obj))
-
-class TestPickling:
-    def setup_method(self, method):
-        pt = PickleTransport()
-        self.p1_to_p2 = pt.p1_to_p2
-        self.p2_to_p1 = pt.p2_to_p1
-
-    def unifyconfig(self, config):
-        p2config = self.p1_to_p2(config)
-        p2config._initafterpickle(config.topdir)
-        return p2config
-
-    def test_pickle_config(self):
-        config1 = py.test.config._reparse([])
-        p2config = self.unifyconfig(config1)
-        assert p2config.topdir == config1.topdir
-        config_back = self.p2_to_p1(p2config)
-        assert config_back is config1
-
-    def test_pickle_module(self, testdir):
-        modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
-
-        modcol2a = self.p1_to_p2(modcol1)
-        modcol2b = self.p1_to_p2(modcol1)
-        assert modcol2a is modcol2b
-
-        modcol1_back = self.p2_to_p1(modcol2a)
-        assert modcol1_back
-
-    def test_pickle_func(self, testdir):
-        modcol1 = testdir.getmodulecol("def test_one(): pass")
-        self.unifyconfig(modcol1._config) 
-        item = modcol1.collect_by_name("test_one")
-        item2a = self.p1_to_p2(item)
-        assert item is not item2a # of course
-        assert item2a.name == item.name
-        modback = self.p2_to_p1(item2a.parent)
-        assert modback is modcol1
-



More information about the pytest-commit mailing list