-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update operator from 3.13.5 #5935
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| import unittest | ||
| import inspect | ||
| import pickle | ||
| import sys | ||
| from decimal import Decimal | ||
| from fractions import Fraction | ||
|
|
||
| from test import support | ||
| from test.support import import_helper | ||
|
|
@@ -508,6 +511,44 @@ def __getitem__(self, other): return 5 # so that C is a sequence | |
| self.assertEqual(operator.ixor (c, 5), "ixor") | ||
| self.assertEqual(operator.iconcat (c, c), "iadd") | ||
|
|
||
| def test_iconcat_without_getitem(self): | ||
| operator = self.module | ||
|
|
||
| msg = "'int' object can't be concatenated" | ||
| with self.assertRaisesRegex(TypeError, msg): | ||
| operator.iconcat(1, 0.5) | ||
|
|
||
| def test_index(self): | ||
| operator = self.module | ||
| class X: | ||
| def __index__(self): | ||
| return 1 | ||
|
|
||
| self.assertEqual(operator.index(X()), 1) | ||
| self.assertEqual(operator.index(0), 0) | ||
| self.assertEqual(operator.index(1), 1) | ||
| self.assertEqual(operator.index(2), 2) | ||
| with self.assertRaises((AttributeError, TypeError)): | ||
| operator.index(1.5) | ||
| with self.assertRaises((AttributeError, TypeError)): | ||
| operator.index(Fraction(3, 7)) | ||
| with self.assertRaises((AttributeError, TypeError)): | ||
| operator.index(Decimal(1)) | ||
| with self.assertRaises((AttributeError, TypeError)): | ||
| operator.index(None) | ||
|
|
||
| def test_not_(self): | ||
| operator = self.module | ||
| class C: | ||
| def __bool__(self): | ||
| raise SyntaxError | ||
| self.assertRaises(TypeError, operator.not_) | ||
| self.assertRaises(SyntaxError, operator.not_, C()) | ||
| self.assertFalse(operator.not_(5)) | ||
| self.assertFalse(operator.not_([0])) | ||
| self.assertTrue(operator.not_(0)) | ||
| self.assertTrue(operator.not_([])) | ||
|
|
||
| def test_length_hint(self): | ||
| operator = self.module | ||
| class X(object): | ||
|
|
@@ -533,6 +574,13 @@ def __length_hint__(self): | |
| with self.assertRaises(LookupError): | ||
| operator.length_hint(X(LookupError)) | ||
|
|
||
| class Y: pass | ||
|
|
||
| msg = "'str' object cannot be interpreted as an integer" | ||
| with self.assertRaisesRegex(TypeError, msg): | ||
| operator.length_hint(X(2), "abc") | ||
| self.assertEqual(operator.length_hint(Y(), 10), 10) | ||
|
|
||
| def test_call(self): | ||
| operator = self.module | ||
|
|
||
|
|
@@ -555,6 +603,43 @@ def test_dunder_is_original(self): | |
| if dunder: | ||
| self.assertIs(dunder, orig) | ||
|
|
||
| @support.requires_docstrings | ||
| def test_attrgetter_signature(self): | ||
| # TODO: RUSTPYTHON fails only when running inside COperatorTestCase | ||
| if type(self).__name__ == 'COperatorTestCase': | ||
| self.skipTest("TODO: RUSTPYTHON") | ||
|
Member
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. This way of handling makes hard to fix it when it is actually fixed. A recommended pattern is adding another test function under COperatorTestCase.
Contributor
Author
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.
sure, np |
||
|
|
||
| operator = self.module | ||
| sig = inspect.signature(operator.attrgetter) | ||
| self.assertEqual(str(sig), '(attr, /, *attrs)') | ||
| sig = inspect.signature(operator.attrgetter('x', 'z', 'y')) | ||
| self.assertEqual(str(sig), '(obj, /)') | ||
|
|
||
| @support.requires_docstrings | ||
| def test_itemgetter_signature(self): | ||
| # TODO: RUSTPYTHON fails only when running inside COperatorTestCase | ||
| if type(self).__name__ == 'COperatorTestCase': | ||
| self.skipTest("TODO: RUSTPYTHON") | ||
|
|
||
| operator = self.module | ||
| sig = inspect.signature(operator.itemgetter) | ||
| self.assertEqual(str(sig), '(item, /, *items)') | ||
| sig = inspect.signature(operator.itemgetter(2, 3, 5)) | ||
| self.assertEqual(str(sig), '(obj, /)') | ||
|
|
||
| @support.requires_docstrings | ||
| def test_methodcaller_signature(self): | ||
| # TODO: RUSTPYTHON fails only when running inside COperatorTestCase | ||
| if type(self).__name__ == 'COperatorTestCase': | ||
| self.skipTest("TODO: RUSTPYTHON") | ||
|
|
||
| operator = self.module | ||
| sig = inspect.signature(operator.methodcaller) | ||
| self.assertEqual(str(sig), '(name, /, *args, **kwargs)') | ||
| sig = inspect.signature(operator.methodcaller('foo', 2, y=3)) | ||
| self.assertEqual(str(sig), '(obj, /)') | ||
|
|
||
|
|
||
| class PyOperatorTestCase(OperatorTestCase, unittest.TestCase): | ||
| module = py_operator | ||
|
|
||
|
|
||
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.
I have tried to mark those signature tests with
unittest.expectedFailurebut then the test fails on "UNEXPECTED SUCCESS", very strange.I have tried to mess with defining
__text_signature__but I'm guessing that I'm doing something wrong because it completely ignores it. I would appreciate any suggestion that you have:)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.
Maybe it is a base class of multiple other tests