[py-svn] r51573 - in py/branch/event/py/test2: . testing
hpk at codespeak.net
hpk at codespeak.net
Mon Feb 18 09:48:08 CET 2008
Author: hpk
Date: Mon Feb 18 09:48:06 2008
New Revision: 51573
Modified:
py/branch/event/py/test2/collect.py
py/branch/event/py/test2/config.py
py/branch/event/py/test2/item.py
py/branch/event/py/test2/testing/test_collect.py
py/branch/event/py/test2/testing/test_doctest.py
Log:
use explicit "local" config object in collector tree
(instead of going to process-global py.test.config object)
Modified: py/branch/event/py/test2/collect.py
==============================================================================
--- py/branch/event/py/test2/collect.py (original)
+++ py/branch/event/py/test2/collect.py Mon Feb 18 09:48:06 2008
@@ -39,10 +39,12 @@
Nodes with Children are "Collectors" and leaves
are the actual Test Items.
"""
- def __init__(self, name, parent=None):
+ def __init__(self, name, parent=None, config=None):
self.name = name
self.parent = parent
- self._config = getattr(parent, '_config', py.test2.config)
+ if config is None:
+ config = getattr(parent, '_config')
+ self._config = config
def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, self.name)
@@ -177,8 +179,8 @@
Function = configproperty('Function')
Generator = configproperty('Generator')
- def __init__(self, name, parent=None):
- super(Collector, self).__init__(name, parent)
+ def __init__(self, name, parent=None, config=None):
+ super(Collector, self).__init__(name, parent, config=config)
self.fspath = getattr(parent, 'fspath', None)
def run(self):
@@ -200,9 +202,9 @@
raise NotImplementedError("abstract")
class FSCollector(Collector):
- def __init__(self, fspath, parent=None):
+ def __init__(self, fspath, parent=None, config=None):
fspath = py.path.local(fspath)
- super(FSCollector, self).__init__(fspath.basename, parent)
+ super(FSCollector, self).__init__(fspath.basename, parent, config=config)
self.fspath = fspath
class Directory(FSCollector):
Modified: py/branch/event/py/test2/config.py
==============================================================================
--- py/branch/event/py/test2/config.py (original)
+++ py/branch/event/py/test2/config.py Mon Feb 18 09:48:06 2008
@@ -82,9 +82,8 @@
pkgpath = path.pypkgpath()
if pkgpath is None:
pkgpath = path.check(file=1) and path.dirpath() or path
- col = self._conftest.rget("Directory", pkgpath)(pkgpath)
- col._config = self
- return col
+ Dir = self._conftest.rget("Directory", pkgpath)
+ return Dir(pkgpath, config=self)
def getvalue_pathlist(self, name, path=None):
""" return a matching value, which needs to be sequence
Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py (original)
+++ py/branch/event/py/test2/item.py Mon Feb 18 09:48:06 2008
@@ -30,8 +30,8 @@
self.stack.append(col)
class Item(Base):
- def __init__(self, name, parent=None):
- super(Item, self).__init__(name, parent)
+ def __init__(self, name, parent=None, config=None):
+ super(Item, self).__init__(name, parent=parent, config=config)
self.fspath = getattr(parent, 'fspath', None)
def startcapture(self):
Modified: py/branch/event/py/test2/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test2/testing/test_collect.py (original)
+++ py/branch/event/py/test2/testing/test_collect.py Mon Feb 18 09:48:06 2008
@@ -4,13 +4,21 @@
from py.__.test2.genitem import genitems
from py.__.test2.doctest import DoctestText
import setupdata, suptest
+from py.__.test2.conftesthandle import Conftest
+
+class DummyConfig:
+ def __init__(self):
+ self._conftest = Conftest()
+ def getvalue(self, name, fspath):
+ return self._conftest.rget(name, fspath)
def setup_module(mod):
mod.tmpdir = py.test2.ensuretemp(mod.__name__)
+ mod.dummyconfig = DummyConfig()
def test_collect_versus_item():
path = setupdata.getexamplefile("filetest.py")
- col = py.test2.collect.Module(path)
+ col = py.test2.collect.Module(path, config=dummyconfig)
assert not isinstance(col, py.test2.collect.Item)
item = col.join("test_one")
assert not hasattr(item, "join")
@@ -18,20 +26,21 @@
def test_collector_deprecated_run_method():
path = setupdata.getexamplefile("filetest.py")
- col = py.test2.collect.Module(path)
+ col = py.test2.collect.Module(path, config=dummyconfig)
res1 = py.test2.deprecated_call(col.run)
res2 = col.listdir()
assert res1 == res2
def test_failing_import_execfile():
dest = setupdata.getexamplefile('failingimport.py')
- col = py.test2.collect.Module(dest)
+ col = py.test2.collect.Module(dest, config=dummyconfig)
py.test2.raises(ImportError, col.listdir)
py.test2.raises(ImportError, col.listdir)
def test_collect_listnames_and_back():
path = setupdata.getexamplefile("filetest.py")
- col1 = py.test2.collect.Directory(path.dirpath().dirpath())
+ col1 = py.test2.collect.Directory(path.dirpath().dirpath(),
+ config=dummyconfig)
col2 = col1.join(path.dirpath().basename)
col3 = col2.join(path.basename)
l = col3.listnames()
@@ -45,7 +54,7 @@
def test_finds_tests():
fn = setupdata.getexamplefile('filetest.py')
- col = py.test2.collect.Module(fn)
+ col = py.test2.collect.Module(fn, config=dummyconfig)
l = col.listdir()
assert len(l) == 2
assert l[0] == 'test_one'
@@ -56,7 +65,7 @@
tmp.ensure('test_found.py')
tmp.ensure('found_test.py')
- col = py.test2.collect.Directory(tmp)
+ col = py.test2.collect.Directory(tmp, config=dummyconfig)
items = [col.join(x) for x in col.listdir()]
assert len(items) == 2
@@ -73,7 +82,7 @@
tmp.ensure("normal", 'test_found.py')
tmp.ensure('test_found.py')
- col = py.test2.collect.Directory(tmp)
+ col = py.test2.collect.Directory(tmp, config=dummyconfig)
items = col.listdir()
assert len(items) == 2
assert 'normal' in items
@@ -84,7 +93,7 @@
def filefilter(self, p):
return p.check(fnmatch='testspecial*.py')
filetest = setupdata.getexamplefile("testspecial_importerror.py")
- mydir = MyDirectory(filetest.dirpath())
+ mydir = MyDirectory(filetest.dirpath(), config=dummyconfig)
l = mydir.listdir()
assert len(l) == 1
col = mydir.join(l[0])
@@ -93,16 +102,17 @@
def test_module_file_not_found():
fn = tmpdir.join('nada','no')
- col = py.test2.collect.Module(fn)
+ col = py.test2.collect.Module(fn, config=dummyconfig)
py.test2.raises(py.error.ENOENT, col.listdir)
def test_syntax_error_in_module():
modpath = setupdata.getexamplefile("syntax_error.py")
- col = py.test2.collect.Module(modpath)
+ col = py.test2.collect.Module(modpath, config=dummyconfig)
py.test2.raises(SyntaxError, col.listdir)
def test_disabled_class():
- col = py.test2.collect.Module(setupdata.getexamplefile('disabled.py'))
+ p = setupdata.getexamplefile('disabled.py')
+ col = py.test2.collect.Module(p, config=dummyconfig)
l = col.listdir()
assert len(l) == 1
col = col.join(l[0])
@@ -111,13 +121,13 @@
def test_disabled_module():
p = setupdata.getexamplefile("disabled_module.py")
- col = py.test2.collect.Module(p)
+ col = py.test2.collect.Module(p, config=dummyconfig)
l = col.listdir()
assert len(l) == 0
def test_generative_simple():
tfile = setupdata.getexamplefile('test_generative.py')
- col = py.test2.collect.Module(tfile)
+ col = py.test2.collect.Module(tfile, config=dummyconfig)
l = col.listdir()
assert len(l) == 2
l = col.multijoin(l)
@@ -216,13 +226,13 @@
fnames.sort()
tmpdir.ensure('adir', dir=1)
fnames.insert(10, 'adir')
- col = py.test2.collect.Directory(tmpdir)
+ col = py.test2.collect.Directory(tmpdir, config=dummyconfig)
names = col.listdir()
assert names == fnames
def test_check_random_inequality():
path = setupdata.getexamplefile("funcexamples.py")
- col = py.test2.collect.Module(path)
+ col = py.test2.collect.Module(path, config=dummyconfig)
fn = col.join("funcpass")
assert fn != 3
assert fn != col
Modified: py/branch/event/py/test2/testing/test_doctest.py
==============================================================================
--- py/branch/event/py/test2/testing/test_doctest.py (original)
+++ py/branch/event/py/test2/testing/test_doctest.py Mon Feb 18 09:48:06 2008
@@ -4,7 +4,7 @@
from py.__.test2.outcome import Skipped, Failed, Passed, Outcome
def test_simple_docteststring():
- testitem = DoctestText(name="dummy", parent=None)
+ testitem = DoctestText(name="dummy", parent=None, config=42)
testitem._setcontent("""
>>> i = 0
>>> i + 1
@@ -14,7 +14,7 @@
assert res is None
def test_simple_docteststring_failing():
- testitem = DoctestText(name="dummy2", parent=None)
+ testitem = DoctestText(name="dummy2", parent=None, config=42)
testitem._setcontent("""
>>> i = 0
>>> i + 1
More information about the py-svn
mailing list