Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle pass-through assertion methods that are just forwarding parameters #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changelog
=========

* :bug:`85` Fixed marbles handling of deprecated assertEquals and similar methods
* :release:`0.9.5 <2018-06-24>`
* :support:`80` Added support for ``pandas<0.24``
* :bug:`58` Fixed test failure on OSX
Expand Down
14 changes: 12 additions & 2 deletions marbles/core/marbles/core/marbles.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,19 @@ def _find_msg_argument(signature):
The index of the ``msg`` param, the default value for it,
and the number of non-``msg`` positional parameters we expect.
'''
names = signature.parameters.keys()
names = list(signature.parameters.keys())
if len(names) == 2:
param_kinds = [signature.parameters[name].kind for name in names]
if (param_kinds[0] == inspect.Parameter.VAR_POSITIONAL
and param_kinds[1] == inspect.Parameter.VAR_KEYWORD):
# This is likely an assertion wrapper like
# assertEquals(*args, **kwargs), in which case we should
# just forward the arguments along and catch them in the
# wrapped assertion method (see
# https://github.com/twosigma/marbles/issue/85).
return sys.maxsize, None, len(names)
try:
msg_idx = list(names).index('msg')
msg_idx = names.index('msg')
default_msg = signature.parameters['msg'].default
except ValueError: # 'msg' is not in list
# It's likely that this is a custom assertion that's just
Expand Down
45 changes: 44 additions & 1 deletion marbles/core/tests/test_marbles.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def test_success(self):
def test_failure(self):
self.assertTrue(False, note='some note')

def test_deprecated_assertEquals_success(self):
x = 1
y = 1
self.assertEquals(x, y)

def test_deprecated_assertEquals_failure(self):
x = 1
y = 2
self.assertEquals(x, y)

def test_deprecated_assertEquals_success_with_note(self):
x = 1
y = 1
self.assertEquals(x, y, note='x should equal y')

def test_deprecated_assertEquals_failure_with_note(self):
x = 1
y = 2
self.assertEquals(x, y, note='x should equal y')

def test_fail_without_msg_without_note(self):
self.fail()

Expand Down Expand Up @@ -345,6 +365,29 @@ def test_annotated_assertion_error_raised(self):
with self.assertRaises(ContextualAssertionError):
self.case.test_failure()

def test_deprecated_assertEquals_success(self):
'''Does the deprecated assertEquals method still work?'''
if self._use_annotated_test_case:
with self.assertRaises(AnnotationError):
self.case.test_deprecated_assertEquals_success()
self.case.test_deprecated_assertEquals_success_with_note()
else:
self.case.test_deprecated_assertEquals_success()
self.case.test_deprecated_assertEquals_success_with_note()

def test_deprecated_assertEquals_failure(self):
'''Does the deprecated assertEquals method work on failure?'''
if self._use_annotated_test_case:
with self.assertRaises(AnnotationError):
self.case.test_deprecated_assertEquals_failure()
with self.assertRaises(ContextualAssertionError):
self.case.test_deprecated_assertEquals_failure_with_note()
else:
with self.assertRaises(ContextualAssertionError):
self.case.test_deprecated_assertEquals_failure()
with self.assertRaises(ContextualAssertionError):
self.case.test_deprecated_assertEquals_failure_with_note()

def test_fail_handles_note_properly(self):
'''Does TestCase.fail() deal with note the right way?'''
if self._use_annotated_test_case:
Expand Down Expand Up @@ -515,7 +558,7 @@ def test_get_stack(self):
self.assertEqual(e.filename, os.path.abspath(__file__))
# This isn't great because I have to change it every time I
# add/remove imports but oh well
self.assertEqual(e.linenumber, 211)
self.assertEqual(e.linenumber, 231)

def test_assert_stmt_indicates_line(self):
'''Does e.assert_stmt indicate the line from the source code?'''
Expand Down