catch duplicate _id values

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-12 02:16:02 +02:00
parent ebb0de4ff7
commit b40c3d5110
2 changed files with 5 additions and 2 deletions

View File

@ -39,6 +39,7 @@ class FuncSpecs:
self.cls = cls
self.module = module
self._calls = []
self._ids = py.builtin.set()
def addcall(self, _id=None, **kwargs):
for argname in kwargs:
@ -50,8 +51,9 @@ class FuncSpecs:
if _id is None:
_id = len(self._calls)
_id = str(_id)
#if _id in self._ids:
# raise ValueError("duplicate id %r" % _id)
if _id in self._ids:
raise ValueError("duplicate id %r" % _id)
self._ids.add(_id)
self._calls.append(CallSpec(_id, kwargs))
class FunctionCollector(py.test.collect.Collector):

View File

@ -152,6 +152,7 @@ class TestFuncSpecs:
funcspec.addcall(_xyz=10)
""")
funcspec.addcall(_id="hello", arg1=100)
py.test.raises(ValueError, "funcspec.addcall(_id='hello', arg1=100)")
call = funcspec._calls[0]
assert call.id == "hello"
assert call.funcargs == {'arg1': 100}