diff --git a/py/test/collect.py b/py/test/collect.py index 1efd6baab..f04339ccc 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -192,7 +192,7 @@ class Collector(object): return True return False - def tryiter(self, yieldtype=None, reporterror=None, keyword=None): + def _tryiter(self, yieldtype=None, reporterror=None, keyword=None): """ yield stop item instances from flattening the collector. XXX deprecated: this way of iteration is not safe in all cases. @@ -213,7 +213,7 @@ class Collector(object): if reporterror is not None: reporterror((None, self)) for x in self.run(): - for y in self.join(x).tryiter(yieldtype, + for y in self.join(x)._tryiter(yieldtype, reporterror, keyword): yield y except KeyboardInterrupt: @@ -226,7 +226,7 @@ class Collector(object): def _getsortvalue(self): return self.name - captured_out = captured_err = None + _captured_out = _captured_err = None def startcapture(self): return None # by default collectors don't capture output @@ -234,7 +234,7 @@ class Collector(object): return None # by default collectors don't capture output def _getouterr(self): - return self.captured_out, self.captured_err + return self._captured_out, self._captured_err def _get_collector_trail(self): """ Shortcut @@ -369,7 +369,7 @@ class Module(FSCollector, PyCollectorMixin): if hasattr(self, '_capture'): capture = self._capture del self._capture - self.captured_out, self.captured_err = capture.reset() + self._captured_out, self._captured_err = capture.reset() def __repr__(self): return "<%s %r>" % (self.__class__.__name__, self.name) @@ -436,7 +436,7 @@ class Class(PyCollectorMixin, Collector): except IOError: pass # fall back... - for x in self.tryiter((py.test.collect.Generator, py.test.Item)): + for x in self._tryiter((py.test.collect.Generator, py.test.Item)): return x._getsortvalue() class Instance(PyCollectorMixin, Collector): diff --git a/py/test/item.py b/py/test/item.py index eb68103ba..b192ae550 100644 --- a/py/test/item.py +++ b/py/test/item.py @@ -39,7 +39,7 @@ class Item(py.test.collect.Collector): if hasattr(self, '_capture'): capture = self._capture del self._capture - self.captured_out, self.captured_err = capture.reset() + self._captured_out, self._captured_err = capture.reset() class Function(Item): diff --git a/py/test/rsession/master.py b/py/test/rsession/master.py index 1ddae78b0..a1a31c29b 100644 --- a/py/test/rsession/master.py +++ b/py/test/rsession/master.py @@ -36,7 +36,7 @@ class MasterNode(object): def itemgen(colitems, reporter, keyword, reporterror): for x in colitems: - for y in x.tryiter(reporterror = lambda x: reporterror(reporter, x), keyword = keyword): + for y in x._tryiter(reporterror = lambda x: reporterror(reporter, x), keyword = keyword): yield y def randomgen(items, done_dict): diff --git a/py/test/rsession/reporter.py b/py/test/rsession/reporter.py index d3b3cc3db..e9c44717d 100644 --- a/py/test/rsession/reporter.py +++ b/py/test/rsession/reporter.py @@ -288,7 +288,7 @@ class LocalReporter(AbstractReporter): # XXX This is a terrible hack, I don't like it # and will rewrite it at some point #self.count = 0 - lgt = len(list(item.tryiter())) + lgt = len(list(item._tryiter())) #self.lgt = lgt # print names relative to current workdir name = "/".join(item.listnames()) diff --git a/py/test/rsession/rest.py b/py/test/rsession/rest.py index 514bf565f..ddcacdcf7 100644 --- a/py/test/rsession/rest.py +++ b/py/test/rsession/rest.py @@ -66,7 +66,7 @@ class RestReporter(AbstractReporter): def report_ItemStart(self, event): item = event.item if isinstance(item, py.test.collect.Module): - lgt = len(list(item.tryiter())) + lgt = len(list(item._tryiter())) lns = item.listnames()[1:] name = "/".join(lns) link = self.get_linkwriter().get_link(self.get_rootpath(item), diff --git a/py/test/rsession/testing/test_reporter.py b/py/test/rsession/testing/test_reporter.py index 8da388743..ca6fac911 100644 --- a/py/test/rsession/testing/test_reporter.py +++ b/py/test/rsession/testing/test_reporter.py @@ -123,7 +123,7 @@ class AbstractTestReporter(object): rootcol = py.test.collect.Directory(tmpdir) hosts = [HostInfo('localhost')] r = self.reporter(config, hosts) - list(rootcol.tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x))) + list(rootcol._tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x))) cap = py.io.StdCaptureFD() boxfun() @@ -144,7 +144,7 @@ class AbstractTestReporter(object): r = self.reporter(config, [host]) r.report(report.TestStarted([host])) r.report(report.RsyncFinished()) - list(rootcol.tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x))) + list(rootcol._tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x))) r.report(report.TestFinished()) cap = py.io.StdCaptureFD() diff --git a/py/test/rsession/testing/test_rest.py b/py/test/rsession/testing/test_rest.py index 0c456b661..5c426b719 100644 --- a/py/test/rsession/testing/test_rest.py +++ b/py/test/rsession/testing/test_rest.py @@ -78,7 +78,7 @@ Running tests on hosts\: localhost, foo.com def __init__(self, parent): self.parent = parent self.fspath = py.path.local('.') - def tryiter(self): + def _tryiter(self): return ['test_foo', 'test_bar'] def listnames(self): return ['package', 'foo', 'bar.py'] diff --git a/py/test/rsession/testing/test_rsession.py b/py/test/rsession/testing/test_rsession.py index 2ac0edd0f..932c3c200 100644 --- a/py/test/rsession/testing/test_rsession.py +++ b/py/test/rsession/testing/test_rsession.py @@ -68,7 +68,7 @@ def test_example_tryiter(): pass """)) rootcol = py.test.collect.Directory(tmpdir) - data = list(rootcol.tryiter(reporterror=events.append)) + data = list(rootcol._tryiter(reporterror=events.append)) assert len(events) == 2 assert str(events[1][0].value) == "Reason" diff --git a/py/test/rsession/web.py b/py/test/rsession/web.py index 95764fa7b..0cf3ee663 100644 --- a/py/test/rsession/web.py +++ b/py/test/rsession/web.py @@ -62,7 +62,7 @@ def add_item(event): 'itemname': itemname} #if itemtype == 'Module': try: - d['length'] = str(len(list(event.item.tryiter()))) + d['length'] = str(len(list(event.item._tryiter()))) except: d['length'] = "?" return d diff --git a/py/test/terminal/terminal.py b/py/test/terminal/terminal.py index 97f767aa2..647f7ea2d 100644 --- a/py/test/terminal/terminal.py +++ b/py/test/terminal/terminal.py @@ -64,8 +64,8 @@ class TerminalSession(Session): and not self.config.option.collectonly): try: sum = 0 - for sub in subitems: - sum += len(list(colitem.join(sub).tryiter())) + for sub in subitems: + sum += len(list(colitem.join(sub)._tryiter())) except (SystemExit, KeyboardInterrupt): raise except: diff --git a/py/test/testing/test_collect.py b/py/test/testing/test_collect.py index ed19e190d..746fc1970 100644 --- a/py/test/testing/test_collect.py +++ b/py/test/testing/test_collect.py @@ -40,7 +40,7 @@ def test_found_certain_testfiles(): tmp.ensure('found_test.py') colitem = py.test.collect.Directory(tmp) - items = list(colitem.tryiter(py.test.collect.Module)) + items = list(colitem._tryiter(py.test.collect.Module)) assert len(items) == 2 items = [item.name for item in items] assert 'test_found.py' in items @@ -57,7 +57,7 @@ def test_ignored_certain_directories(): tmp.ensure('test_found.py') colitem = py.test.collect.Directory(tmp) - items = list(colitem.tryiter(py.test.collect.Module)) + items = list(colitem._tryiter(py.test.collect.Module)) assert len(items) == 2 for item in items: assert item.name == 'test_found.py' @@ -196,7 +196,7 @@ def test_custom_python_collection_from_conftest(): config = py.test.config._reparse([x]) #print "checking that %s returns custom items" % (x,) col = config._getcollector(x) - assert len(list(col.tryiter(py.test.Item))) == 2 + assert len(list(col._tryiter(py.test.Item))) == 2 #assert items[1].__class__.__name__ == 'MyFunction' # test that running a session works from the directories @@ -243,7 +243,7 @@ def test_custom_NONpython_collection_from_conftest(): print "checking that %s returns custom items" % (x,) config = py.test.config._reparse([x]) col = config._getcollector(x) - assert len(list(col.tryiter(py.test.Item))) == 1 + assert len(list(col._tryiter(py.test.Item))) == 1 #assert items[1].__class__.__name__ == 'MyFunction' # test that running a session works from the directories @@ -319,13 +319,13 @@ def test_documentation_virtual_collector_interaction(): try: conf.option.forcegen = 1 col = py.test.collect.Directory(rootdir) - x = list(col.tryiter(yieldtype=py.test.Function)) + x = list(col._tryiter(yieldtype=py.test.Function)) finally: conf.option.forcegen = old -def test_tryiter_ignores_skips(): - tmp = py.test.ensuretemp("tryiterskip") +def test__tryiter_ignores_skips(): + tmp = py.test.ensuretemp("_tryiterskip") tmp.ensure("subdir", "conftest.py").write(py.code.Source(""" import py class Directory(py.test.collect.Directory): @@ -334,7 +334,7 @@ def test_tryiter_ignores_skips(): """)) col = py.test.collect.Directory(tmp) try: - list(col.tryiter()) + list(col._tryiter()) except KeyboardInterrupt: raise except: @@ -342,14 +342,14 @@ def test_tryiter_ignores_skips(): py.test.fail("should not have raised: %s" %(exc,)) -def test_tryiter_ignores_failing_collectors(): - tmp = py.test.ensuretemp("tryiterfailing") +def test__tryiter_ignores_failing_collectors(): + tmp = py.test.ensuretemp("_tryiterfailing") tmp.ensure("subdir", "conftest.py").write(py.code.Source(""" bla bla bla """)) col = py.test.collect.Directory(tmp) try: - list(col.tryiter()) + list(col._tryiter()) except KeyboardInterrupt: raise except: @@ -357,7 +357,7 @@ def test_tryiter_ignores_failing_collectors(): py.test.fail("should not have raised: %s" %(exc,)) l = [] - list(col.tryiter(reporterror=l.append)) + list(col._tryiter(reporterror=l.append)) assert len(l) == 2 excinfo, item = l[-1] assert isinstance(excinfo, py.code.ExceptionInfo) @@ -368,7 +368,7 @@ def test_tryiter_handles_keyboardinterrupt(): raise KeyboardInterrupt() """)) col = py.test.collect.Directory(tmp) - py.test.raises(KeyboardInterrupt, list, col.tryiter()) + py.test.raises(KeyboardInterrupt, list, col._tryiter()) def test_check_random_inequality(): tmp = py.test.ensuretemp("ineq") @@ -376,7 +376,7 @@ def test_check_random_inequality(): pass """)) col = py.test.collect.Directory(tmp) - fn = col.tryiter().next() + fn = col._tryiter().next() assert fn != 3 assert fn != col assert fn != [1,2,3] @@ -399,7 +399,7 @@ def test_check_generator_collect_problems(): tmp.ensure("__init__.py") col = py.test.collect.Module(tmp.join("test_one.py")) errors = [] - l = list(col.tryiter(reporterror=errors.append)) + l = list(col._tryiter(reporterror=errors.append)) assert len(errors) == 2 def test_check_collect_hashes(): @@ -420,7 +420,7 @@ def test_check_collect_hashes(): """)) tmp.ensure("__init__.py") col = py.test.collect.Directory(tmp) - l = list(col.tryiter()) + l = list(col._tryiter()) assert len(l) == 4 for numi, i in enumerate(l): for numj, j in enumerate(l): diff --git a/py/test/testing/test_doctest.py b/py/test/testing/test_doctest.py index bc75a3082..f61ce1ce1 100644 --- a/py/test/testing/test_doctest.py +++ b/py/test/testing/test_doctest.py @@ -37,7 +37,7 @@ def test_collect_doctest_files_with_test_prefix(): #print "checking that %s returns custom items" % (x,) config = py.test.config._reparse([x]) col = config._getcollector(x) - items = list(col.tryiter(py.test.Item)) + items = list(col._tryiter(py.test.Item)) assert len(items) == 1 assert isinstance(items[0], DoctestText)