* kill some code and indirections
* have metainfo() directly provide fileinfo + message --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									3245b0c1af
								
							
						
					
					
						commit
						aad04ea8ae
					
				|  | @ -12,31 +12,6 @@ def configproperty(name): | |||
|         return self.config.getvalue(name, self.fspath)  | ||||
|     return property(fget) | ||||
| 
 | ||||
| class ReprMetaInfo(object): | ||||
|     def __init__(self, fspath=None, lineno=None, modpath=None): | ||||
|         self.fspath = fspath | ||||
|         self.lineno = lineno  | ||||
|         self.modpath = modpath | ||||
| 
 | ||||
|     def verboseline(self, basedir=None): | ||||
|         params = self.__dict__.copy() | ||||
|         if self.fspath: | ||||
|             if basedir is not None: | ||||
|                 params['fspath'] = basedir.bestrelpath(self.fspath) | ||||
|         if self.lineno is not None: | ||||
|             params['lineno'] = self.lineno + 1 | ||||
| 
 | ||||
|         if self.fspath and self.lineno and self.modpath: | ||||
|             line = "%(fspath)s:%(lineno)s: %(modpath)s" | ||||
|         elif self.fspath and self.modpath: | ||||
|             line = "%(fspath)s: %(modpath)s" | ||||
|         elif self.fspath and self.lineno: | ||||
|             line = "%(fspath)s:%(lineno)s" | ||||
|         else: | ||||
|             line = "[nometainfo]" | ||||
|         return line % params | ||||
|          | ||||
| 
 | ||||
| class Node(object):  | ||||
|     """ base class for Nodes in the collection tree.   | ||||
|         Collector nodes have children and  | ||||
|  | @ -50,7 +25,6 @@ class Node(object): | |||
|         - configuration/options for setup/teardown  | ||||
|           stdout/stderr capturing and execution of test items  | ||||
|     """ | ||||
|     ReprMetaInfo = ReprMetaInfo | ||||
|     def __init__(self, name, parent=None, config=None): | ||||
|         self.name = name  | ||||
|         self.parent = parent | ||||
|  | @ -450,31 +424,21 @@ class Item(Node): | |||
|     def _deprecated_testexecution(self): | ||||
|         if self.__class__.run != Item.run: | ||||
|             warnoldtestrun(function=self.run) | ||||
|             self.run() | ||||
|             return True | ||||
|         elif self.__class__.execute != Item.execute: | ||||
|             warnoldtestrun(function=self.execute) | ||||
|             self.execute(self.obj, *self._args) | ||||
|             return True | ||||
|         else: | ||||
|             return False | ||||
|         self.run() | ||||
|         return True | ||||
| 
 | ||||
|     def run(self): | ||||
|         """ deprecated, here because subclasses might call it. """  | ||||
|         """ deprecated, here because subclasses might call it. """ | ||||
|         return self.execute(self.obj, *self._args) | ||||
| 
 | ||||
|     def execute(self, obj, *args): | ||||
|         """ deprecated, here because subclasses might call it. """  | ||||
|         warnoldtestrun(function=self.execute) | ||||
|         """ deprecated, here because subclasses might call it. """ | ||||
|         return obj(*args) | ||||
| 
 | ||||
|     def repr_metainfo(self): | ||||
|         try: | ||||
|             return self.ReprMetaInfo(self.fspath, modpath=self.__class__.__name__) | ||||
|         except AttributeError: | ||||
|             code = py.code.Code(self.execute) | ||||
|             return self.ReprMetaInfo(code.path, code.firstlineno) | ||||
|        | ||||
|     def runtest(self): | ||||
|         """ execute this test item.""" | ||||
|          | ||||
| def warnoldcollect(function=None): | ||||
|     py.log._apiwarn("1.0",  | ||||
|  |  | |||
|  | @ -64,6 +64,9 @@ class ReSTSyntaxTest(py.test.collect.Item): | |||
|         super(ReSTSyntaxTest, self).__init__(*args, **kwargs) | ||||
|         self.project = project | ||||
| 
 | ||||
|     def metainfo(self): | ||||
|         return self.fspath, None, "syntax check" | ||||
| 
 | ||||
|     def runtest(self): | ||||
|         self.restcheck(py.path.svnwc(self.fspath)) | ||||
| 
 | ||||
|  | @ -193,6 +196,9 @@ class ReSTSyntaxTest(py.test.collect.Item): | |||
|                     #return [] # no need to rebuild  | ||||
| 
 | ||||
| class DoctestText(py.test.collect.Item):  | ||||
|     def metainfo(self): | ||||
|         return self.fspath, None, "doctest" | ||||
| 
 | ||||
|     def runtest(self):  | ||||
|         content = self._normalize_linesep() | ||||
|         newcontent = self.config.api.pytest_doctest_prepare_content(content=content) | ||||
|  | @ -276,9 +282,9 @@ class LinkCheckerMaker(py.test.collect.Collector): | |||
|                             args=(tryfn, path, lineno), callobj=localrefcheck) | ||||
|          | ||||
| class CheckLink(py.test.collect.Function):  | ||||
|     def repr_metainfo(self): | ||||
|         return self.ReprMetaInfo(fspath=self.fspath, lineno=self._args[2], | ||||
|             modpath="checklink: %s" % (self._args[0],)) | ||||
|     def metainfo(self, basedir=None): | ||||
|         return (self.fspath, self._args[2], "checklink: %s" % self._args[0]) | ||||
| 
 | ||||
|     def setup(self):  | ||||
|         pass  | ||||
|     def teardown(self):  | ||||
|  |  | |||
|  | @ -138,8 +138,7 @@ class TerminalReporter: | |||
| 
 | ||||
|     def pytest_itemstart(self, item, node=None): | ||||
|         if self.config.option.debug: | ||||
|             info = item.repr_metainfo() | ||||
|             line = info.verboseline(basedir=self.curdir) + " " | ||||
|             line = self._metainfoline(item) | ||||
|             extra = "" | ||||
|             if node: | ||||
|                 extra = "-> " + str(node.gateway.id) | ||||
|  | @ -149,8 +148,7 @@ class TerminalReporter: | |||
|         elif self.config.option.verbose and self.config.option.dist == "no": | ||||
|             # ensure that the path is printed before the 1st test of | ||||
|             # a module starts running | ||||
|             info = item.repr_metainfo() | ||||
|             line = info.verboseline(basedir=self.curdir) + " " | ||||
|             line = self._metainfoline(item) | ||||
|             #self.write_fspath_result(fspath, "") | ||||
|             self.write_ensure_prefix(line, "")  | ||||
| 
 | ||||
|  | @ -172,8 +170,7 @@ class TerminalReporter: | |||
|         if not self.config.option.verbose: | ||||
|             self.write_fspath_result(fspath, letter) | ||||
|         else: | ||||
|             info = rep.colitem.repr_metainfo() | ||||
|             line = info.verboseline(basedir=self.curdir) + " " | ||||
|             line = self._metainfoline(rep.colitem) | ||||
|             if not hasattr(rep, 'node'): | ||||
|                 self.write_ensure_prefix(line, word, **markup) | ||||
|             else: | ||||
|  | @ -250,6 +247,22 @@ class TerminalReporter: | |||
|         for rootdir in rootdirs: | ||||
|             self.write_line("### Watching:   %s" %(rootdir,), bold=True) | ||||
| 
 | ||||
|     def _metainfoline(self, item): | ||||
|         fspath, lineno, msg = item.metainfo() | ||||
|         if fspath: | ||||
|             fspath = self.curdir.bestrelpath(fspath) | ||||
|         if lineno is not None: | ||||
|             lineno += 1 | ||||
|         if fspath and lineno and msg: | ||||
|             line = "%(fspath)s:%(lineno)s: %(msg)s" | ||||
|         elif fspath and msg: | ||||
|             line = "%(fspath)s: %(msg)s" | ||||
|         elif fspath and lineno: | ||||
|             line = "%(fspath)s:%(lineno)s" | ||||
|         else: | ||||
|             line = "[nometainfo]" | ||||
|         return line % locals() + " " | ||||
| 
 | ||||
|     # | ||||
|     # summaries for testrunfinish  | ||||
|     # | ||||
|  |  | |||
|  | @ -87,15 +87,10 @@ class PyobjMixin(object): | |||
|         self._fslineno = fspath, lineno | ||||
|         return fspath, lineno | ||||
| 
 | ||||
|     def repr_metainfo(self): | ||||
|     def metainfo(self): | ||||
|         fspath, lineno = self.getfslineno() | ||||
|         modpath = self.getmodpath() | ||||
|         return self.ReprMetaInfo( | ||||
|             fspath=fspath,  | ||||
|             lineno=lineno, | ||||
|             modpath=modpath, | ||||
|         ) | ||||
| 
 | ||||
|         return fspath, lineno, modpath  | ||||
| 
 | ||||
| class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):  | ||||
|     Class = configproperty('Class') | ||||
|  | @ -235,6 +230,7 @@ class Instance(PyCollectorMixin, py.test.collect.Collector): | |||
| class FunctionMixin(PyobjMixin): | ||||
|     """ mixin for the code common to Function and Generator. | ||||
|     """ | ||||
| 
 | ||||
|     def _getsortvalue(self):   | ||||
|         return self.getfslineno() | ||||
| 
 | ||||
|  | @ -314,6 +310,7 @@ class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector): | |||
|             name = None | ||||
|         call, args = obj[0], obj[1:] | ||||
|         return name, call, args  | ||||
|      | ||||
| 
 | ||||
| # | ||||
| #  Test Items  | ||||
|  | @ -389,7 +386,7 @@ class Function(FunctionMixin, py.test.collect.Item): | |||
| 
 | ||||
|     def getrequest(self, argname): | ||||
|         return FuncargRequest(pyfuncitem=self, argname=argname)  | ||||
|          | ||||
| 
 | ||||
| 
 | ||||
| class FuncargRequest: | ||||
|     _argprefix = "pytest_funcarg__" | ||||
|  | @ -447,8 +444,9 @@ class FuncargRequest: | |||
|                     name = name[len(self._argprefix):] | ||||
|                     if name not in available: | ||||
|                         available.append(name)  | ||||
|         metainfo = self._pyfuncitem.repr_metainfo() | ||||
|         msg = "funcargument %r not found for: %s" %(self.argname,metainfo.verboseline()) | ||||
|         fspath, lineno, msg = self._pyfuncitem.metainfo() | ||||
|         line = "%s:%s" %(fspath, lineno) | ||||
|         msg = "funcargument %r not found for: %s" %(self.argname, line) | ||||
|         msg += "\n available funcargs: %s" %(", ".join(available),) | ||||
|         raise LookupError(msg) | ||||
| 
 | ||||
|  |  | |||
|  | @ -206,63 +206,3 @@ class TestCustomConftests: | |||
|         evrec = testdir.inline_run(testdir.tmpdir, "--XX") | ||||
|         names = [rep.colitem.name for rep in evrec.getreports("collectreport")] | ||||
|         assert 'hello' in names  | ||||
| 
 | ||||
| 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 | ||||
|        """ | ||||
|  |  | |||
|  | @ -339,3 +339,55 @@ class TestConftestCustomization: | |||
|         assert len(colitems) == 1 | ||||
|         assert colitems[0].name == "check_method" | ||||
| 
 | ||||
| 
 | ||||
| class TestMetaInfo: | ||||
|          | ||||
|     def test_func_metainfo(self, testdir): | ||||
|         item = testdir.getitem("def test_func(): pass") | ||||
|         fspath, lineno, modpath = item.metainfo() | ||||
|         assert fspath == item.fspath  | ||||
|         assert lineno == 0 | ||||
|         assert modpath == "test_func" | ||||
| 
 | ||||
|     def test_class_metainfo(self, testdir): | ||||
|         modcol = testdir.getmodulecol(""" | ||||
|             # lineno 0 | ||||
|             class TestClass: | ||||
|                 def test_hello(self): pass | ||||
|         """) | ||||
|         classcol = modcol.collect_by_name("TestClass") | ||||
|         fspath, lineno, msg = classcol.metainfo() | ||||
|         assert fspath == modcol.fspath  | ||||
|         assert lineno == 1 | ||||
|         assert msg == "TestClass" | ||||
| 
 | ||||
|     def test_generator_metainfo(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") | ||||
|         fspath, lineno, modpath = gencol.metainfo() | ||||
|         assert fspath == modcol.fspath | ||||
|         assert lineno == 1 | ||||
|         assert modpath == "test_gen" | ||||
| 
 | ||||
|         genitem = gencol.collect()[0] | ||||
|         fspath, lineno, modpath = genitem.metainfo() | ||||
|         assert fspath == modcol.fspath | ||||
|         assert lineno == 2 | ||||
|         assert 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 | ||||
|        """ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue