Skip to content
Snippets Groups Projects
Verified Commit 206c0e36 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-more-pip-info

parents 6d478f4b 7b18356d
Branches
Tags
1 merge request!42DOC: More info for pip.
Pipeline #18621 passed
...@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
- #90 compare_entities function in apiutils does not check units - #90 compare_entities function in apiutils does not check units
- #94 some special properties were not checked in compare_entities
### Security ### ### Security ###
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# ** header v3.0
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> # Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> # Copyright (C) 2020-2022 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -109,7 +108,7 @@ def retrieve_entities_with_ids(entities): ...@@ -109,7 +108,7 @@ def retrieve_entities_with_ids(entities):
for i in range(len(entities)//step+1): for i in range(len(entities)//step+1):
collection.extend( collection.extend(
execute_query( execute_query(
create_id_query(entities[i*step:(i+1)*step]))) create_id_query(entities[i*step:(i+1)*step])))
return collection return collection
...@@ -558,7 +557,8 @@ def getCommitIn(folder): ...@@ -558,7 +557,8 @@ def getCommitIn(folder):
return t.readline().strip() return t.readline().strip()
COMPARED = ["name", "role", "datatype", "description", "importance"] COMPARED = ["name", "role", "datatype", "description", "importance",
"id", "path", "checksum", "size"]
def compare_entities(old_entity: Entity, new_entity: Entity): def compare_entities(old_entity: Entity, new_entity: Entity):
...@@ -653,7 +653,8 @@ def compare_entities(old_entity: Entity, new_entity: Entity): ...@@ -653,7 +653,8 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
olddiff["properties"].pop(prop.name) olddiff["properties"].pop(prop.name)
else: else:
raise NotImplementedError() raise NotImplementedError(
"Comparison not implemented for multi-properties.")
for prop in new_entity.properties: for prop in new_entity.properties:
if len([0 for p in old_entity.properties if p.name == prop.name]) == 0: if len([0 for p in old_entity.properties if p.name == prop.name]) == 0:
......
[tox] [tox]
envlist=py36, py37, py38, py39 envlist=py36, py37, py38, py39, py310
skip_missing_interpreters = true skip_missing_interpreters = true
[testenv] [testenv]
......
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# #
# ** header v3.0
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> # Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> # Copyright (C) 2020-2022 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -179,3 +178,55 @@ def test_compare_entities_units(): ...@@ -179,3 +178,55 @@ def test_compare_entities_units():
assert diff_r1["properties"]["test"]["unit"] == "cm" assert diff_r1["properties"]["test"]["unit"] == "cm"
assert diff_r2["properties"]["test"]["unit"] == "m" assert diff_r2["properties"]["test"]["unit"] == "m"
def test_compare_special_properties():
# Test for all known special properties:
SPECIAL_PROPERTIES = ("description", "name",
"checksum", "size", "path", "id")
INTS = ("size", "id")
HIDDEN = ("checksum", "size")
for key in SPECIAL_PROPERTIES:
set_key = key
if key in HIDDEN:
set_key = "_" + key
r1 = db.Record()
r2 = db.Record()
if key not in INTS:
setattr(r1, set_key, "bla 1")
setattr(r2, set_key, "bla 1")
else:
setattr(r1, set_key, 1)
setattr(r2, set_key, 1)
diff_r1, diff_r2 = compare_entities(r1, r2)
print(diff_r1)
print(diff_r2)
assert key not in diff_r1
assert key not in diff_r2
assert len(diff_r1["parents"]) == 0
assert len(diff_r2["parents"]) == 0
assert len(diff_r1["properties"]) == 0
assert len(diff_r2["properties"]) == 0
if key not in INTS:
setattr(r2, set_key, "bla test")
else:
setattr(r2, set_key, 2)
diff_r1, diff_r2 = compare_entities(r1, r2)
print(r1)
print(r2)
print(diff_r1)
print(diff_r2)
assert key in diff_r1
assert key in diff_r2
if key not in INTS:
assert diff_r1[key] == "bla 1"
assert diff_r2[key] == "bla test"
else:
assert diff_r1[key] == 1
assert diff_r2[key] == 2
assert len(diff_r1["properties"]) == 0
assert len(diff_r2["properties"]) == 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment