Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
d3c6f56e
Commit
d3c6f56e
authored
8 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
test(apiutils): added a unittest for describe_diff function
parent
ef3ecc9b
No related branches found
No related tags found
2 merge requests
!159
Release 0.16.o
,
!154
Added the possibility to use custom labels instead of 'old' and 'new'
Pipeline
#56805
passed with warnings
8 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/linkahead/apiutils.py
+3
-3
3 additions, 3 deletions
src/linkahead/apiutils.py
tox.ini
+1
-1
1 addition, 1 deletion
tox.ini
unittests/test_apiutils.py
+46
-1
46 additions, 1 deletion
unittests/test_apiutils.py
with
50 additions
and
5 deletions
src/linkahead/apiutils.py
+
3
−
3
View file @
d3c6f56e
This diff is collapsed.
Click to expand it.
tox.ini
+
1
−
1
View file @
d3c6f56e
...
...
@@ -17,6 +17,6 @@ max-line-length=100
[pytest]
testpaths
=
unittests
xfail_strict
=
True
addopts
=
-x -vv --cov=
caosdb
addopts
=
-x -vv --cov=
linkahead
pythonpath
=
src
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
46
−
1
View file @
d3c6f56e
#
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Alexander Schlemmer <a.schlemmer@indiscale.com>
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2022 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# Copyright (C) 2022 Daniel Hornung <d.hornung@indiscale.com>
...
...
@@ -31,7 +32,8 @@ import linkahead.apiutils
import
pytest
from
linkahead.apiutils
import
(
EntityMergeConflictError
,
apply_to_ids
,
compare_entities
,
create_id_query
,
empty_diff
,
merge_entities
,
resolve_reference
)
merge_entities
,
resolve_reference
,
describe_diff
)
from
linkahead.common.models
import
SPECIAL_ATTRIBUTES
...
...
@@ -627,3 +629,46 @@ def test_merge_id_with_resolved_entity():
merge_entities
(
recA
,
recB
,
merge_id_with_resolved_entity
=
True
)
assert
recA
.
get_property
(
rtname
).
value
==
[
ref_id
,
ref_id
*
2
]
assert
recA
.
get_property
(
rtname
).
value
==
recB
.
get_property
(
rtname
).
value
def
test_describe_diff
():
recA
=
db
.
Record
()
recA
.
add_property
(
name
=
"
propA
"
,
value
=
2
)
recA
.
add_property
(
name
=
"
propB
"
,
value
=
2
)
recA
.
add_property
(
name
=
"
propD
"
,
value
=-
273
,
unit
=
"
K
"
)
recB
=
db
.
Record
()
recB
.
add_property
(
name
=
"
propA
"
,
value
=
2
)
recB
.
add_property
(
name
=
"
propB
"
,
value
=
12
)
recB
.
add_property
(
name
=
"
propC
"
,
value
=
"
cool 17
"
)
recB
.
add_property
(
name
=
"
propD
"
,
value
=-
273
,
unit
=
"
°C
"
)
diff
=
compare_entities
(
recA
,
recB
)
diffout
=
describe_diff
(
*
diff
)
assert
diffout
.
startswith
(
"
## Difference between the old version and the new version of None
"
)
# The output of the describe_diff function is currently not ordered (e.g. by name of the property)
# so we cannot just compare a well-defined output string.
assert
"
it does not exist in the old version:
"
in
diffout
assert
"
old version: {
'
value
'
: 2}
"
in
diffout
assert
"
new version: {
'
value
'
: 12}
"
in
diffout
assert
"
old version: {
'
unit
'
:
'
K
'
}
"
in
diffout
assert
"
new version: {
'
unit
'
:
'
°C
'
}
"
in
diffout
diffout
=
describe_diff
(
*
diff
,
name
=
"
Entity
"
)
assert
diffout
.
startswith
(
"
## Difference between the old version and the new version of Entity
"
)
diffout
=
describe_diff
(
*
diff
,
label_old
=
"
recA
"
,
label_new
=
"
recB
"
)
assert
"
recA: {
'
value
'
: 2}
"
in
diffout
assert
"
recB: {
'
value
'
: 12}
"
in
diffout
assert
"
recA: {
'
unit
'
:
'
K
'
}
"
in
diffout
assert
"
recB: {
'
unit
'
:
'
°C
'
}
"
in
diffout
assert
"
it does not exist in the recA:
"
in
diffout
assert
"
old
"
not
in
diffout
assert
"
new
"
not
in
diffout
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment