diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-18 20:20:50 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-18 20:20:50 (GMT) |
commit | 2489bd5d4e45b2a1d90f9336bf528ab1bba2d796 (patch) | |
tree | 807b68918b59cbadf99e71afa796ba6fda4c02cf /Lib/test/test_inspect.py | |
parent | f12e3e2b695d56ca6ac8a4fe0a74016dacbab478 (diff) | |
parent | 3018cc49e88721ef50c80b2d832b25dd4f0fe9d7 (diff) | |
download | cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.zip cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.tar.gz cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.tar.bz2 |
Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index a02f2e1..8e0e73c 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -89,6 +89,9 @@ def gen_coroutine_function_example(self): yield return 'spam' +class EqualsToAll: + def __eq__(self, other): + return True class TestPredicates(IsTestBase): @@ -2672,69 +2675,84 @@ class TestSignatureObject(unittest.TestCase): def test_signature_equality(self): def foo(a, *, b:int) -> float: pass - self.assertNotEqual(inspect.signature(foo), 42) + self.assertFalse(inspect.signature(foo) == 42) + self.assertTrue(inspect.signature(foo) != 42) + self.assertTrue(inspect.signature(foo) == EqualsToAll()) + self.assertFalse(inspect.signature(foo) != EqualsToAll()) def bar(a, *, b:int) -> float: pass - self.assertEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) == inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) != inspect.signature(bar)) self.assertEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def bar(a, *, b:int) -> int: pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def bar(a, *, b:int): pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def bar(a, *, b:int=42) -> float: pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def bar(a, *, c) -> float: pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def bar(a, b:int) -> float: pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def spam(b:int, a) -> float: pass - self.assertNotEqual(inspect.signature(spam), inspect.signature(bar)) + self.assertFalse(inspect.signature(spam) == inspect.signature(bar)) + self.assertTrue(inspect.signature(spam) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(spam)), hash(inspect.signature(bar))) def foo(*, a, b, c): pass def bar(*, c, b, a): pass - self.assertEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) == inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) != inspect.signature(bar)) self.assertEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def foo(*, a=1, b, c): pass def bar(*, c, b, a=1): pass - self.assertEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) == inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) != inspect.signature(bar)) self.assertEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def foo(pos, *, a=1, b, c): pass def bar(pos, *, c, b, a=1): pass - self.assertEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) == inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) != inspect.signature(bar)) self.assertEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def foo(pos, *, a, b, c): pass def bar(pos, *, c, b, a=1): pass - self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) == inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) != inspect.signature(bar)) self.assertNotEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) def foo(pos, *args, a=42, b, c, **kwargs:int): pass def bar(pos, *args, c, b, a=42, **kwargs:int): pass - self.assertEqual(inspect.signature(foo), inspect.signature(bar)) + self.assertTrue(inspect.signature(foo) == inspect.signature(bar)) + self.assertFalse(inspect.signature(foo) != inspect.signature(bar)) self.assertEqual( hash(inspect.signature(foo)), hash(inspect.signature(bar))) @@ -2907,11 +2925,17 @@ class TestParameterObject(unittest.TestCase): P = inspect.Parameter p = P('foo', default=42, kind=inspect.Parameter.KEYWORD_ONLY) - self.assertEqual(p, p) - self.assertNotEqual(p, 42) + self.assertTrue(p == p) + self.assertFalse(p != p) + self.assertFalse(p == 42) + self.assertTrue(p != 42) + self.assertTrue(p == EqualsToAll()) + self.assertFalse(p != EqualsToAll()) - self.assertEqual(p, P('foo', default=42, - kind=inspect.Parameter.KEYWORD_ONLY)) + self.assertTrue(p == P('foo', default=42, + kind=inspect.Parameter.KEYWORD_ONLY)) + self.assertFalse(p != P('foo', default=42, + kind=inspect.Parameter.KEYWORD_ONLY)) def test_signature_parameter_replace(self): p = inspect.Parameter('foo', default=42, @@ -3215,25 +3239,33 @@ class TestBoundArguments(unittest.TestCase): def test_signature_bound_arguments_equality(self): def foo(a): pass ba = inspect.signature(foo).bind(1) - self.assertEqual(ba, ba) + self.assertTrue(ba == ba) + self.assertFalse(ba != ba) + self.assertTrue(ba == EqualsToAll()) + self.assertFalse(ba != EqualsToAll()) ba2 = inspect.signature(foo).bind(1) - self.assertEqual(ba, ba2) + self.assertTrue(ba == ba2) + self.assertFalse(ba != ba2) ba3 = inspect.signature(foo).bind(2) - self.assertNotEqual(ba, ba3) + self.assertFalse(ba == ba3) + self.assertTrue(ba != ba3) ba3.arguments['a'] = 1 - self.assertEqual(ba, ba3) + self.assertTrue(ba == ba3) + self.assertFalse(ba != ba3) def bar(b): pass ba4 = inspect.signature(bar).bind(1) - self.assertNotEqual(ba, ba4) + self.assertFalse(ba == ba4) + self.assertTrue(ba != ba4) def foo(*, a, b): pass sig = inspect.signature(foo) ba1 = sig.bind(a=1, b=2) ba2 = sig.bind(b=2, a=1) - self.assertEqual(ba1, ba2) + self.assertTrue(ba1 == ba2) + self.assertFalse(ba1 != ba2) def test_signature_bound_arguments_pickle(self): def foo(a, b, *, c:1={}, **kw) -> {42:'ham'}: pass |