-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-33284 Add to a unit test to improve coverage for numbers.py #6480
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4585786
Add to a unit test to improve coverage
barry-patrick 8766002
add test
barry-patrick a0c1942
Add test
barry-patrick bf91ec8
Merge branch 'master' of https://github.com/londinburgh/cpython
barry-patrick ac1fab6
get rid of old test
barry-patrick 57ede6e
improve test
barry-patrick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import math | ||
import operator | ||
import unittest | ||
from random import random | ||
from numbers import Complex, Real, Rational, Integral | ||
|
||
class TestNumbers(unittest.TestCase): | ||
|
@@ -40,5 +41,92 @@ def test_complex(self): | |
self.assertRaises(TypeError, int, c1) | ||
|
||
|
||
class TestAbstractNumbers(unittest.TestCase): | ||
def testComplex(self): | ||
|
||
class SubComplex(Complex): | ||
def __complex__(self): | ||
pass | ||
|
||
@property | ||
def real(self): | ||
return self._imag | ||
|
||
@property | ||
def imag(self): | ||
return self._real | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And same here with |
||
|
||
def __add__(self, other): | ||
pass | ||
|
||
def __radd__(self, other): | ||
pass | ||
|
||
def __neg__(self): | ||
pass | ||
|
||
def __pos__(self): | ||
pass | ||
|
||
def __mul__(self, other): | ||
pass | ||
|
||
def __rmul__(self, other): | ||
pass | ||
|
||
def __truediv__(self, other): | ||
pass | ||
|
||
def __rtruediv__(self, other): | ||
pass | ||
|
||
def __pow__(self, exponent): | ||
pass | ||
|
||
def __rpow__(self, base): | ||
pass | ||
|
||
def __abs__(self): | ||
pass | ||
|
||
def conjugate(self): | ||
pass | ||
|
||
def __init__(self, r, i): | ||
self.real = r | ||
self.imag = i | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, SubComplex) and self.imag == other.imag and self.real == other.real | ||
|
||
@imag.setter | ||
def imag(self, value): | ||
self._imag = value | ||
|
||
@real.setter | ||
def real(self, value): | ||
self._real = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These setters would be better placed alongside the getters. |
||
|
||
sc = SubComplex(0,0) | ||
self.assertIsInstance(sc, Complex) | ||
|
||
nonInstances = [None, "hat", lambda x: x + 1] | ||
|
||
for nonInstance in nonInstances: | ||
self.assertNotIsInstance(nonInstance, Complex) | ||
|
||
self.assertFalse(SubComplex.__bool__(0)) | ||
for i in range(100): | ||
self.assertTrue(SubComplex.__bool__(random() + 1e-6)) | ||
x = random() | ||
y = random() | ||
self.assertEqual(SubComplex.__sub__(x, y), x - y) | ||
self.assertEqual(SubComplex.__rsub__(x, y), - x + y) | ||
sc1 = SubComplex(x, y) | ||
sc2 = SubComplex(x, y) | ||
self.assertEqual(sc1, sc2) | ||
self.assertNotEqual(x, y + 1e-6) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be
return self._real
, right?