FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
datajoint-python/tests/test_adapted_attributes.py at master · mohammadbashiri/datajoint-python · GitHub
mohammadbashiri
datajoint-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
datajoint-python
/
tests
/
test_adapted_attributes.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (68 loc) · 2.99 KB
Breadcrumbs
datajoint-python
/
tests
/
test_adapted_attributes.py
Copy path
File metadata and controls
84 lines (68 loc) · 2.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import
datajoint
as
dj
import
networkx
as
nx
from
itertools
import
zip_longest
from
nose
.
tools
import
assert_true
,
assert_equal
,
assert_dict_equal
from
.
import
schema_adapted
as
adapted
from
.
schema_adapted
import
graph
def
test_adapted_type
(
c
=
adapted
.
Connectivity
()):
dj
.
errors
.
_switch_adapted_types
(
True
)
graphs
=
[
nx
.
lollipop_graph
(
4
,
2
),
nx
.
star_graph
(
5
),
nx
.
barbell_graph
(
3
,
1
),
nx
.
cycle_graph
(
5
)]
c
.
insert
((
i
,
g
)
for
i
,
g
in
enumerate
(
graphs
))
returned_graphs
=
c
.
fetch
(
'conn_graph'
,
order_by
=
'connid'
)
for
g1
,
g2
in
zip
(
graphs
,
returned_graphs
):
assert_true
(
isinstance
(
g2
,
nx
.
Graph
))
assert_equal
(
len
(
g1
.
edges
),
len
(
g2
.
edges
))
assert_true
(
0
==
len
(
nx
.
symmetric_difference
(
g1
,
g2
).
edges
))
c
.
delete
()
dj
.
errors
.
_switch_adapted_types
(
False
)
def
test_adapted_filepath_type
():
# https://github.com/datajoint/datajoint-python/issues/684
dj
.
errors
.
_switch_adapted_types
(
True
)
dj
.
errors
.
_switch_filepath_types
(
True
)
c
=
adapted
.
Connectivity
()
c
.
delete
()
c
.
insert1
((
0
,
nx
.
lollipop_graph
(
4
,
2
)))
layout
=
nx
.
spring_layout
(
c
.
fetch1
(
'conn_graph'
))
# make json friendly
layout
=
{
str
(
k
): [
round
(
r
,
ndigits
=
4
)
for
r
in
v
]
for
k
,
v
in
layout
.
items
()}
t
=
adapted
.
Layout
()
t
.
insert1
((
0
,
layout
))
result
=
t
.
fetch1
(
'layout'
)
assert_dict_equal
(
result
,
layout
)
t
.
delete
()
c
.
delete
()
dj
.
errors
.
_switch_filepath_types
(
False
)
dj
.
errors
.
_switch_adapted_types
(
False
)
# test spawned classes
local_schema
=
dj
.
Schema
(
adapted
.
schema_name
)
local_schema
.
spawn_missing_classes
()
def
test_adapted_spawned
():
dj
.
errors
.
_switch_adapted_types
(
True
)
c
=
Connectivity
()
# a spawned class
graphs
=
[
nx
.
lollipop_graph
(
4
,
2
),
nx
.
star_graph
(
5
),
nx
.
barbell_graph
(
3
,
1
),
nx
.
cycle_graph
(
5
)]
c
.
insert
((
i
,
g
)
for
i
,
g
in
enumerate
(
graphs
))
returned_graphs
=
c
.
fetch
(
'conn_graph'
,
order_by
=
'connid'
)
for
g1
,
g2
in
zip
(
graphs
,
returned_graphs
):
assert_true
(
isinstance
(
g2
,
nx
.
Graph
))
assert_equal
(
len
(
g1
.
edges
),
len
(
g2
.
edges
))
assert_true
(
0
==
len
(
nx
.
symmetric_difference
(
g1
,
g2
).
edges
))
c
.
delete
()
dj
.
errors
.
_switch_adapted_types
(
False
)
# test with virtual module
virtual_module
=
dj
.
VirtualModule
(
'virtual_module'
,
adapted
.
schema_name
,
add_objects
=
{
'graph'
:
graph
})
def
test_adapted_virtual
():
dj
.
errors
.
_switch_adapted_types
(
True
)
c
=
virtual_module
.
Connectivity
()
graphs
=
[
nx
.
lollipop_graph
(
4
,
2
),
nx
.
star_graph
(
5
),
nx
.
barbell_graph
(
3
,
1
),
nx
.
cycle_graph
(
5
)]
c
.
insert
((
i
,
g
)
for
i
,
g
in
enumerate
(
graphs
))
c
.
insert1
({
'connid'
:
100
})
# test work with NULLs
returned_graphs
=
c
.
fetch
(
'conn_graph'
,
order_by
=
'connid'
)
for
g1
,
g2
in
zip_longest
(
graphs
,
returned_graphs
):
if
g1
is
None
:
assert_true
(
g2
is
None
)
else
:
assert_true
(
isinstance
(
g2
,
nx
.
Graph
))
assert_equal
(
len
(
g1
.
edges
),
len
(
g2
.
edges
))
assert_true
(
0
==
len
(
nx
.
symmetric_difference
(
g1
,
g2
).
edges
))
c
.
delete
()
dj
.
errors
.
_switch_adapted_types
(
False
)
Back
|
FazBrowse Home
|
New Git URL