Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
42838e73
Commit
42838e73
authored
5 months ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
TST: refine test
parent
cf6fdcd4
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!217
TST: Make NamedTemporaryFiles Windows-compatible
,
!212
ENH: introduce inheritance of identifiables
Pipeline
#59881
failed
5 months ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caoscrawler/identifiable_adapters.py
+7
-3
7 additions, 3 deletions
src/caoscrawler/identifiable_adapters.py
src/doc/concepts.rst
+14
-8
14 additions, 8 deletions
src/doc/concepts.rst
unittests/test_identifiable_adapters.py
+3
-2
3 additions, 2 deletions
unittests/test_identifiable_adapters.py
with
24 additions
and
13 deletions
src/caoscrawler/identifiable_adapters.py
+
7
−
3
View file @
42838e73
...
...
@@ -650,15 +650,17 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
reg
=
self
.
_get_registered_for_rt
(
prt
)
if
reg
is
not
None
:
registered
.
append
(
reg
)
# TODO we might in future want to check whether the registered identifiables are the same
if
len
(
registered
)
>
1
:
raise
RuntimeError
(
"
Multiple registered identifiables found.
"
)
raise
RuntimeError
(
"
Multiple registered identifiables found for a Record
"
f
"
with the following parents:
{
record
.
parents
}
"
)
elif
len
(
registered
)
==
1
:
return
registered
[
0
]
else
:
return
None
def
_get_registered_for_rt
(
self
,
rt
):
def
_get_registered_for_rt
(
self
,
rt
:
db
.
RecordType
):
"""
returns the registered identifiable for the given RecordType or the
registered identifiable of the first parent
...
...
@@ -671,8 +673,10 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
for
parent
in
rt
.
parents
:
prt
=
_retrieve_RecordType
(
id
=
parent
.
id
,
name
=
parent
.
name
)
registered
.
append
(
self
.
_get_registered_for_rt
(
prt
))
# TODO we might in future want to check whether the registered identifiables are the same
if
len
(
registered
)
>
1
:
raise
RuntimeError
(
"
Multiple registered identifiables found.
"
)
raise
RuntimeError
(
"
Multiple registered identifiables found for the RecordType
"
f
"
{
rt
.
name
}
with the following parents:
{
rt
.
parents
}
"
)
elif
len
(
registered
)
==
1
:
return
registered
[
0
]
else
:
...
...
This diff is collapsed.
Click to expand it.
src/doc/concepts.rst
+
14
−
8
View file @
42838e73
...
...
@@ -94,20 +94,26 @@ reference the object to be identified. You can also use the wildcard "*" as
RecordType name in the configuration which will only require, that ANY Record
references the Record at hand.
If a Record has multiple parents, only one of them must have an registered identifiable.
Instead of defining registered identifiables for a RecordType directly, they can be
defined for their parents. I.e. if there is no registered identifiable for a RecordType,
then it will be checked whether there is a parent that has one.
If multiple recordtypes exist in the inheritance chain with a registered identifiable, then
the one that is closest to the direct parent is used. In case of multiple inheritance, only one branch must have registered identifiables.
Reasoning:
If there
ar
e mutliple registered identifiables that could be used to identify a given record
, then
only a single
one of them
is
used, it might be that the existence check returns a different result than if
an
other one would
be used. This would allow for unpredictable and inconsistent behavior(Example: one registered identifiable
If there
would b
e mutliple registered identifiables that could be used to identify a given record
and
only a single
one of them
would
used, it might be that the existence check returns a different result than if
the
other one would
be used. This would allow for unpredictable and inconsistent behavior
(Example: one registered identifiable
contains the name another one property date. Using the name might imply that the record does not exist and using
the date might imply that it does. Thus, for any Record the registered identifiable must be unique).
Anlogous Example: If you ti
n
nk in the context, of relational databases, there can always only be a foreign key
Anlogous Example: If you t
h
ink in the context, of relational databases, there can always only be a foreign key
associated with one table.
When no registered identifiable exist for the direct parents, registered identifiables may be used
from their parents. If multiple recordtypes exist in the inheritance chain with a registered identifiable, then
the one that is closest to the direct parent is used. In case of multiple inheritance, only one branch must have registered identifiables.
Note:
In case of using the registered identifiable of a parent, the identifiable will be created by using the parent RecordType. Example: The
registered identifiable is defined for the parent "Experiment" and the RecordType at hand "LaseExperiment" is a child of "Experiment".
Then the identifiable will construct a query that searches for "Experiment" Records (and not "LaseExperiment" Records).
Identified Records
...
...
This diff is collapsed.
Click to expand it.
unittests/test_identifiable_adapters.py
+
3
−
2
View file @
42838e73
...
...
@@ -54,6 +54,7 @@ def mock_retrieve_RecordType(id, name):
"
Experiment
"
:
db
.
RecordType
(
name
=
"
Experiment
"
),
"
Lab
"
:
db
.
RecordType
(
name
=
"
Lab
"
),
"
Analysis
"
:
db
.
RecordType
(
name
=
"
Analysis
"
),
"
MetaAnalysis
"
:
db
.
RecordType
(
name
=
"
MetaAnalysis
"
).
add_parent
(
"
Analysis
"
),
"
Measurement
"
:
db
.
RecordType
(
name
=
"
Measurement
"
).
add_parent
(
"
Experiment
"
)
}[
name
]
...
...
@@ -322,8 +323,8 @@ def test_get_registered_identifiable():
with
pytest
.
raises
(
RuntimeError
):
registered
=
ident
.
get_registered_identifiable
(
rec
)
# Test the same but with an additional parent that
also has
a registered identifiable
rec
=
db
.
Record
().
add_parent
(
name
=
"
Me
asurement
"
).
add_parent
(
name
=
"
Experiment
"
)
# Test the same but with an additional parent that
has a parent with
a registered identifiable
rec
=
db
.
Record
().
add_parent
(
name
=
"
Me
taAnalysis
"
).
add_parent
(
name
=
"
Experiment
"
)
with
pytest
.
raises
(
RuntimeError
):
registered
=
ident
.
get_registered_identifiable
(
rec
)
...
...
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