diff --git a/swh/model/test_identifiers.py b/swh/model/test_identifiers.py deleted file mode 100644 --- a/swh/model/test_identifiers.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2020 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from swh.model.identifiers import SWHID - - -def test_swhid_hash(): - object_id = "94a9ed024d3859793618152ea559a168bbcbb5e2" - - assert hash(SWHID(object_type="directory", object_id=object_id)) == hash( - SWHID(object_type="directory", object_id=object_id) - ) - - assert hash( - SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) - ) == hash( - SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) - ) - - # Different order of the dictionary, so the underlying order of the tuple in - # ImmutableDict is different. - assert hash( - SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) - ) == hash( - SWHID( - object_type="directory", - object_id=object_id, - metadata={"baz": "qux", "foo": "bar"}, - ) - ) - - -def test_swhid_eq(): - object_id = "94a9ed024d3859793618152ea559a168bbcbb5e2" - - assert SWHID(object_type="directory", object_id=object_id) == SWHID( - object_type="directory", object_id=object_id - ) - - assert SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) == SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) - - assert SWHID( - object_type="directory", - object_id=object_id, - metadata={"foo": "bar", "baz": "qux"}, - ) == SWHID( - object_type="directory", - object_id=object_id, - metadata={"baz": "qux", "foo": "bar"}, - ) diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -1075,3 +1075,69 @@ def test_normalize_timestamp_dict_invalid_timestamp(dict_input): with pytest.raises(ValueError, match="non-integer timestamp"): normalize_timestamp(dict_input) + + +def test_swhid_hash(): + object_id = "94a9ed024d3859793618152ea559a168bbcbb5e2" + + assert hash(SWHID(object_type="directory", object_id=object_id)) == hash( + SWHID(object_type="directory", object_id=object_id) + ) + + assert hash( + SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) + ) == hash( + SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) + ) + + # Different order of the dictionary, so the underlying order of the tuple in + # ImmutableDict is different. + assert hash( + SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) + ) == hash( + SWHID( + object_type="directory", + object_id=object_id, + metadata={"baz": "qux", "foo": "bar"}, + ) + ) + + +def test_swhid_eq(): + object_id = "94a9ed024d3859793618152ea559a168bbcbb5e2" + + assert SWHID(object_type="directory", object_id=object_id) == SWHID( + object_type="directory", object_id=object_id + ) + + assert SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) == SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) + + assert SWHID( + object_type="directory", + object_id=object_id, + metadata={"foo": "bar", "baz": "qux"}, + ) == SWHID( + object_type="directory", + object_id=object_id, + metadata={"baz": "qux", "foo": "bar"}, + )