diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-03-31 23:41:16 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-03-31 23:41:16 +0200 |
commit | 78f5cc159afb76d35b703bd6f3d1adcdc96bdd8a (patch) | |
tree | c79d4daafaadb51d42c6da724a86dea239afd920 | |
parent | cbb64dd73ca7114ee423caa5e5dcc58a2de87126 (diff) | |
download | pygobject-78f5cc159afb76d35b703bd6f3d1adcdc96bdd8a.tar.gz |
enum/flags: set tp_hash on Python 2 as well; add hash() tests
It shouldn't make a difference.
-rw-r--r-- | gi/pygenum.c | 2 | ||||
-rw-r--r-- | gi/pygflags.c | 2 | ||||
-rw-r--r-- | tests/test_gi.py | 12 |
3 files changed, 12 insertions, 4 deletions
diff --git a/gi/pygenum.c b/gi/pygenum.c index 5671ff5d..dd324700 100644 --- a/gi/pygenum.c +++ b/gi/pygenum.c @@ -376,9 +376,7 @@ pygi_enum_register_types(PyObject *d) PyGEnum_Type.tp_base = &PYGLIB_PyLong_Type; PyGEnum_Type.tp_new = pyg_enum_new; -#if PY_VERSION_HEX >= 0x03000000 PyGEnum_Type.tp_hash = PyLong_Type.tp_hash; -#endif PyGEnum_Type.tp_repr = (reprfunc)pyg_enum_repr; PyGEnum_Type.tp_str = (reprfunc)pyg_enum_repr; PyGEnum_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; diff --git a/gi/pygflags.c b/gi/pygflags.c index 3280a8c6..f59612db 100644 --- a/gi/pygflags.c +++ b/gi/pygflags.c @@ -505,9 +505,7 @@ pygi_flags_register_types(PyObject *d) PyGFlags_Type.tp_base = &PYGLIB_PyLong_Type; PyGFlags_Type.tp_new = pyg_flags_new; -#if PY_VERSION_HEX >= 0x03000000 PyGFlags_Type.tp_hash = PyLong_Type.tp_hash; -#endif PyGFlags_Type.tp_repr = (reprfunc)pyg_flags_repr; PyGFlags_Type.tp_as_number = &pyg_flags_as_number; PyGFlags_Type.tp_str = (reprfunc)pyg_flags_repr; diff --git a/tests/test_gi.py b/tests/test_gi.py index 24d94b20..4d65e803 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -1814,6 +1814,10 @@ class TestEnum(unittest.TestCase): self.assertEqual(GIMarshallingTests.Enum.__module__, "gi.repository.GIMarshallingTests") + def test_hash(self): + assert (hash(GIMarshallingTests.Enum.VALUE1) == + hash(GIMarshallingTests.Enum(GIMarshallingTests.Enum.VALUE1))) + def test_repr(self): self.assertEqual(repr(GIMarshallingTests.Enum.VALUE3), "<enum GI_MARSHALLING_TESTS_ENUM_VALUE3 of type " @@ -1890,6 +1894,10 @@ class TestGEnum(unittest.TestCase): self.assertEqual(GIMarshallingTests.GEnum.__module__, "gi.repository.GIMarshallingTests") + def test_hash(self): + assert (hash(GIMarshallingTests.GEnum.VALUE3) == + hash(GIMarshallingTests.GEnum(GIMarshallingTests.GEnum.VALUE3))) + def test_repr(self): self.assertEqual(repr(GIMarshallingTests.GEnum.VALUE3), "<enum GI_MARSHALLING_TESTS_GENUM_VALUE3 of type " @@ -1958,6 +1966,10 @@ class TestGFlags(unittest.TestCase): "<flags GI_MARSHALLING_TESTS_FLAGS_VALUE2 of type " "GIMarshallingTests.Flags>") + def test_hash(self): + assert (hash(GIMarshallingTests.Flags.VALUE2) == + hash(GIMarshallingTests.Flags(GIMarshallingTests.Flags.VALUE2))) + def test_flags_large_in(self): GIMarshallingTests.extra_flags_large_in( GIMarshallingTests.ExtraFlags.VALUE2) |