From 734c5e5040476c310f5e495c680f603e63462484 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Thu, 4 Jun 2020 14:13:48 +0200 Subject: [PATCH] STY: autopep8'ed --- src/caosdb/common/models.py | 2 +- unittests/test_datatype.py | 13 +++++----- unittests/test_xml_parsing.py | 46 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 unittests/test_xml_parsing.py diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index ead0eb61..06617d1e 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -970,6 +970,7 @@ class Entity(object): return self + def _parse_value(datatype, value): if value is None: return value @@ -1031,7 +1032,6 @@ def _parse_value(datatype, value): return str(value) - def _log_request(request, xml_body=None): if Container._debug() > 0: print("\n" + request) diff --git a/unittests/test_datatype.py b/unittests/test_datatype.py index ccda7734..ef650ce2 100644 --- a/unittests/test_datatype.py +++ b/unittests/test_datatype.py @@ -37,14 +37,14 @@ def test_list_utilites(): def test_parsing_of_intger_list_values(): dtype = db.LIST(db.INTEGER) - assert _parse_value(dtype, [1,2,3]) == [1,2,3] + assert _parse_value(dtype, [1, 2, 3]) == [1, 2, 3] assert _parse_value(dtype, [1]) == [1] - assert _parse_value(dtype, [None,1,2,3]) == [None,1,2,3] - assert _parse_value(dtype, [1, None,1,2,3]) == [1, None,1,2,3] - assert _parse_value(dtype, ["4", 4]) == [4,4] + assert _parse_value(dtype, [None, 1, 2, 3]) == [None, 1, 2, 3] + assert _parse_value(dtype, [1, None, 1, 2, 3]) == [1, None, 1, 2, 3] + assert _parse_value(dtype, ["4", 4]) == [4, 4] assert _parse_value(dtype, []) == [] - assert _parse_value(dtype, None) == None - assert _parse_value(None, [1,2,3.14,"asdf"]) == [1,2,3.14,"asdf"] + assert _parse_value(dtype, None) is None + assert _parse_value(None, [1, 2, 3.14, "asdf"]) == [1, 2, 3.14, "asdf"] assert _parse_value(dtype, 1) == [1] with raises(ValueError): @@ -75,6 +75,5 @@ def test_parsing_of_references(): assert _parse_value(dtype, "2345") == 2345 assert _parse_value(dtype, 2345) == 2345 - entity = db.Record(name="bla") assert id(_parse_value(dtype, entity)) == id(entity) diff --git a/unittests/test_xml_parsing.py b/unittests/test_xml_parsing.py new file mode 100644 index 00000000..46c6978c --- /dev/null +++ b/unittests/test_xml_parsing.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +# +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2020 Timm Fitschen <t.fitschen@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/>. +# +# ** end header + +import caosdb as db +from caosdb.common.utils import xml2str +from .test_property import testrecord + + +def test_null_empty_text_value_1(): + assert testrecord.get_property("LISTofTEXT").value == ["One", "Two", "Three", None, ""] + + +def test_null_empty_text_value_2(): + assert testrecord.get_property("NULLTEXT1").value is None + + +def test_null_empty_text_value_3(): + assert testrecord.get_property("NULLTEXT2").value is None + + +def test_null_empty_text_value_4(): + assert testrecord.get_property("EMPTYTEXT1").value == "" + + +def test_null_empty_text_value_5(): + assert testrecord.get_property("EMPTYTEXT2").value == "" -- GitLab