remove superflous collect_by_name, and improve some docs
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									b6ec5a575d
								
							
						
					
					
						commit
						bc574f4d94
					
				|  | @ -334,13 +334,23 @@ Reference of important objects involved in hooks | ||||||
| .. autoclass:: pytest.plugin.config.Parser | .. autoclass:: pytest.plugin.config.Parser | ||||||
|     :members: |     :members: | ||||||
| 
 | 
 | ||||||
| .. autoclass:: pytest.plugin.session.File | .. autoclass:: pytest.plugin.session.Node(name, parent) | ||||||
|     :inherited-members: |     :members: | ||||||
| 
 | 
 | ||||||
| .. autoclass:: pytest.plugin.session.Item | ..  | ||||||
|     :inherited-members: |     .. autoclass:: pytest.plugin.session.File(fspath, parent) | ||||||
|  |         :members: | ||||||
| 
 | 
 | ||||||
| .. autoclass:: pytest.plugin.python.Function |     .. autoclass:: pytest.plugin.session.Item(name, parent) | ||||||
|  |         :members: | ||||||
|  | 
 | ||||||
|  |     .. autoclass:: pytest.plugin.python.Module(name, parent) | ||||||
|  |         :members: | ||||||
|  | 
 | ||||||
|  |     .. autoclass:: pytest.plugin.python.Class(name, parent) | ||||||
|  |         :members: | ||||||
|  | 
 | ||||||
|  |     .. autoclass:: pytest.plugin.python.Function(name, parent) | ||||||
|         :members: |         :members: | ||||||
| 
 | 
 | ||||||
| .. autoclass:: pytest.plugin.runner.CallInfo | .. autoclass:: pytest.plugin.runner.CallInfo | ||||||
|  |  | ||||||
|  | @ -244,7 +244,6 @@ class CmdOptions(object): | ||||||
| 
 | 
 | ||||||
| class Config(object): | class Config(object): | ||||||
|     """ access to configuration values, pluginmanager and plugin hooks.  """ |     """ access to configuration values, pluginmanager and plugin hooks.  """ | ||||||
|     Option = py.std.optparse.Option |  | ||||||
|     basetemp = None |     basetemp = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self, pluginmanager=None): |     def __init__(self, pluginmanager=None): | ||||||
|  | @ -353,7 +352,9 @@ class Config(object): | ||||||
|                 keep=0, rootdir=basetemp, lock_timeout=None) |                 keep=0, rootdir=basetemp, lock_timeout=None) | ||||||
| 
 | 
 | ||||||
|     def getini(self, name): |     def getini(self, name): | ||||||
|         """ return configuration value from an ini file. """ |         """ return configuration value from an ini file. If the | ||||||
|  |         specified name hasn't been registered through a prior ``parse.addini`` | ||||||
|  |         call (usually from a plugin), a ValueError is raised. """ | ||||||
|         try: |         try: | ||||||
|             description, type = self._parser._inidict[name] |             description, type = self._parser._inidict[name] | ||||||
|         except KeyError: |         except KeyError: | ||||||
|  | @ -391,7 +392,8 @@ class Config(object): | ||||||
|         return self._conftest.rget(name, path) |         return self._conftest.rget(name, path) | ||||||
| 
 | 
 | ||||||
|     def getvalue(self, name, path=None): |     def getvalue(self, name, path=None): | ||||||
|         """ return 'name' value looked up from command line 'options'. |         """ return ``name`` value looked set from command line options. | ||||||
|  | 
 | ||||||
|         (deprecated) if we can't find the option also lookup |         (deprecated) if we can't find the option also lookup | ||||||
|         the name in a matching conftest file. |         the name in a matching conftest file. | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  | @ -385,6 +385,11 @@ class TmpTestdir: | ||||||
|         #config.pluginmanager.do_unconfigure(config) |         #config.pluginmanager.do_unconfigure(config) | ||||||
|         return node |         return node | ||||||
| 
 | 
 | ||||||
|  |     def collect_by_name(self, modcol, name): | ||||||
|  |         for colitem in modcol._memocollect(): | ||||||
|  |             if colitem.name == name: | ||||||
|  |                 return colitem | ||||||
|  | 
 | ||||||
|     def popen(self, cmdargs, stdout, stderr, **kw): |     def popen(self, cmdargs, stdout, stderr, **kw): | ||||||
|         if not hasattr(py.std, 'subprocess'): |         if not hasattr(py.std, 'subprocess'): | ||||||
|             py.test.skip("no subprocess module") |             py.test.skip("no subprocess module") | ||||||
|  |  | ||||||
|  | @ -446,13 +446,8 @@ class Collector(Node): | ||||||
|         """ |         """ | ||||||
|         raise NotImplementedError("abstract") |         raise NotImplementedError("abstract") | ||||||
| 
 | 
 | ||||||
|     def collect_by_name(self, name): |  | ||||||
|         for colitem in self._memocollect(): |  | ||||||
|             if colitem.name == name: |  | ||||||
|                 return colitem |  | ||||||
| 
 |  | ||||||
|     def repr_failure(self, excinfo): |     def repr_failure(self, excinfo): | ||||||
|         """ represent a failure. """ |         """ represent a collection failure. """ | ||||||
|         if excinfo.errisinstance(self.CollectError): |         if excinfo.errisinstance(self.CollectError): | ||||||
|             exc = excinfo.value |             exc = excinfo.value | ||||||
|             return str(exc.args[0]) |             return str(exc.args[0]) | ||||||
|  | @ -525,8 +520,7 @@ class Directory(FSCollector): | ||||||
| 
 | 
 | ||||||
| class Item(Node): | class Item(Node): | ||||||
|     """ a basic test invocation item. Note that for a single function |     """ a basic test invocation item. Note that for a single function | ||||||
|     there might be multiple test invocation items. Attributes: |     there might be multiple test invocation items. | ||||||
|      |  | ||||||
|     """ |     """ | ||||||
|     def reportinfo(self): |     def reportinfo(self): | ||||||
|         return self.fspath, None, "" |         return self.fspath, None, "" | ||||||
|  |  | ||||||
|  | @ -268,9 +268,9 @@ class TestSorting: | ||||||
|             def test_pass(): pass |             def test_pass(): pass | ||||||
|             def test_fail(): assert 0 |             def test_fail(): assert 0 | ||||||
|         """) |         """) | ||||||
|         fn1 = modcol.collect_by_name("test_pass") |         fn1 = testdir.collect_by_name(modcol, "test_pass") | ||||||
|         assert isinstance(fn1, py.test.collect.Function) |         assert isinstance(fn1, py.test.collect.Function) | ||||||
|         fn2 = modcol.collect_by_name("test_pass") |         fn2 = testdir.collect_by_name(modcol, "test_pass") | ||||||
|         assert isinstance(fn2, py.test.collect.Function) |         assert isinstance(fn2, py.test.collect.Function) | ||||||
| 
 | 
 | ||||||
|         assert fn1 == fn2 |         assert fn1 == fn2 | ||||||
|  | @ -279,7 +279,7 @@ class TestSorting: | ||||||
|             assert cmp(fn1, fn2) == 0 |             assert cmp(fn1, fn2) == 0 | ||||||
|         assert hash(fn1) == hash(fn2) |         assert hash(fn1) == hash(fn2) | ||||||
| 
 | 
 | ||||||
|         fn3 = modcol.collect_by_name("test_fail") |         fn3 = testdir.collect_by_name(modcol, "test_fail") | ||||||
|         assert isinstance(fn3, py.test.collect.Function) |         assert isinstance(fn3, py.test.collect.Function) | ||||||
|         assert not (fn1 == fn3) |         assert not (fn1 == fn3) | ||||||
|         assert fn1 != fn3 |         assert fn1 != fn3 | ||||||
|  | @ -1092,7 +1092,7 @@ class TestReportInfo: | ||||||
|             class TestClass: |             class TestClass: | ||||||
|                 def test_hello(self): pass |                 def test_hello(self): pass | ||||||
|         """) |         """) | ||||||
|         classcol = modcol.collect_by_name("TestClass") |         classcol = testdir.collect_by_name(modcol, "TestClass") | ||||||
|         fspath, lineno, msg = classcol.reportinfo() |         fspath, lineno, msg = classcol.reportinfo() | ||||||
|         assert fspath == modcol.fspath |         assert fspath == modcol.fspath | ||||||
|         assert lineno == 1 |         assert lineno == 1 | ||||||
|  | @ -1106,7 +1106,7 @@ class TestReportInfo: | ||||||
|                     assert x |                     assert x | ||||||
|                 yield check, 3 |                 yield check, 3 | ||||||
|         """) |         """) | ||||||
|         gencol = modcol.collect_by_name("test_gen") |         gencol = testdir.collect_by_name(modcol, "test_gen") | ||||||
|         fspath, lineno, modpath = gencol.reportinfo() |         fspath, lineno, modpath = gencol.reportinfo() | ||||||
|         assert fspath == modcol.fspath |         assert fspath == modcol.fspath | ||||||
|         assert lineno == 1 |         assert lineno == 1 | ||||||
|  |  | ||||||
|  | @ -28,9 +28,9 @@ class TestCollector: | ||||||
|             def test_pass(): pass |             def test_pass(): pass | ||||||
|             def test_fail(): assert 0 |             def test_fail(): assert 0 | ||||||
|         """) |         """) | ||||||
|         fn1 = modcol.collect_by_name("test_pass") |         fn1 = testdir.collect_by_name(modcol, "test_pass") | ||||||
|         assert isinstance(fn1, py.test.collect.Function) |         assert isinstance(fn1, py.test.collect.Function) | ||||||
|         fn2 = modcol.collect_by_name("test_pass") |         fn2 = testdir.collect_by_name(modcol, "test_pass") | ||||||
|         assert isinstance(fn2, py.test.collect.Function) |         assert isinstance(fn2, py.test.collect.Function) | ||||||
| 
 | 
 | ||||||
|         assert fn1 == fn2 |         assert fn1 == fn2 | ||||||
|  | @ -39,7 +39,7 @@ class TestCollector: | ||||||
|             assert cmp(fn1, fn2) == 0 |             assert cmp(fn1, fn2) == 0 | ||||||
|         assert hash(fn1) == hash(fn2) |         assert hash(fn1) == hash(fn2) | ||||||
| 
 | 
 | ||||||
|         fn3 = modcol.collect_by_name("test_fail") |         fn3 = testdir.collect_by_name(modcol, "test_fail") | ||||||
|         assert isinstance(fn3, py.test.collect.Function) |         assert isinstance(fn3, py.test.collect.Function) | ||||||
|         assert not (fn1 == fn3) |         assert not (fn1 == fn3) | ||||||
|         assert fn1 != fn3 |         assert fn1 != fn3 | ||||||
|  | @ -57,8 +57,9 @@ class TestCollector: | ||||||
|                  def test_foo(): |                  def test_foo(): | ||||||
|                      pass |                      pass | ||||||
|         """) |         """) | ||||||
|         cls = modcol.collect_by_name("TestClass") |         cls = testdir.collect_by_name(modcol, "TestClass") | ||||||
|         fn = cls.collect_by_name("()").collect_by_name("test_foo") |         fn = testdir.collect_by_name( | ||||||
|  |             testdir.collect_by_name(cls, "()"), "test_foo") | ||||||
| 
 | 
 | ||||||
|         parent = fn.getparent(py.test.collect.Module) |         parent = fn.getparent(py.test.collect.Module) | ||||||
|         assert parent is modcol |         assert parent is modcol | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue