Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
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-julialib
Commits
51239e8e
Commit
51239e8e
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
TST: Fix unittests
parent
ddd10f94
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!13
ENH: Use new value and datatype structs
Pipeline
#13891
failed
3 years ago
Stage: info
Stage: code-style
Stage: setup
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Entity.jl
+3
-3
3 additions, 3 deletions
src/Entity.jl
test/runtests.jl
+79
-73
79 additions, 73 deletions
test/runtests.jl
with
82 additions
and
76 deletions
src/Entity.jl
+
3
−
3
View file @
51239e8e
...
...
@@ -580,7 +580,7 @@ function create_value(
)
elseif
in_type
<:
Integer
err_code
=
ccall
(
(
:
caosdb_entity_create_
bool
_value
,
CaosDB
.
library_name
),
(
:
caosdb_entity_create_
int
_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Value
},
Clong
),
out
,
...
...
@@ -588,7 +588,7 @@ function create_value(
)
elseif
in_type
<:
Number
err_code
=
ccall
(
(
:
caosdb_entity_create_
bool
_value
,
CaosDB
.
library_name
),
(
:
caosdb_entity_create_
double
_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Value
},
Cdouble
),
out
,
...
...
@@ -1224,7 +1224,7 @@ function _get_value(value::Ref{_Value})
# convert to vector of type of elements s.th. it can be re-used in a
# `set_value` function.
elt_type
=
typeof
(
out
[
1
])
convert
(
Vector
{
elt_type
},
out
)
return
convert
(
Vector
{
elt_type
},
out
)
end
return
out
...
...
This diff is collapsed.
Click to expand it.
test/runtests.jl
+
79
−
73
View file @
51239e8e
...
...
@@ -102,12 +102,13 @@ using CaosDB
rt_with_name
=
CaosDB
.
Entity
.
create_recordtype
(
"TestRT"
)
@test
CaosDB
.
Entity
.
get_name
(
rt_with_name
)
==
"TestRT"
@test
CaosDB
.
Entity
.
get_role
(
rt_with_name
)
==
"
RECORD_TYPE
"
@test
CaosDB
.
Entity
.
get_role
(
rt_with_name
)
==
CaosDB
.
Constants
.
ROLE
.
RECORD_TYPE
prop_with_name_and_unit
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"TestProp"
,
unit
=
"m"
)
@test
CaosDB
.
Entity
.
get_name
(
prop_with_name_and_unit
)
==
"TestProp"
@test
CaosDB
.
Entity
.
get_role
(
prop_with_name_and_unit
)
==
"PROPERTY"
@test
CaosDB
.
Entity
.
get_role
(
prop_with_name_and_unit
)
==
CaosDB
.
Constants
.
ROLE
.
PROPERTY
@test
CaosDB
.
Entity
.
get_unit
(
prop_with_name_and_unit
)
==
"m"
rec_with_parent_and_props
=
CaosDB
.
Entity
.
create_record
(
"TestRec"
)
...
...
@@ -119,7 +120,7 @@ using CaosDB
# cannot set the datatype of a record
@test_throws
CaosDB
.
Exceptions
.
ClientException
CaosDB
.
Entity
.
set_datatype
(
rec_with_parent_and_props
,
"
INTEGER
"
,
CaosDB
.
Constants
.
DATATYPE
.
INTEGER
,
)
par1
=
CaosDB
.
Entity
.
create_parent
(
name
=
"Parent1"
)
...
...
@@ -145,22 +146,20 @@ using CaosDB
prop1
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property1"
,
value
=
"2"
)
prop2
=
CaosDB
.
Entity
.
create_property
(
id
=
"id_of_property_2"
)
CaosDB
.
Entity
.
set_datatype
(
prop2
,
"
TEXT
"
)
CaosDB
.
Entity
.
set_datatype
(
prop2
,
CaosDB
.
Constants
.
DATATYPE
.
TEXT
)
prop3
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property3"
)
CaosDB
.
Entity
.
append_properties
(
rec_with_parent_and_props
,
[
prop1
,
prop2
,
prop3
])
@test
length
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
))
==
3
# properties can be accessed as a list
#
TODO(florian) Fix this once we have a reasonable treatment of value objects in Extern C.
@test
_broken
CaosDB
.
Entity
.
get_value
(
#
properties can be accessed as a list
@test
CaosDB
.
Entity
.
get_value
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
1
],
)
==
"2"
type
,
is_ref
,
is_list
=
CaosDB
.
Entity
.
get_datatype
(
type
,
collection
=
CaosDB
.
Entity
.
get_datatype
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
@test
type
==
"TEXT"
@test
is_ref
==
false
@test
is_list
==
false
@test
type
==
CaosDB
.
Constants
.
DATATYPE
.
TEXT
@test
collection
==
nothing
@test
CaosDB
.
Entity
.
get_id
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
==
"id_of_property_2"
...
...
@@ -177,7 +176,7 @@ using CaosDB
local_path
=
string
(
pwd
(),
"/"
,
"caosdbfilefortests.txt"
),
remote_path
=
"/remote_path/file.txt"
,
)
@test
CaosDB
.
Entity
.
get_role
(
file_ent
)
==
"
FILE
"
@test
CaosDB
.
Entity
.
get_role
(
file_ent
)
==
CaosDB
.
Constants
.
ROLE
.
FILE
@test
CaosDB
.
Entity
.
get_name
(
file_ent
)
==
"TestFile"
# local file not found
rm
(
string
(
pwd
(),
"/"
,
"caosdbfilefortests.txt"
))
...
...
@@ -191,21 +190,16 @@ using CaosDB
@testset
"Property values and datatypes"
begin
@testset
"Entity properties"
begin
int_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"IntProp"
,
datatype
=
"INTEGER"
)
double_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"DoubleProp"
,
datatype
=
"DOUBLE"
,
)
bool_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"BoolProp"
,
datatype
=
"BOOLEAN"
,
)
CaosDB
.
Entity
.
create_property_entity
(
name
=
"IntProp"
,
datatype
=
INTEGER
)
double_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"DoubleProp"
,
datatype
=
DOUBLE
)
bool_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"BoolProp"
,
datatype
=
BOOLEAN
)
string_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"StringProp"
,
datatype
=
"
TEXT
"
)
CaosDB
.
Entity
.
create_property_entity
(
name
=
"StringProp"
,
datatype
=
TEXT
)
ref_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"RefProp"
,
datatype
=
"MyRefType"
,
is_reference
=
true
,
)
CaosDB
.
Entity
.
set_value
(
int_prop
,
123
)
CaosDB
.
Entity
.
set_value
(
double_prop
,
10.246
)
...
...
@@ -222,38 +216,37 @@ using CaosDB
@test
isa
(
CaosDB
.
Entity
.
get_value
(
bool_prop
),
Bool
)
@test
isa
(
CaosDB
.
Entity
.
get_value
(
string_prop
),
String
)
@test
isa
(
CaosDB
.
Entity
.
get_value
(
ref_prop
),
String
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_prop
)
==
(
"
INTEGER
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_prop
)
==
(
"
DOUBLE
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_prop
)
==
(
"
BOOLEAN
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_prop
)
==
(
"
TEXT
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_prop
)
==
(
"MyRefType"
,
true
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_prop
)
==
(
INTEGER
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_prop
)
==
(
DOUBLE
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_prop
)
==
(
BOOLEAN
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_prop
)
==
(
TEXT
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_prop
)
==
(
"MyRefType"
,
nothing
)
""" Test lists """
int_list_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"IntProp"
,
datatype
=
"
INTEGER
"
,
is_list
=
true
,
datatype
=
INTEGER
,
collection
=
LIST
,
)
double_list_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"DoubleProp"
,
datatype
=
"
DOUBLE
"
,
is_list
=
true
,
datatype
=
DOUBLE
,
collection
=
LIST
,
)
bool_list_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"BoolProp"
,
datatype
=
"
BOOLEAN
"
,
is_list
=
true
,
datatype
=
BOOLEAN
,
collection
=
LIST
,
)
string_list_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"StringProp"
,
datatype
=
"
TEXT
"
,
is_list
=
true
,
datatype
=
TEXT
,
collection
=
LIST
,
)
ref_list_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"RefListProp"
,
datatype
=
"MyRefType"
,
is_list
=
true
,
is_reference
=
true
,
collection
=
LIST
,
)
CaosDB
.
Entity
.
set_value
(
int_list_prop
,
[
123
,
456
])
CaosDB
.
Entity
.
set_value
(
double_list_prop
,
[
10.246
,
3.14
])
...
...
@@ -270,25 +263,39 @@ using CaosDB
@test
isa
(
CaosDB
.
Entity
.
get_value
(
bool_list_prop
),
Vector
{
Bool
})
@test
isa
(
CaosDB
.
Entity
.
get_value
(
string_list_prop
),
Vector
{
String
})
@test
isa
(
CaosDB
.
Entity
.
get_value
(
ref_list_prop
),
Vector
{
String
})
@test
CaosDB
.
Entity
.
get_datatype
(
int_list_prop
)
==
(
"INTEGER"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_list_prop
)
==
(
"DOUBLE"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_list_prop
)
==
(
"BOOLEAN"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_list_prop
)
==
(
"TEXT"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_list_prop
)
==
(
"MyRefType"
,
true
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_list_prop
)
==
(
INTEGER
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_list_prop
)
==
(
DOUBLE
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_list_prop
)
==
(
BOOLEAN
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_list_prop
)
==
(
TEXT
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_list_prop
)
==
(
"MyRefType"
,
LIST
)
# Check copying of values and datatypes
copied_prop
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"CopiedProp"
)
set_datatype
(
copied_prop
,
get_datatype
(
int_list_prop
))
set_value
(
copied_prop
,
get_value
(
int_list_prop
))
@test
get_datatype
(
copied_prop
)
==
get_datatype
(
int_list_prop
)
@test
get_value
(
copied_prop
)
==
get_value
(
int_list_prop
)
set_datatype
(
copied_prop
,
get_datatype
(
double_prop
))
set_value
(
copied_prop
,
get_value
(
double_prop
))
@test
get_datatype
(
copied_prop
)
==
get_datatype
(
double_prop
)
@test
get_value
(
copied_prop
)
==
get_value
(
double_prop
)
set_datatype
(
copied_prop
,
get_datatype
(
ref_list_prop
))
set_value
(
copied_prop
,
get_value
(
ref_list_prop
))
@test
get_datatype
(
copied_prop
)
==
get_datatype
(
ref_list_prop
)
# TODO(fspreck) Fix this. Garbage collection?
@test_broken
get_value
(
copied_prop
)
==
get_value
(
ref_list_prop
)
end
@testset
"Property properties"
begin
int_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"IntProp"
,
datatype
=
"
INTEGER
"
)
int_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"IntProp"
,
datatype
=
INTEGER
)
double_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"DoubleProp"
,
datatype
=
"DOUBLE"
)
bool_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"BoolProp"
,
datatype
=
"BOOLEAN"
)
CaosDB
.
Entity
.
create_property
(
name
=
"DoubleProp"
,
datatype
=
DOUBLE
)
bool_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"BoolProp"
,
datatype
=
BOOLEAN
)
string_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"StringProp"
,
datatype
=
"TEXT"
)
ref_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"RefProp"
,
datatype
=
"MyRefType"
,
is_reference
=
true
,
)
CaosDB
.
Entity
.
create_property
(
name
=
"StringProp"
,
datatype
=
TEXT
)
ref_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"RefProp"
,
datatype
=
"MyRefType"
)
CaosDB
.
Entity
.
set_value
(
int_prop
,
123
)
CaosDB
.
Entity
.
set_value
(
double_prop
,
10.246
)
CaosDB
.
Entity
.
set_value
(
bool_prop
,
true
)
...
...
@@ -304,38 +311,37 @@ using CaosDB
@test
isa
(
CaosDB
.
Entity
.
get_value
(
bool_prop
),
Bool
)
@test
isa
(
CaosDB
.
Entity
.
get_value
(
string_prop
),
String
)
@test
isa
(
CaosDB
.
Entity
.
get_value
(
ref_prop
),
String
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_prop
)
==
(
"
INTEGER
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_prop
)
==
(
"
DOUBLE
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_prop
)
==
(
"
BOOLEAN
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_prop
)
==
(
"
TEXT
"
,
false
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_prop
)
==
(
"MyRefType"
,
true
,
false
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_prop
)
==
(
INTEGER
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_prop
)
==
(
DOUBLE
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_prop
)
==
(
BOOLEAN
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_prop
)
==
(
TEXT
,
nothing
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_prop
)
==
(
"MyRefType"
,
nothing
)
""" Test lists """
int_list_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"IntProp"
,
datatype
=
"
INTEGER
"
,
is_list
=
true
,
datatype
=
INTEGER
,
collection
=
LIST
,
)
double_list_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"DoubleProp"
,
datatype
=
"
DOUBLE
"
,
is_list
=
true
,
datatype
=
DOUBLE
,
collection
=
LIST
,
)
bool_list_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"BoolProp"
,
datatype
=
"
BOOLEAN
"
,
is_list
=
true
,
datatype
=
BOOLEAN
,
collection
=
LIST
,
)
string_list_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"StringProp"
,
datatype
=
"
TEXT
"
,
is_list
=
true
,
datatype
=
TEXT
,
collection
=
LIST
,
)
ref_list_prop
=
CaosDB
.
Entity
.
create_property
(
name
=
"RefListProp"
,
datatype
=
"MyRefType"
,
is_list
=
true
,
is_reference
=
true
,
collection
=
LIST
,
)
CaosDB
.
Entity
.
set_value
(
int_list_prop
,
[
123
,
456
])
CaosDB
.
Entity
.
set_value
(
double_list_prop
,
[
10.246
,
3.14
])
...
...
@@ -352,11 +358,11 @@ using CaosDB
@test
isa
(
CaosDB
.
Entity
.
get_value
(
bool_list_prop
),
Vector
{
Bool
})
@test
isa
(
CaosDB
.
Entity
.
get_value
(
string_list_prop
),
Vector
{
String
})
@test
isa
(
CaosDB
.
Entity
.
get_value
(
ref_list_prop
),
Vector
{
String
})
@test
CaosDB
.
Entity
.
get_datatype
(
int_list_prop
)
==
(
"
INTEGER
"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_list_prop
)
==
(
"
DOUBLE
"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_list_prop
)
==
(
"
BOOLEAN
"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_list_prop
)
==
(
"
TEXT
"
,
false
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_list_prop
)
==
(
"MyRefType"
,
true
,
true
)
@test
CaosDB
.
Entity
.
get_datatype
(
int_list_prop
)
==
(
INTEGER
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
double_list_prop
)
==
(
DOUBLE
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
bool_list_prop
)
==
(
BOOLEAN
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
string_list_prop
)
==
(
TEXT
,
LIST
)
@test
CaosDB
.
Entity
.
get_datatype
(
ref_list_prop
)
==
(
"MyRefType"
,
LIST
)
end
end
end
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