[py-svn] r62007 - in py/branch/pytestplugin/py/test: plugin testing

hpk at codespeak.net hpk at codespeak.net
Wed Feb 18 15:43:53 CET 2009


Author: hpk
Date: Wed Feb 18 15:43:50 2009
New Revision: 62007

Modified:
   py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
   py/branch/pytestplugin/py/test/testing/test_collect.py
   py/branch/pytestplugin/py/test/testing/test_config.py
   py/branch/pytestplugin/py/test/testing/test_deprecated_api.py
Log:
removing usage of suptest some more


Modified: py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_pytester.py	(original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pytester.py	Wed Feb 18 15:43:50 2009
@@ -34,17 +34,31 @@
                 ret = p
         return ret 
 
+    def makefile(self, ext, *args, **kwargs):
+        return self._makefile(ext, args, kwargs)
+
     def makepyfile(self, *args, **kwargs):
         return self._makefile('.py', args, kwargs)
 
     def maketxtfile(self, *args, **kwargs):
         return self._makefile('.txt', args, kwargs)
 
+    def mkdir(self, name):
+        return self.tmpdir.mkdir(name)
+
     def ensureplugin(self, impname):
         assert isinstance(impname, str)
         if not impname in self._plugins:
             self._plugins.append(impname)
 
+    def inline_genitems(self, *args):
+        config = self.parseconfig(*args)
+        session = config.initsession()
+        rec = EventRecorder(config.bus)
+        colitems = [config.getfsnode(arg) for arg in config.args]
+        items = list(session.genitems(colitems))
+        return items, rec 
+
     def inline_run(self, *args):
         config = self.parseconfig(*args)
         config.pluginmanager.configure(config)
@@ -139,7 +153,7 @@
 
 
 class EventRecorder(object):
-    def __init__(self, bus, debug=True):
+    def __init__(self, bus, debug=False): # True):
         self.events = []
         self.bus = bus
         bus.subscribe(self.record)

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	Wed Feb 18 15:43:50 2009
@@ -65,7 +65,7 @@
         assert modcol.name == x.name 
 
     def test_listnames_getitembynames_custom(self, fstester):
-        hello = fstester._makefile(".xxx", (), {'hello':"world"})
+        hello = fstester.makefile(".xxx", hello="world")
         fstester.makepyfile(conftest="""
             import py
             class CustomFile(py.test.collect.File):
@@ -344,7 +344,7 @@
                     if fspath.ext == ".xxx":
                         return CustomItem(fspath.basename, parent=self)
         """)
-        checkfile = fstester._makefile(ext="xxx", args=(), kwargs={'hello': "world"})
+        checkfile = fstester.makefile(ext="xxx", hello="world")
         fstester.makepyfile(x="")
         fstester.maketxtfile(x="")
         config = fstester.parseconfig()

Modified: py/branch/pytestplugin/py/test/testing/test_config.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_config.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_config.py	Wed Feb 18 15:43:50 2009
@@ -2,14 +2,10 @@
 import py
 
 from py.__.test.config import gettopdir
-from py.__.test.testing import suptest
 
 def getcolitems(config):
     return [config.getfsnode(arg) for arg in config.args]
 
-def test_default_bus():
-    assert py.test.config.bus._bus is py.event
-    
 def test_tmpdir():
     d1 = py.test.ensuretemp('hello') 
     d2 = py.test.ensuretemp('hello') 
@@ -166,21 +162,10 @@
     assert config.option.gdest == 11
     assert option.gdest == 11
 
-class TestSessionAndOptions(suptest.FileCreation): 
-    def exampletestfile(self):
-        return self.makepyfile(file_test="""
-            def test_one(): 
-                assert 42 == 43
-
-            class TestClass(object): 
-                def test_method_one(self): 
-                    assert 42 == 43 
-        """)
-
-    def test_tracedir_tracer(self):
-        tracedir = self.tmpdir.join("tracedir")
-        config = py.test.config._reparse([self.tmpdir, 
-                                          '--tracedir=%s' % tracedir])
+class TestSessionAndOptions:
+    def test_tracedir_tracer(self, fstester):
+        tracedir = fstester.mkdir("tracedir")
+        config = fstester.parseconfig("--tracedir=%s" % tracedir)
         assert config.gettracedir() == tracedir
 
         trace = config.maketrace("trace1.log") # flush=True by default
@@ -193,57 +178,57 @@
         assert lines[1].find("A") != -1
         trace.close()
 
-    def test_trace_null(self):
-        config = py.test.config._reparse([self.tmpdir])
+    def test_trace_null(self, fstester):
+        config = fstester.parseconfig(fstester.tmpdir)
         assert config.gettracedir() is None
         trace = config.maketrace("hello", flush=True)
         trace("hello", "world")
         trace.close()
 
-    def test_implied_dsession(self):
+    def test_implied_dsession(self, fstester):
         for x in 'startserver runbrowser rest'.split():
-            config = py.test.config._reparse([self.tmpdir, '--dist', '--%s' % x])
+            config = fstester.parseconfig(fstester.tmpdir, '--dist', '--%s' % x)
             assert config._getsessionname() == 'DSession'
 
-    def test_implied_different_sessions(self):
-        config = py.test.config._reparse([self.tmpdir])
+    def test_implied_different_sessions(self, tmpdir):
+        config = py.test.config._reparse([tmpdir])
         assert config._getsessionname() == 'Session'
-        config = py.test.config._reparse([self.tmpdir, '--dist'])
+        config = py.test.config._reparse([tmpdir, '--dist'])
         assert config._getsessionname() == 'DSession'
-        config = py.test.config._reparse([self.tmpdir, '-n3'])
+        config = py.test.config._reparse([tmpdir, '-n3'])
         assert config._getsessionname() == 'DSession'
-        config = py.test.config._reparse([self.tmpdir, '--looponfailing'])
+        config = py.test.config._reparse([tmpdir, '--looponfailing'])
         assert config._getsessionname() == 'LooponfailingSession'
-        config = py.test.config._reparse([self.tmpdir, '--exec=x'])
+        config = py.test.config._reparse([tmpdir, '--exec=x'])
         assert config._getsessionname() == 'DSession'
-        config = py.test.config._reparse([self.tmpdir, '--dist', '--exec=x'])
+        config = py.test.config._reparse([tmpdir, '--dist', '--exec=x'])
         assert config._getsessionname() == 'DSession'
-        config = py.test.config._reparse([self.tmpdir, '-f', 
+        config = py.test.config._reparse([tmpdir, '-f', 
                                           '--dist', '--exec=x'])
         assert config._getsessionname() == 'LooponfailingSession'
-        config = py.test.config._reparse([self.tmpdir, '-f', '-n3',
+        config = py.test.config._reparse([tmpdir, '-f', '-n3',
                                           '--dist', '--exec=x', 
                                           '--collectonly'])
         assert config._getsessionname() == 'Session'
 
-    def test_sessionname_lookup_custom(self):
-        self.tmpdir.join("conftest.py").write(py.code.Source("""
+    def test_sessionname_lookup_custom(self, fstester):
+        fstester.makepyfile(conftest="""
             from py.__.test.session import Session
             class MySession(Session):
                 pass
-        """)) 
-        config = py.test.config._reparse(["--session=MySession", self.tmpdir])
+        """) 
+        config = fstester.parseconfig("--session=MySession", fstester.tmpdir)
         session = config.initsession()
         assert session.__class__.__name__ == 'MySession'
 
-    def test_initsession(self):
-        config = py.test.config._reparse([self.tmpdir])
+    def test_initsession(self, tmpdir):
+        config = py.test.config._reparse([tmpdir])
         session = config.initsession()
         assert session.config is config 
 
-    def test_boxed_option_default(self):
-        self.tmpdir.join("conftest.py").write("dist_hosts=[]")
-        tmpdir = self.tmpdir.ensure("subdir", dir=1)
+    def test_boxed_option_default(self, fstester):
+        fstester.makepyfile(conftest="dist_hosts=[]")
+        tmpdir = fstester.tmpdir.ensure("subdir", dir=1)
         config = py.test.config._reparse([tmpdir])
         config.initsession()
         assert not config.option.boxed
@@ -251,9 +236,9 @@
         config.initsession()
         assert not config.option.boxed
 
-    def test_boxed_option_from_conftest(self):
-        self.tmpdir.join("conftest.py").write("dist_hosts=[]")
-        tmpdir = self.tmpdir.ensure("subdir", dir=1)
+    def test_boxed_option_from_conftest(self, fstester):
+        fstester.makepyfile(conftest="dist_hosts=[]")
+        tmpdir = fstester.tmpdir.ensure("subdir", dir=1)
         tmpdir.join("conftest.py").write(py.code.Source("""
             dist_hosts = []
             dist_boxed = True
@@ -262,18 +247,14 @@
         config.initsession()
         assert config.option.boxed 
 
-    def test_boxed_option_from_conftest(self):
-        tmpdir = self.tmpdir
-        tmpdir.join("conftest.py").write(py.code.Source("""
-            dist_boxed = False
-        """))
-        config = py.test.config._reparse([tmpdir, '--box'])
+    def test_boxed_option_from_conftest(self, fstester):
+        fstester.makepyfile(conftest="dist_boxed=False")
+        config = py.test.config._reparse([fstester.tmpdir, '--box'])
         assert config.option.boxed 
         config.initsession()
         assert config.option.boxed
 
-    def test_getvalue_pathlist(self):
-        tmpdir = self.tmpdir
+    def test_getvalue_pathlist(self, tmpdir):
         somepath = tmpdir.join("x", "y", "z")
         p = tmpdir.join("conftest.py")
         p.write("pathlist = ['.', %r]" % str(somepath))
@@ -289,10 +270,10 @@
         pl = config.getvalue_pathlist('mypathlist')
         assert pl == [py.path.local()]
 
-    def test_config_iocapturing(self):
-        config = py.test.config._reparse([self.tmpdir])
+    def test_config_iocapturing(self, fstester):
+        config = fstester.parseconfig(fstester.tmpdir)
         assert config.getvalue("conf_iocapture")
-        tmpdir = self.tmpdir.ensure("sub-with-conftest", dir=1)
+        tmpdir = fstester.tmpdir.ensure("sub-with-conftest", dir=1)
         tmpdir.join("conftest.py").write(py.code.Source("""
             conf_iocapture = "no"
         """))
@@ -314,8 +295,7 @@
     def test_conflict_options(self):
         def check_conflict_option(opts):
             print "testing if options conflict:", " ".join(opts)
-            path = self.exampletestfile()
-            config = py.test.config._reparse(opts + [path])
+            config = py.test.config._reparse(opts)
             py.test.raises((ValueError, SystemExit), """
                 config.initsession()
             """)
@@ -329,48 +309,30 @@
             opts = spec.split()
             yield check_conflict_option, opts
     
-    def test_implied_options(self):
-        def check_implied_option(opts, expr):
-            path = self.exampletestfile()
-            config = py.test.config._reparse(opts + [path])
-            session = config.initsession()
-            assert eval(expr, session.config.option.__dict__)
-
-        implied_options = {
-            '-v': 'verbose', 
-            '-l': 'showlocals',
-            #'--runbrowser': 'startserver and runbrowser', XXX starts browser
-        }
-        for key, expr in implied_options.items():
-            yield check_implied_option, [key], expr
-
-    def test_default_session_options(self):
+    def test_default_session_options(self, fstester):
         def runfiletest(opts):
-            sorter = suptest.events_from_cmdline(opts)
+            sorter = fstester.inline_run(*opts)
             passed, skipped, failed = sorter.countoutcomes()
             assert failed == 2 
             assert skipped == passed == 0
-        path = self.exampletestfile()
+        path = fstester.makepyfile("""
+            def test_f1(): assert 0
+            def test_f2(): assert 0
+        """)
+    
         for opts in ([], ['-l'], ['-s'], ['--tb=no'], ['--tb=short'], 
                      ['--tb=long'], ['--fulltrace'], ['--nomagic'], 
                      ['--traceconfig'], ['-v'], ['-v', '-v']):
-            yield runfiletest, opts + [path]
+            runfiletest(opts + [path])
 
-    def test_is_not_boxed_by_default(self):
-        path = self.exampletestfile()
-        config = py.test.config._reparse([path])
+    def test_is_not_boxed_by_default(self, fstester):
+        config = py.test.config._reparse([fstester.tmpdir])
         assert not config.option.boxed
 
 
-class TestConfigColitems(suptest.FileCreation):
-    def setup_class(cls):
-        cls.tmproot = py.test.ensuretemp(cls.__name__)
-
-    def setup_method(self, method):
-        self.tmpdir = self.tmproot.mkdir(method.__name__) 
-    
-    def test_getcolitems_onedir(self):
-        config = py.test.config._reparse([self.tmpdir])
+class TestConfigColitems:
+    def test_getcolitems_onedir(self, tmpdir):
+        config = py.test.config._reparse([tmpdir])
         colitems = getcolitems(config)
         assert len(colitems) == 1
         col = colitems[0]
@@ -378,39 +340,39 @@
         for col in col.listchain():
             assert col._config is config 
 
-    def test_getcolitems_twodirs(self):
-        config = py.test.config._reparse([self.tmpdir, self.tmpdir])
+    def test_getcolitems_twodirs(self, tmpdir):
+        config = py.test.config._reparse([tmpdir, tmpdir])
         colitems = getcolitems(config)
         assert len(colitems) == 2
         col1, col2 = colitems 
         assert col1.name == col2.name 
         assert col1.parent == col2.parent 
 
-    def test_getcolitems_curdir_and_subdir(self):
-        a = self.tmpdir.ensure("a", dir=1)
-        config = py.test.config._reparse([self.tmpdir, a])
+    def test_getcolitems_curdir_and_subdir(self, tmpdir):
+        a = tmpdir.ensure("a", dir=1)
+        config = py.test.config._reparse([tmpdir, a])
         colitems = getcolitems(config)
         assert len(colitems) == 2
         col1, col2 = colitems 
-        assert col1.name == self.tmpdir.basename
+        assert col1.name == tmpdir.basename
         assert col2.name == 'a'
         for col in colitems:
             for subcol in col.listchain():
                 assert col._config is config 
 
-    def test__getcol_global_file(self):
-        x = self.tmpdir.ensure("x.py")
+    def test__getcol_global_file(self, tmpdir):
+        x = tmpdir.ensure("x.py")
         config = py.test.config._reparse([x])
         col = config.getfsnode(x)
         assert isinstance(col, py.test.collect.Module)
         assert col.name == 'x.py'
-        assert col.parent.name == self.tmpdir.basename 
+        assert col.parent.name == tmpdir.basename 
         assert col.parent.parent is None
         for col in col.listchain():
             assert col._config is config 
 
-    def test__getcol_global_dir(self):
-        x = self.tmpdir.ensure("a", dir=1)
+    def test__getcol_global_dir(self, tmpdir):
+        x = tmpdir.ensure("a", dir=1)
         config = py.test.config._reparse([x])
         col = config.getfsnode(x)
         assert isinstance(col, py.test.collect.Directory)
@@ -419,9 +381,9 @@
         assert col.parent is None
         assert col._config is config 
 
-    def test__getcol_pkgfile(self):
-        x = self.tmpdir.ensure("x.py")
-        self.tmpdir.ensure("__init__.py")
+    def test__getcol_pkgfile(self, tmpdir):
+        x = tmpdir.ensure("x.py")
+        tmpdir.ensure("__init__.py")
         config = py.test.config._reparse([x])
         col = config.getfsnode(x)
         assert isinstance(col, py.test.collect.Module)
@@ -431,9 +393,9 @@
         for col in col.listchain():
             assert col._config is config 
 
-    def test_config_picklability(self):
+    def test_config_picklability(self, tmpdir):
         import cPickle
-        config = py.test.config._reparse([self.tmpdir])
+        config = py.test.config._reparse([tmpdir])
         s = cPickle.dumps(config)
         newconfig = cPickle.loads(s)
         assert not hasattr(newconfig, "topdir")
@@ -442,11 +404,11 @@
         newconfig._initafterpickle(config.topdir)
         assert newconfig.topdir == config.topdir 
         assert newconfig._initialized 
-        assert newconfig.args == [self.tmpdir]
+        assert newconfig.args == [tmpdir]
 
-    def test_config_and_collector_pickling_missing_initafter(self):
+    def test_config_and_collector_pickling_missing_initafter(self, tmpdir):
         from cPickle import Pickler, Unpickler
-        config = py.test.config._reparse([self.tmpdir])
+        config = py.test.config._reparse([tmpdir])
         col = config.getfsnode(config.topdir)
         io = py.std.cStringIO.StringIO()
         pickler = Pickler(io)
@@ -458,10 +420,10 @@
         # we don't call _initafterpickle ... so
         py.test.raises(ValueError, "unpickler.load()")
 
-    def test_config_and_collector_pickling(self):
+    def test_config_and_collector_pickling(self, tmpdir):
         from cPickle import Pickler, Unpickler
-        dir1 = self.tmpdir.ensure("somedir", dir=1)
-        config = py.test.config._reparse([self.tmpdir])
+        dir1 = tmpdir.ensure("somedir", dir=1)
+        config = py.test.config._reparse([tmpdir])
         col = config.getfsnode(config.topdir)
         col1 = col.join(dir1.basename)
         assert col1.parent is col 
@@ -474,7 +436,7 @@
         io.seek(0) 
         unpickler = Unpickler(io)
         newconfig = unpickler.load()
-        topdir = self.tmpdir.ensure("newtopdir", dir=1)
+        topdir = tmpdir.ensure("newtopdir", dir=1)
         newconfig._initafterpickle(topdir)
         topdir.ensure("somedir", dir=1)
         newcol = unpickler.load()
@@ -489,3 +451,6 @@
         assert newcol2.fspath.basename == dir1.basename
         assert newcol2.fspath.relto(topdir)
 
+def test_default_bus():
+    assert py.test.config.bus._bus is py.event
+    

Modified: py/branch/pytestplugin/py/test/testing/test_deprecated_api.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_deprecated_api.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_deprecated_api.py	Wed Feb 18 15:43:50 2009
@@ -1,18 +1,17 @@
 
 import py
-from py.__.test.testing import suptest
 
-class TestCollectDeprecated(suptest.InlineCollection):
-    def test_directory_run_join_warnings(self):
-        p = self.makepyfile(test_one="")
-        config = self.parseconfig()  
+class TestCollectDeprecated:
+    def test_directory_run_join_warnings(self, fstester):
+        p = fstester.makepyfile(test_one="")
+        config = fstester.parseconfig(p)  
         dirnode = config.getfsnode(p.dirpath())
         py.test.deprecated_call(dirnode.run)
         # XXX for directories we still have join()
         #py.test.deprecated_call(dirnode.join, 'test_one')
         
-    def test_collect_with_deprecated_run_and_join(self):
-        self.makepyfile(conftest="""
+    def test_collect_with_deprecated_run_and_join(self, fstester):
+        fstester.makepyfile(conftest="""
             import py
 
             class MyInstance(py.test.collect.Instance):
@@ -46,12 +45,12 @@
                         return self.Module(self.fspath.join(name), parent=self)
             Directory = MyDirectory
         """)
-        p = self.makepyfile(somefile="""
+        p = fstester.makepyfile(somefile="""
             def check(): pass
             class Cls:
                 def check2(self): pass 
         """)
-        config = self.parseconfig()
+        config = fstester.parseconfig()
         dirnode = config.getfsnode(p.dirpath())
         colitems = py.test.deprecated_call(dirnode.collect)
         assert len(colitems) == 1
@@ -69,8 +68,9 @@
         assert len(colitems) == 1
         assert colitems[0].name == 'check2'
 
-    def test_collect_with_deprecated_join_but_no_run(self):
-        self.makepyfile(conftest="""
+    def test_collect_with_deprecated_join_but_no_run(self, tsession):
+        fstester = tsession.fstester
+        fstester.makepyfile(conftest="""
             import py
 
             class Module(py.test.collect.Module):
@@ -83,7 +83,7 @@
                         return self.Function(name, parent=self)
                     assert name != "SomeClass", "join should not be called with this name"
         """)
-        col = self.getmodulecol("""
+        col = tsession.getmodulecol("""
             def somefunc(): pass
             def check_one(): pass
             class SomeClass: pass
@@ -93,51 +93,53 @@
         funcitem = colitems[0]
         assert funcitem.name == "check_one"
 
-    def test_function_custom_run(self):
-        self.makepyfile(conftest="""
+    def test_function_custom_run(self, tsession):
+        fstester = tsession.fstester
+        fstester.makepyfile(conftest="""
             import py
             class MyFunction(py.test.collect.Function):
                 def run(self):
                     pass
             Function=MyFunction 
         """)
-        modcol = self.getmodulecol("def test_func(): pass")
+        modcol = tsession.getmodulecol("def test_func(): pass")
         funcitem = modcol.collect()[0]
         assert funcitem.name == 'test_func'
         py.test.deprecated_call(funcitem.runtest)
 
-    def test_function_custom_execute(self):
-        self.makepyfile(conftest="""
+    def test_function_custom_execute(self, tsession):
+        fstester = tsession.fstester
+        fstester.makepyfile(conftest="""
             import py
             class MyFunction(py.test.collect.Function):
                 def execute(self, obj, *args):
                     pass
             Function=MyFunction 
         """)
-        modcol = self.getmodulecol("def test_func(): pass")
+        modcol = tsession.getmodulecol("def test_func(): pass")
         funcitem = modcol.collect()[0]
         assert funcitem.name == 'test_func'
         py.test.deprecated_call(funcitem.runtest)
 
-    def test_function_deprecated_run_execute(self):
-        modcol = self.getmodulecol("def test_some(): pass")
+    def test_function_deprecated_run_execute(self, tsession):
+        modcol = tsession.getmodulecol("def test_some(): pass")
         funcitem = modcol.collect()[0]
         py.test.deprecated_call(funcitem.run)
         py.test.deprecated_call(funcitem.execute, funcitem.obj)
 
-    def test_function_deprecated_run_recursive(self):
-        self.makepyfile(conftest="""
+    def test_function_deprecated_run_recursive(self, tsession):
+        tsession.fstester.makepyfile(conftest="""
             import py
             class Module(py.test.collect.Module):
                 def run(self):
                     return super(Module, self).run()
         """)
-        modcol = self.getmodulecol("def test_some(): pass")
+        modcol = tsession.getmodulecol("def test_some(): pass")
         colitems = py.test.deprecated_call(modcol.collect)
         funcitem = colitems[0]
 
-    def test_conftest_subclasses_Module_with_non_pyfile(self):
-        self.makepyfile(conftest="""
+    def test_conftest_subclasses_Module_with_non_pyfile(self, fstester):
+        fstester.makepyfile(conftest="""
             import py
             class Module(py.test.collect.Module):
                 def run(self):
@@ -148,7 +150,7 @@
                         return Module(path, parent=self)
                     return super(Directory, self).consider_file(path)
         """)
-        testme = self._makefile('xxx', testme="hello")
-        config = self.parseconfig(testme)
+        testme = fstester.makefile('xxx', testme="hello")
+        config = fstester.parseconfig(testme)
         col = config.getfsnode(testme)
         assert col.collect() == []



More information about the pytest-commit mailing list