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

Fix test_nonnumeric_magnitudes #661

Closed
wants to merge 12 commits into from
Closed

Fix test_nonnumeric_magnitudes #661

wants to merge 12 commits into from

Conversation

labrys
Copy link

@labrys labrys commented Jul 21, 2018

The test for non-numeric magnitudes was using assertRaises incorrectly. While the context-manager form should be preferred, with the given style it should be passed the function to test, not the result of the function.

# Wrong
self.assertRaises(RuntimeError, self.compareQuantity_compact(x,x))

# Better
self.assertRaises(RuntimeError, self.compareQuantity_compact, x, x)

# Best
with self.assertRaises(RuntimeError):
    self.compareQuantity_compact(x,x)

While fixing this I found that RuntimeError was not being raised, instead a RuntimeWarning was being issued. Since unittest.TestCase.assertWarns was not added until Python 3.2 (see docs), I'm testing for the warning as recommended in the Python 2.7 docs.

Fixes #659

labrys added 11 commits July 21, 2018 23:52
Fix `test_nonnumeric_magnitudes`
Should be 'if cond is None:'
Should be 'not in'
Should be 'is not'
Bare except also catches unexpected events like memory errors,
interrupts,  system exit, and so on.  Prefer the specific exception
or `except Exception:` for general exceptions.  If you're sure
what you're doing, be explicit and write `except BaseException:`.
@hgrecco hgrecco mentioned this pull request Jul 25, 2018
@hgrecco
Copy link
Owner

hgrecco commented Dec 5, 2019

I think this PR is no longer necessary due to the recent merge of #910

@hgrecco hgrecco closed this Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DeprecationWarning callable is None when running unit tests
2 participants