Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
661f2c5a
Commit
661f2c5a
authored
4 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Update test_error_stuff.py
parent
7059554d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_error_stuff.py
+50
-43
50 additions, 43 deletions
tests/test_error_stuff.py
with
50 additions
and
43 deletions
tests/test_error_stuff.py
+
50
−
43
View file @
661f2c5a
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#
#
# 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 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2020 Florian Spreckelsen <f.spreckelsen@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
...
@@ -21,62 +23,67 @@
...
@@ -21,62 +23,67 @@
#
#
# ** end header
# ** end header
#
#
"""
Created on 19.02.2015.
"""
Test different entity errors.
Created on 19.02.2015.
@author: tf
@author: tf
"""
"""
from
caosdb.exceptions
import
EntityDoesNotExistError
,
UniqueNamesError
,
\
import
caosdb
as
h
TransactionError
,
EntityError
,
UnqualifiedPropertiesError
,
\
from
caosdb.exceptions
import
(
EntityDoesNotExistError
,
EntityHasNoDatatypeError
,
UnqualifiedParentsError
UniqueNamesError
,
TransactionError
,
EntityError
,
UnqualifiedPropertiesError
,
EntityHasNoDatatypeError
,
UnqualifiedParentsError
)
import
pytest
def
test_retrieval_no_exception_raised
():
def
setup_module
():
import
caosdb
as
h
try
:
from
nose.tools
import
assert_true
,
assert_false
# @UnresolvedImport
h
.
execute_query
(
"
FIND Test*
"
).
delete
()
except
:
pass
p
=
h
.
Property
(
name
=
"
Non-ExsistentProperty
"
).
retrieve
(
unique
=
True
,
raise_exception_on_error
=
False
)
assert_false
(
p
.
is_valid
())
assert_true
(
p
.
id
is
None
or
p
.
id
<
0
)
def
setup
():
"""
No additional setup required.
"""
setup_module
()
def
test_retrieval_exception_raised
():
import
caosdb
as
h
from
nose.tools
import
assert_true
,
assert_is_not_none
,
assert_equal
# @UnresolvedImport
# special error: EntityDoesNotExistError
def
teardown
():
try
:
"""
Delete everything.
"""
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
setup_module
()
raise_exception_on_error
=
True
)
assert_true
(
False
)
except
EntityDoesNotExistError
as
e
:
print
(
"
print(
"
+
str
(
id
(
e
))
+
"
)
"
)
print
(
e
)
assert_is_not_none
(
e
.
get_entity
())
# more general error: EntityError
try
:
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
raise_exception_on_error
=
True
)
assert_true
(
False
)
except
EntityError
as
e
:
print
(
e
)
assert_is_not_none
(
e
.
get_entity
())
assert_equal
(
'
Non-ExistentProperty
'
,
e
.
get_entity
().
name
)
# most general error: TransactionError
def
test_retrieval_no_exception_raised
():
try
:
"""
Test whether retrieval fails but error is suppressed.
"""
p
=
h
.
Property
(
name
=
"
TestNon-ExsistentProperty
"
).
retrieve
(
unique
=
True
,
raise_exception_on_error
=
False
)
assert
not
p
.
is_valid
()
assert
(
p
.
id
is
None
or
p
.
id
<
0
)
def
test_retrieval_exception_raised
():
"""
Test if a TransactionError with the correct child is raised, and if
the child has the correct super classes.
"""
propname
=
"
TestNon-ExistentProperty
"
with
pytest
.
raises
(
TransactionError
)
as
te
:
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
raise_exception_on_error
=
True
)
raise_exception_on_error
=
True
)
assert_true
(
False
)
te
=
te
.
value
except
EntityDoesNotExistError
as
e
:
assert
len
(
te
.
get_errors
())
==
1
print
(
e
)
ee
=
te
.
get_errors
()[
0
]
assert_is_not_none
(
e
.
get_entities
())
# Check for type incl. inheritance
print
(
e
.
get_entities
())
assert
isinstance
(
ee
,
EntityDoesNotExistError
)
assert_is_not_none
(
e
.
get_entity
())
assert
isinstance
(
ee
,
EntityError
)
print
(
e
.
get_entity
())
assert
isinstance
(
ee
,
TransactionError
)
assert_equal
(
1
,
len
(
e
.
get_entities
()))
# Correct entity causing the error:
assert_equal
(
'
Non-ExistentProperty
'
,
e
.
get_entities
()[
0
].
name
)
assert
not
(
ee
.
get_entity
()
is
None
)
assert
ee
.
get_entity
().
name
==
propname
assert
len
(
ee
.
get_entities
())
==
1
assert
ee
.
get_entities
()[
0
].
name
==
propname
def
test_insertion_no_exception_raised
():
def
test_insertion_no_exception_raised
():
...
...
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