[svn r37877] Intermediate checkin for some privatising of attributes

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-03 19:29:24 +01:00
parent 46a91b3705
commit 1dca2498fb
16 changed files with 78 additions and 79 deletions

View File

@ -29,7 +29,7 @@ import py
def configproperty(name):
def fget(self):
#print "retrieving %r property from %s" %(name, self.fspath)
return self.config.getvalue(name, self.fspath)
return self._config.getvalue(name, self.fspath)
return property(fget)
class Collector(object):
@ -43,8 +43,11 @@ class Collector(object):
"""
def __init__(self, name, parent=None):
self.name = name
self.parent = parent
self.config = getattr(parent, 'config', py.test.config)
self.parent = parent
self._config = getattr(parent, '_config', py.test.config)
if parent is not None:
if hasattr(parent, 'config'):
py.test.pdb()
self.fspath = getattr(parent, 'fspath', None)
Module = configproperty('Module')
@ -73,8 +76,8 @@ class Collector(object):
return not self == other
def __cmp__(self, other):
s1 = self.getsortvalue()
s2 = other.getsortvalue()
s1 = self._getsortvalue()
s2 = other._getsortvalue()
#print "cmp", s1, s2
return cmp(s1, s2)
@ -116,7 +119,7 @@ class Collector(object):
""" return a list of colitems for the given namelist. """
return [self.join(name) for name in namelist]
def getpathlineno(self):
def _getpathlineno(self):
return self.fspath, py.std.sys.maxint
def setup(self):
@ -139,7 +142,7 @@ class Collector(object):
def listnames(self):
return [x.name for x in self.listchain()]
def getitembynames(self, namelist):
def _getitembynames(self, namelist):
if isinstance(namelist, str):
namelist = namelist.split("/")
cur = self
@ -150,10 +153,10 @@ class Collector(object):
cur = next
return cur
def haskeyword(self, keyword):
def _haskeyword(self, keyword):
return keyword in self.name
def getmodpath(self):
def _getmodpath(self):
""" return dotted module path (relative to the containing). """
inmodule = False
newl = []
@ -169,7 +172,7 @@ class Collector(object):
newl.append(x.name)
return ".".join(newl)
def skipbykeyword(self, keyword):
def _skipbykeyword(self, keyword):
""" raise Skipped() exception if the given keyword
matches for this collector.
"""
@ -184,8 +187,8 @@ class Collector(object):
py.test.skip("test not selected by keyword %r" %(keyword,))
def _matchonekeyword(self, key, chain):
for subitem in chain:
if subitem.haskeyword(key):
for subitem in chain:
if subitem._haskeyword(key):
return True
return False
@ -198,7 +201,7 @@ class Collector(object):
yieldtype = py.test.Item
if isinstance(self, yieldtype):
try:
self.skipbykeyword(keyword)
self._skipbykeyword(keyword)
yield self
except py.test.Item.Skipped:
if reporterror is not None:
@ -220,21 +223,23 @@ class Collector(object):
excinfo = py.code.ExceptionInfo()
reporterror((excinfo, self))
def getsortvalue(self):
def _getsortvalue(self):
return self.name
captured_out = captured_err = None
def startcapture(self):
return None # by default collectors don't capture output
return None # by default collectors don't capture output
def finishcapture(self):
return None # by default collectors don't capture output
def getouterr(self):
return None # by default collectors don't capture output
def _getouterr(self):
return self.captured_out, self.captured_err
def _get_collector_trail(self):
""" Shortcut
"""
return self.config.get_collector_trail(self)
return self._config.get_collector_trail(self)
class FSCollector(Collector):
def __init__(self, fspath, parent=None):
@ -356,7 +361,7 @@ class Module(FSCollector, PyCollectorMixin):
return res
def startcapture(self):
if not self.config.option.nocapture:
if not self._config.option.nocapture:
assert not hasattr(self, '_capture')
self._capture = py.io.StdCaptureFD()
@ -418,7 +423,7 @@ class Class(PyCollectorMixin, Collector):
teardown_class = getattr(teardown_class, 'im_func', teardown_class)
teardown_class(self.obj)
def getsortvalue(self):
def _getsortvalue(self):
# try to locate the class in the source - not nice, but probably
# the most useful "solution" that we have
try:
@ -432,7 +437,7 @@ class Class(PyCollectorMixin, Collector):
pass
# fall back...
for x in self.tryiter((py.test.collect.Generator, py.test.Item)):
return x.getsortvalue()
return x._getsortvalue()
class Instance(PyCollectorMixin, Collector):
def _getobj(self):
@ -468,12 +473,12 @@ class Generator(PyCollectorMixin, Collector):
call, args = obj, ()
return call, args
def getpathlineno(self):
def _getpathlineno(self):
code = py.code.Code(self.obj)
return code.path, code.firstlineno
def getsortvalue(self):
return self.getpathlineno()
def _getsortvalue(self):
return self._getpathlineno()
class DoctestFile(PyCollectorMixin, FSCollector):
def run(self):

View File

@ -75,14 +75,14 @@ class Config(object):
assert path.check(), "%s: path does not exist" %(path,)
col = self._getrootcollector(path)
names = path.relto(col.fspath).split(path.sep)
return col.getitembynames(names)
return col._getitembynames(names)
def _getrootcollector(self, path):
pkgpath = path.pypkgpath()
if pkgpath is None:
pkgpath = path.check(file=1) and path.dirpath() or path
col = self.conftest.rget("Directory", pkgpath)(pkgpath)
col.config = self
col._config = self
return col
def addoptions(self, groupname, *specs):

View File

@ -32,7 +32,7 @@ class SetupState(object):
class Item(py.test.collect.Collector):
def startcapture(self):
if not self.config.option.nocapture:
if not self._config.option.nocapture:
self._capture = py.io.StdCaptureFD()
def finishcapture(self):
@ -57,13 +57,13 @@ class Function(Item):
def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, self.name)
def getpathlineno(self):
def _getpathlineno(self):
code = py.code.Code(self.obj)
return code.path, code.firstlineno
def getsortvalue(self):
def _getsortvalue(self):
if self.sort_value is None:
return self.getpathlineno()
return self._getpathlineno()
return self.sort_value
def run(self):

View File

@ -43,13 +43,13 @@ class Presenter(object):
""" This method represents py.test.Item info (path and module)
"""
root = item.fspath
modpath = item.getmodpath()
modpath = item._getmodpath()
try:
fn, lineno = item.getpathlineno()
fn, lineno = item._getpathlineno()
except TypeError:
assert isinstance(item.parent, py.test.collect.Generator)
# a generative test yielded a non-callable
fn, lineno = item.parent.getpathlineno()
fn, lineno = item.parent._getpathlineno()
if root == fn:
self.out.sep("_", "entrypoint: %s" %(modpath))
else:

View File

@ -128,8 +128,6 @@ class AbstractReporter(object):
def repr_failure(self, item, outcome):
excinfo = outcome.excinfo
traceback = excinfo.traceback
#if item and not self.config.option.fulltrace:
# path, firstlineno = item.getpathlineno()
if not traceback:
self.out.line("empty traceback from item %r" % (item,))
return

View File

@ -52,11 +52,7 @@ class SlaveNode(object):
self.pidinfo = pidinfo
def execute(self, itemspec):
#item = self.rootcollector.getitembynames(itemspec)
item = self.config._getcollector(itemspec)
#if isinstance(item, py.test.Function):
# ex = Executor(item.obj, setup=item.setup)
#else:
ex = self.executor(item, config=self.config)
if self.executor is AsyncExecutor:
cont, pid = ex.execute()

View File

@ -94,7 +94,7 @@ def test_box_executor():
def test_box_executor_stdout():
rootcol = py.test.collect.Directory(rootdir)
item = rootcol.getitembynames(funcprint_spec)
item = rootcol._getitembynames(funcprint_spec)
ex = BoxExecutor(item, config=config)
outcome_repr = ex.execute()
outcome = ReprOutcome(outcome_repr)
@ -103,7 +103,7 @@ def test_box_executor_stdout():
def test_box_executor_stdout_error():
rootcol = py.test.collect.Directory(rootdir)
item = rootcol.getitembynames(funcprintfail_spec)
item = rootcol._getitembynames(funcprintfail_spec)
ex = BoxExecutor(item, config=config)
outcome_repr = ex.execute()
outcome = ReprOutcome(outcome_repr)
@ -112,7 +112,7 @@ def test_box_executor_stdout_error():
def test_cont_executor():
rootcol = py.test.collect.Directory(rootdir)
item = rootcol.getitembynames(funcprintfail_spec)
item = rootcol._getitembynames(funcprintfail_spec)
ex = AsyncExecutor(item, config=config)
cont, pid = ex.execute()
assert pid
@ -154,13 +154,13 @@ def test_apigen_executor():
"""))
rootcol = py.test.collect.Directory(tmpdir)
tracer = Tracer()
item = rootcol.getitembynames("test_one.py/test_1")
item = rootcol._getitembynames("test_one.py/test_1")
ex = ApigenExecutor(item, config=config)
out1 = ex.execute(tracer)
item = rootcol.getitembynames("test_one.py/TestX/()/test_one")
item = rootcol._getitembynames("test_one.py/TestX/()/test_one")
ex = ApigenExecutor(item, config=config)
out2 = ex.execute(tracer)
item = rootcol.getitembynames("test_one.py/TestX/()/test_raise")
item = rootcol._getitembynames("test_one.py/TestX/()/test_raise")
ex = ApigenExecutor(item, config=config)
out3 = ex.execute(tracer)
assert tracer.starts == 3

View File

@ -96,7 +96,7 @@ def test_slave_setup():
gw = py.execnet.PopenGateway()
config = py.test.config._reparse([])
channel = setup_slave(gw, pkgdir, config)
spec = rootcol.getitembynames(funcpass_spec)._get_collector_trail()
spec = rootcol._getitembynames(funcpass_spec)._get_collector_trail()
channel.send(spec)
output = ReprOutcome(channel.receive())
assert output.passed
@ -124,8 +124,8 @@ def test_slave_running():
return mn
master_nodes = [open_gw(), open_gw(), open_gw()]
funcpass_item = rootcol.getitembynames(funcpass_spec)
funcfail_item = rootcol.getitembynames(funcfail_spec)
funcpass_item = rootcol._getitembynames(funcpass_spec)
funcfail_item = rootcol._getitembynames(funcfail_spec)
itemgenerator = iter([funcfail_item] +
[funcpass_item] * 5 + [funcfail_item] * 5)
shouldstop = lambda : False
@ -153,7 +153,7 @@ def test_slave_running_interrupted():
mn, gw, channel = open_gw()
rootcol = py.test.collect.Directory(pkgdir)
funchang_item = rootcol.getitembynames(funchang_spec)
funchang_item = rootcol._getitembynames(funchang_spec)
mn.send(funchang_item)
mn.send(StopIteration)
# XXX: We have to wait here a bit to make sure that it really did happen

View File

@ -64,7 +64,7 @@ class AbstractTestReporter(object):
config = py.test.config._reparse(["some_sub"])
# we just go...
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
item = rootcol.getitembynames(funcpass_spec)
item = rootcol._getitembynames(funcpass_spec)
outcomes = self.prepare_outcomes()
def boxfun(config, item, outcomes):
@ -84,8 +84,8 @@ class AbstractTestReporter(object):
config = py.test.config._reparse(["some_sub"])
# we just go...
rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
funcitem = rootcol.getitembynames(funcpass_spec)
moditem = rootcol.getitembynames(mod_spec)
funcitem = rootcol._getitembynames(funcpass_spec)
moditem = rootcol._getitembynames(mod_spec)
outcomes = self.prepare_outcomes()
def boxfun(pkgdir, config, item, funcitem, outcomes):

View File

@ -196,10 +196,10 @@ class TestRSessionRemote:
import ItemTestPassing, ItemTestFailing, ItemTestSkipping
rootcol = py.test.collect.Directory(pkgdir.dirpath())
itempass = rootcol.getitembynames(funcpass_spec)
itemfail = rootcol.getitembynames(funcfail_spec)
itemskip = rootcol.getitembynames(funcskip_spec)
itemprint = rootcol.getitembynames(funcprint_spec)
itempass = rootcol._getitembynames(funcpass_spec)
itemfail = rootcol._getitembynames(funcfail_spec)
itemskip = rootcol._getitembynames(funcskip_spec)
itemprint = rootcol._getitembynames(funcprint_spec)
# actually run some tests
for node in nodes:
@ -240,7 +240,7 @@ class TestRSessionRemote:
nodes = hm.init_hosts(allevents.append)
rootcol = py.test.collect.Directory(pkgdir.dirpath())
itempass = rootcol.getitembynames(funcoptioncustom_spec)
itempass = rootcol._getitembynames(funcoptioncustom_spec)
for node in nodes:
node.send(itempass)

View File

@ -61,7 +61,7 @@ def gettestnode():
def test_slave_run_passing():
node = gettestnode()
item = rootcol.getitembynames(funcpass_spec)
item = rootcol._getitembynames(funcpass_spec)
outcome = node.execute(item._get_collector_trail())
assert outcome.passed
assert not outcome.setupfailure
@ -73,7 +73,7 @@ def test_slave_run_passing():
def test_slave_run_failing():
node = gettestnode()
item = rootcol.getitembynames(funcfail_spec)
item = rootcol._getitembynames(funcfail_spec)
outcome = node.execute(item._get_collector_trail())
assert not outcome.passed
assert not outcome.setupfailure
@ -88,7 +88,7 @@ def test_slave_run_failing():
def test_slave_run_skipping():
node = gettestnode()
item = rootcol.getitembynames(funcskip_spec)
item = rootcol._getitembynames(funcskip_spec)
outcome = node.execute(item._get_collector_trail())
assert not outcome.passed
assert outcome.skipped
@ -100,7 +100,7 @@ def test_slave_run_skipping():
def test_slave_run_failing_wrapped():
node = gettestnode()
item = rootcol.getitembynames(funcfail_spec)
item = rootcol._getitembynames(funcfail_spec)
repr_outcome = node.run(item._get_collector_trail())
outcome = ReprOutcome(repr_outcome)
assert not outcome.passed
@ -109,8 +109,8 @@ def test_slave_run_failing_wrapped():
def test_slave_main_simple():
res = []
failitem = rootcol.getitembynames(funcfail_spec)
passitem = rootcol.getitembynames(funcpass_spec)
failitem = rootcol._getitembynames(funcfail_spec)
passitem = rootcol._getitembynames(funcpass_spec)
q = [None,
passitem._get_collector_trail(),
failitem._get_collector_trail()
@ -124,7 +124,7 @@ def test_slave_main_simple():
def test_slave_run_different_stuff():
node = gettestnode()
node.run(rootcol.getitembynames("py doc log.txt".split()).
node.run(rootcol._getitembynames("py doc log.txt".split()).
_get_collector_trail())
def test_slave_setup_exit():

View File

@ -102,7 +102,7 @@ class Session(object):
if self.config.option.collectonly and isinstance(colitem, py.test.Item):
return
if isinstance(colitem, py.test.Item):
colitem.skipbykeyword(self.config.option.keyword)
colitem._skipbykeyword(self.config.option.keyword)
res = colitem.run()
if res is None:
return Passed()

View File

@ -77,9 +77,9 @@ class TerminalSession(Session):
def start_Item(self, colitem):
if self.config.option.verbose >= 1:
if isinstance(colitem, py.test.Item):
realpath, lineno = colitem.getpathlineno()
realpath, lineno = colitem._getpathlineno()
location = "%s:%d" % (realpath.basename, lineno+1)
self.out.write("%-20s %s " % (location, colitem.getmodpath()))
self.out.write("%-20s %s " % (location, colitem._getmodpath()))
def finish(self, colitem, outcome):
end = now()
@ -265,7 +265,7 @@ class TerminalSession(Session):
#print "repr_failures sees traceback"
#py.std.pprint.pprint(traceback)
if item and not self.config.option.fulltrace:
path, firstlineno = item.getpathlineno()
path, firstlineno = item._getpathlineno()
ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
if ntraceback == traceback:
ntraceback = ntraceback.cut(path=path)
@ -278,7 +278,7 @@ class TerminalSession(Session):
def repr_out_err(self, colitem):
for parent in colitem.listchain():
for name, obj in zip(['out', 'err'], parent.getouterr()):
for name, obj in zip(['out', 'err'], parent._getouterr()):
if obj:
self.out.sep("- ", "%s: recorded std%s" % (parent.name, name))
self.out.line(obj)

View File

@ -19,9 +19,9 @@ def test_collect_listnames_and_back():
col3 = col2.join('filetest.py')
l = col3.listnames()
assert len(l) == 3
x = col1.getitembynames(l[1:])
x = col1._getitembynames(l[1:])
assert x.name == "filetest.py"
x = col1.getitembynames("/".join(l[1:]))
x = col1._getitembynames("/".join(l[1:]))
assert x.name == "filetest.py"
l2 = x.listnames()
assert len(l2) == 3

View File

@ -272,7 +272,7 @@ class TestConfigColitems:
col = colitems[0]
assert isinstance(col, py.test.collect.Directory)
for col in col.listchain():
assert col.config is config
assert col._config is config
def test_getcolitems_twodirs(self):
config = py.test.config._reparse([self.tmpdir, self.tmpdir])
@ -292,7 +292,7 @@ class TestConfigColitems:
assert col2.name == 'a'
for col in colitems:
for subcol in col.listchain():
assert col.config is config
assert col._config is config
def test__getcol_global_file(self):
x = self.tmpdir.ensure("x.py")
@ -303,7 +303,7 @@ class TestConfigColitems:
assert col.parent.name == self.tmpdir.basename
assert col.parent.parent is None
for col in col.listchain():
assert col.config is config
assert col._config is config
def test__getcol_global_dir(self):
x = self.tmpdir.ensure("a", dir=1)
@ -313,7 +313,7 @@ class TestConfigColitems:
print col.listchain()
assert col.name == 'a'
assert col.parent is None
assert col.config is config
assert col._config is config
def test__getcol_pkgfile(self):
x = self.tmpdir.ensure("x.py")
@ -325,7 +325,7 @@ class TestConfigColitems:
assert col.parent.name == x.dirpath().basename
assert col.parent.parent is None
for col in col.listchain():
assert col.config is config
assert col._config is config
def test_get_collector_trail_and_back(self):
a = self.tmpdir.ensure("a", dir=1)

View File

@ -76,9 +76,9 @@ class TestKeywordSelection:
conftest = o.join('conftest.py').write(py.code.Source("""
import py
class Class(py.test.collect.Class):
def haskeyword(self, keyword):
def _haskeyword(self, keyword):
return keyword == 'xxx' or \
super(Class, self).haskeyword(keyword)
super(Class, self)._haskeyword(keyword)
"""))
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
'TestClass test_2', 'xxx TestClass test_2',):
@ -206,7 +206,7 @@ class TestTerminalSession:
assert int(err.strip()) == 23
assert isinstance(item.parent, py.test.collect.Module)
out, err = item.parent.getouterr()
out, err = item.parent._getouterr()
assert out.find('module level output') != -1
allout = self.file.getvalue()
print "allout:", allout