* 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 self.config.getvalue(name, self.fspath)  | ||||||
|     return property(fget) |     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):  | class Node(object):  | ||||||
|     """ base class for Nodes in the collection tree.   |     """ base class for Nodes in the collection tree.   | ||||||
|         Collector nodes have children and  |         Collector nodes have children and  | ||||||
|  | @ -50,7 +25,6 @@ class Node(object): | ||||||
|         - configuration/options for setup/teardown  |         - configuration/options for setup/teardown  | ||||||
|           stdout/stderr capturing and execution of test items  |           stdout/stderr capturing and execution of test items  | ||||||
|     """ |     """ | ||||||
|     ReprMetaInfo = ReprMetaInfo |  | ||||||
|     def __init__(self, name, parent=None, config=None): |     def __init__(self, name, parent=None, config=None): | ||||||
|         self.name = name  |         self.name = name  | ||||||
|         self.parent = parent |         self.parent = parent | ||||||
|  | @ -450,11 +424,11 @@ class Item(Node): | ||||||
|     def _deprecated_testexecution(self): |     def _deprecated_testexecution(self): | ||||||
|         if self.__class__.run != Item.run: |         if self.__class__.run != Item.run: | ||||||
|             warnoldtestrun(function=self.run) |             warnoldtestrun(function=self.run) | ||||||
|             self.run() |  | ||||||
|             return True |  | ||||||
|         elif self.__class__.execute != Item.execute: |         elif self.__class__.execute != Item.execute: | ||||||
|             warnoldtestrun(function=self.execute) |             warnoldtestrun(function=self.execute) | ||||||
|             self.execute(self.obj, *self._args) |         else: | ||||||
|  |             return False | ||||||
|  |         self.run() | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|     def run(self): |     def run(self): | ||||||
|  | @ -463,18 +437,8 @@ class Item(Node): | ||||||
| 
 | 
 | ||||||
|     def execute(self, obj, *args): |     def execute(self, obj, *args): | ||||||
|         """ deprecated, here because subclasses might call it. """ |         """ deprecated, here because subclasses might call it. """ | ||||||
|         warnoldtestrun(function=self.execute) |  | ||||||
|         return obj(*args) |         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): | def warnoldcollect(function=None): | ||||||
|     py.log._apiwarn("1.0",  |     py.log._apiwarn("1.0",  | ||||||
|  |  | ||||||
|  | @ -64,6 +64,9 @@ class ReSTSyntaxTest(py.test.collect.Item): | ||||||
|         super(ReSTSyntaxTest, self).__init__(*args, **kwargs) |         super(ReSTSyntaxTest, self).__init__(*args, **kwargs) | ||||||
|         self.project = project |         self.project = project | ||||||
| 
 | 
 | ||||||
|  |     def metainfo(self): | ||||||
|  |         return self.fspath, None, "syntax check" | ||||||
|  | 
 | ||||||
|     def runtest(self): |     def runtest(self): | ||||||
|         self.restcheck(py.path.svnwc(self.fspath)) |         self.restcheck(py.path.svnwc(self.fspath)) | ||||||
| 
 | 
 | ||||||
|  | @ -193,6 +196,9 @@ class ReSTSyntaxTest(py.test.collect.Item): | ||||||
|                     #return [] # no need to rebuild  |                     #return [] # no need to rebuild  | ||||||
| 
 | 
 | ||||||
| class DoctestText(py.test.collect.Item):  | class DoctestText(py.test.collect.Item):  | ||||||
|  |     def metainfo(self): | ||||||
|  |         return self.fspath, None, "doctest" | ||||||
|  | 
 | ||||||
|     def runtest(self):  |     def runtest(self):  | ||||||
|         content = self._normalize_linesep() |         content = self._normalize_linesep() | ||||||
|         newcontent = self.config.api.pytest_doctest_prepare_content(content=content) |         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) |                             args=(tryfn, path, lineno), callobj=localrefcheck) | ||||||
|          |          | ||||||
| class CheckLink(py.test.collect.Function):  | class CheckLink(py.test.collect.Function):  | ||||||
|     def repr_metainfo(self): |     def metainfo(self, basedir=None): | ||||||
|         return self.ReprMetaInfo(fspath=self.fspath, lineno=self._args[2], |         return (self.fspath, self._args[2], "checklink: %s" % self._args[0]) | ||||||
|             modpath="checklink: %s" % (self._args[0],)) | 
 | ||||||
|     def setup(self):  |     def setup(self):  | ||||||
|         pass  |         pass  | ||||||
|     def teardown(self):  |     def teardown(self):  | ||||||
|  |  | ||||||
|  | @ -138,8 +138,7 @@ class TerminalReporter: | ||||||
| 
 | 
 | ||||||
|     def pytest_itemstart(self, item, node=None): |     def pytest_itemstart(self, item, node=None): | ||||||
|         if self.config.option.debug: |         if self.config.option.debug: | ||||||
|             info = item.repr_metainfo() |             line = self._metainfoline(item) | ||||||
|             line = info.verboseline(basedir=self.curdir) + " " |  | ||||||
|             extra = "" |             extra = "" | ||||||
|             if node: |             if node: | ||||||
|                 extra = "-> " + str(node.gateway.id) |                 extra = "-> " + str(node.gateway.id) | ||||||
|  | @ -149,8 +148,7 @@ class TerminalReporter: | ||||||
|         elif self.config.option.verbose and self.config.option.dist == "no": |         elif self.config.option.verbose and self.config.option.dist == "no": | ||||||
|             # ensure that the path is printed before the 1st test of |             # ensure that the path is printed before the 1st test of | ||||||
|             # a module starts running |             # a module starts running | ||||||
|             info = item.repr_metainfo() |             line = self._metainfoline(item) | ||||||
|             line = info.verboseline(basedir=self.curdir) + " " |  | ||||||
|             #self.write_fspath_result(fspath, "") |             #self.write_fspath_result(fspath, "") | ||||||
|             self.write_ensure_prefix(line, "")  |             self.write_ensure_prefix(line, "")  | ||||||
| 
 | 
 | ||||||
|  | @ -172,8 +170,7 @@ class TerminalReporter: | ||||||
|         if not self.config.option.verbose: |         if not self.config.option.verbose: | ||||||
|             self.write_fspath_result(fspath, letter) |             self.write_fspath_result(fspath, letter) | ||||||
|         else: |         else: | ||||||
|             info = rep.colitem.repr_metainfo() |             line = self._metainfoline(rep.colitem) | ||||||
|             line = info.verboseline(basedir=self.curdir) + " " |  | ||||||
|             if not hasattr(rep, 'node'): |             if not hasattr(rep, 'node'): | ||||||
|                 self.write_ensure_prefix(line, word, **markup) |                 self.write_ensure_prefix(line, word, **markup) | ||||||
|             else: |             else: | ||||||
|  | @ -250,6 +247,22 @@ class TerminalReporter: | ||||||
|         for rootdir in rootdirs: |         for rootdir in rootdirs: | ||||||
|             self.write_line("### Watching:   %s" %(rootdir,), bold=True) |             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  |     # summaries for testrunfinish  | ||||||
|     # |     # | ||||||
|  |  | ||||||
|  | @ -87,15 +87,10 @@ class PyobjMixin(object): | ||||||
|         self._fslineno = fspath, lineno |         self._fslineno = fspath, lineno | ||||||
|         return fspath, lineno |         return fspath, lineno | ||||||
| 
 | 
 | ||||||
|     def repr_metainfo(self): |     def metainfo(self): | ||||||
|         fspath, lineno = self.getfslineno() |         fspath, lineno = self.getfslineno() | ||||||
|         modpath = self.getmodpath() |         modpath = self.getmodpath() | ||||||
|         return self.ReprMetaInfo( |         return fspath, lineno, modpath  | ||||||
|             fspath=fspath,  |  | ||||||
|             lineno=lineno, |  | ||||||
|             modpath=modpath, |  | ||||||
|         ) |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):  | class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):  | ||||||
|     Class = configproperty('Class') |     Class = configproperty('Class') | ||||||
|  | @ -235,6 +230,7 @@ class Instance(PyCollectorMixin, py.test.collect.Collector): | ||||||
| class FunctionMixin(PyobjMixin): | class FunctionMixin(PyobjMixin): | ||||||
|     """ mixin for the code common to Function and Generator. |     """ mixin for the code common to Function and Generator. | ||||||
|     """ |     """ | ||||||
|  | 
 | ||||||
|     def _getsortvalue(self):   |     def _getsortvalue(self):   | ||||||
|         return self.getfslineno() |         return self.getfslineno() | ||||||
| 
 | 
 | ||||||
|  | @ -315,6 +311,7 @@ class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector): | ||||||
|         call, args = obj[0], obj[1:] |         call, args = obj[0], obj[1:] | ||||||
|         return name, call, args  |         return name, call, args  | ||||||
|      |      | ||||||
|  | 
 | ||||||
| # | # | ||||||
| #  Test Items  | #  Test Items  | ||||||
| # | # | ||||||
|  | @ -447,8 +444,9 @@ class FuncargRequest: | ||||||
|                     name = name[len(self._argprefix):] |                     name = name[len(self._argprefix):] | ||||||
|                     if name not in available: |                     if name not in available: | ||||||
|                         available.append(name)  |                         available.append(name)  | ||||||
|         metainfo = self._pyfuncitem.repr_metainfo() |         fspath, lineno, msg = self._pyfuncitem.metainfo() | ||||||
|         msg = "funcargument %r not found for: %s" %(self.argname,metainfo.verboseline()) |         line = "%s:%s" %(fspath, lineno) | ||||||
|  |         msg = "funcargument %r not found for: %s" %(self.argname, line) | ||||||
|         msg += "\n available funcargs: %s" %(", ".join(available),) |         msg += "\n available funcargs: %s" %(", ".join(available),) | ||||||
|         raise LookupError(msg) |         raise LookupError(msg) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -206,63 +206,3 @@ class TestCustomConftests: | ||||||
|         evrec = testdir.inline_run(testdir.tmpdir, "--XX") |         evrec = testdir.inline_run(testdir.tmpdir, "--XX") | ||||||
|         names = [rep.colitem.name for rep in evrec.getreports("collectreport")] |         names = [rep.colitem.name for rep in evrec.getreports("collectreport")] | ||||||
|         assert 'hello' in names  |         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 len(colitems) == 1 | ||||||
|         assert colitems[0].name == "check_method" |         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