From a6ba7f9a514ec0cba9ee06e2fbd77573d809fd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Mon, 21 Nov 2022 10:28:10 +0100 Subject: [PATCH] TST: move identifiable test to appropriate file --- unittests/test_identifiable.py | 59 ++++++++++++++++++++++++++++++ unittests/test_identified_cache.py | 27 -------------- 2 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 unittests/test_identifiable.py diff --git a/unittests/test_identifiable.py b/unittests/test_identifiable.py new file mode 100644 index 00000000..ab33edea --- /dev/null +++ b/unittests/test_identifiable.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2021 Henrik tom Wörden <h.tomwoerden@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + +""" +test identifiable module +""" + +import caosdb as db +from caoscrawler.identifiable import Identifiable +from caoscrawler.identified_cache import IdentifiedCache + + +def test_create_hashable_string(): + assert Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B")) == "P<B>N<A>" + assert Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>a:5" + a = Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': 4, 'b': 5})) + b = Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'b': 5, 'a': 4})) + assert a == b + assert ( + Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': db.Record(id=12)}) + ) == "P<B>N<A>a:12") + a = Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]})) + assert (a == "P<B>N<A>a:[12]") + assert (Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]") + assert ( + Identifiable._create_hashable_string( + Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12), 11]}) + ) == "P<B>N<A>a:[12, 11]") + assert ( + Identifiable._create_hashable_string( + Identifiable(record_type="B", properties={'a': [db.Record()]}) + ) != Identifiable._create_hashable_string( + Identifiable(record_type="B", properties={'a': [db.Record()]}))) diff --git a/unittests/test_identified_cache.py b/unittests/test_identified_cache.py index dfddbbd9..f6edbdfa 100644 --- a/unittests/test_identified_cache.py +++ b/unittests/test_identified_cache.py @@ -33,33 +33,6 @@ from caoscrawler.identified_cache import IdentifiedCache def test_create_hash(): - assert Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B")) == "P<B>N<A>" - assert Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>a:5" - a = Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': 4, 'b': 5})) - b = Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'b': 5, 'a': 4})) - assert a == b - assert ( - Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': db.Record(id=12)}) - ) == "P<B>N<A>a:12") - a = Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]})) - assert (a == "P<B>N<A>a:[12]") - assert (Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]") - assert ( - Identifiable._create_hashable_string( - Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12), 11]}) - ) == "P<B>N<A>a:[12, 11]") - assert ( - Identifiable._create_hashable_string( - Identifiable(record_type="B", properties={'a': [db.Record()]}) - ) != Identifiable._create_hashable_string( - Identifiable(record_type="B", properties={'a': [db.Record()]}))) def test_IdentifiedCache(): -- GitLab