Skip to content

Commit

Permalink
fix assertArgSpecMatches to function as documented
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Aug 27, 2013
1 parent 3c76164 commit bbfa0ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
7 changes: 3 additions & 4 deletions master/buildbot/test/unit/test_util_interfaces.py
Expand Up @@ -74,7 +74,7 @@ def myfunc6(xx, yy):
error = None

self.assertIdentical(type(error), unittest.FailTest)
self.assertEqual(error.args, ('Expected: (xx, yy); got: (x, y)',))
self.assertEqual(error.args, ('Expected: (x, y); got: (x, yy)',))

def test_function_style(self):
def myfunc(x, y=2, *args):
Expand All @@ -93,6 +93,5 @@ def myfunc3(x, y=3, *args):
else:
error = None

# TODO: instate these commented assertions
self.assertIdentical(type(error), type(None)) #unittest.FailTest)
#self.assertEqual(error.args, ('Expected: (x, y=3, *args); got: (x, y=2, *args)',))
self.assertIdentical(type(error), unittest.FailTest)
self.assertEqual(error.args, ('Expected: (x, y=2, *args); got: (x, y=3, *args)',))
37 changes: 23 additions & 14 deletions master/buildbot/test/util/interfaces.py
Expand Up @@ -19,7 +19,7 @@ class InterfaceTests(object):

# assertions

def assertArgSpecMatches(self, *actualMethods):
def assertArgSpecMatches(self, actualMethod, *fakeMethods):
"""Usage::
@self.assertArgSpecMatches(obj.methodUnderTest)
Expand Down Expand Up @@ -55,19 +55,28 @@ def remove_decorators(func):
except AttributeError:
return func

def wrap(template):
for actual in actualMethods:
actual_argspec = filter(
inspect.getargspec(remove_decorators(actual)))
template_argspec = filter(
inspect.getargspec(remove_decorators(template)))
if actual_argspec != template_argspec:
msg = "Expected: %s; got: %s" % (
inspect.formatargspec(*template_argspec),
inspect.formatargspec(*actual_argspec))
self.fail(msg)
return template # just in case it's useful
return wrap
def assert_same_argspec(expected, actual):
if expected != actual:
msg = "Expected: %s; got: %s" % (
inspect.formatargspec(*expected),
inspect.formatargspec(*actual))
self.fail(msg)

actual_argspec = filter(
inspect.getargspec(remove_decorators(actualMethod)))

for fakeMethod in fakeMethods:
fake_argspec = filter(
inspect.getargspec(remove_decorators(fakeMethod)))
assert_same_argspec(actual_argspec, fake_argspec)

def assert_same_argspec_decorator(decorated):
expected_argspec = filter(
inspect.getargspec(remove_decorators(decorated)))
assert_same_argspec(expected_argspec, actual_argspec)
# The decorated function works as usual.
return decorated
return assert_same_argspec_decorator

def assertInterfacesImplemented(self, cls):
"Given a class, assert that the zope.interface.Interfaces are implemented to specification."
Expand Down

0 comments on commit bbfa0ee

Please sign in to comment.