FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
datajoint-python/tests/test_relation_u.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_relation_u.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (73 loc) · 3.46 KB
Breadcrumbs
datajoint-python
/
tests
/
test_relation_u.py
Copy path
File metadata and controls
86 lines (73 loc) · 3.46 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
85
86
from
nose
.
tools
import
assert_equal
,
assert_true
,
raises
,
assert_list_equal
from
.
import
schema
,
schema_simple
import
datajoint
as
dj
class
TestU
:
"""
Test tables: insert, delete
"""
@
classmethod
def
setup_class
(
cls
):
cls
.
user
=
schema
.
User
()
cls
.
language
=
schema
.
Language
()
cls
.
subject
=
schema
.
Subject
()
cls
.
experiment
=
schema
.
Experiment
()
cls
.
trial
=
schema
.
Trial
()
cls
.
ephys
=
schema
.
Ephys
()
cls
.
channel
=
schema
.
Ephys
.
Channel
()
cls
.
img
=
schema
.
Image
()
cls
.
trash
=
schema
.
UberTrash
()
def
test_restriction
(
self
):
language_set
=
{
s
[
1
]
for
s
in
self
.
language
.
contents
}
rel
=
dj
.
U
(
'language'
)
&
self
.
language
assert_list_equal
(
rel
.
heading
.
names
, [
'language'
])
assert_true
(
len
(
rel
)
==
len
(
language_set
))
assert_true
(
set
(
rel
.
fetch
(
'language'
))
==
language_set
)
# Test for issue #342
rel
=
self
.
trial
*
dj
.
U
(
'start_time'
)
assert_list_equal
(
rel
.
primary_key
,
self
.
trial
.
primary_key
+
[
'start_time'
])
assert_list_equal
(
rel
.
primary_key
, (
rel
&
'trial_id>3'
).
primary_key
)
assert_list_equal
((
dj
.
U
(
'start_time'
)
&
self
.
trial
).
primary_key
, [
'start_time'
])
@
staticmethod
@
raises
(
dj
.
DataJointError
)
def
test_invalid_restriction
():
result
=
dj
.
U
(
'color'
)
&
dict
(
color
=
"red"
)
def
test_ineffective_restriction
(
self
):
rel
=
self
.
language
&
dj
.
U
(
'language'
)
assert_true
(
rel
.
make_sql
()
==
self
.
language
.
make_sql
())
def
test_join
(
self
):
rel
=
self
.
experiment
*
dj
.
U
(
'experiment_date'
)
assert_equal
(
self
.
experiment
.
primary_key
, [
'subject_id'
,
'experiment_id'
])
assert_equal
(
rel
.
primary_key
,
self
.
experiment
.
primary_key
+
[
'experiment_date'
])
rel
=
dj
.
U
(
'experiment_date'
)
*
self
.
experiment
assert_equal
(
self
.
experiment
.
primary_key
, [
'subject_id'
,
'experiment_id'
])
assert_equal
(
rel
.
primary_key
,
self
.
experiment
.
primary_key
+
[
'experiment_date'
])
@
staticmethod
@
raises
(
dj
.
DataJointError
)
def
test_invalid_join
():
rel
=
dj
.
U
(
'language'
)
*
dict
(
language
=
"English"
)
def
test_repr_without_attrs
(
self
):
"""test dj.U() display"""
query
=
dj
.
U
().
aggr
(
schema
.
Language
,
n
=
'count(*)'
)
repr
(
query
)
def
test_aggregations
(
self
):
lang
=
schema
.
Language
()
# test total aggregation on expression object
n1
=
dj
.
U
().
aggr
(
lang
,
n
=
'count(*)'
).
fetch1
(
'n'
)
assert_equal
(
n1
,
len
(
lang
.
fetch
()))
# test total aggregation on expression class
n2
=
dj
.
U
().
aggr
(
schema
.
Language
,
n
=
'count(*)'
).
fetch1
(
'n'
)
assert_equal
(
n1
,
n2
)
rel
=
dj
.
U
(
'language'
).
aggr
(
schema
.
Language
,
number_of_speakers
=
'count(*)'
)
assert_equal
(
len
(
rel
),
len
(
set
(
l
[
1
]
for
l
in
schema
.
Language
.
contents
)))
assert_equal
((
rel
&
'language="English"'
).
fetch1
(
'number_of_speakers'
),
3
)
def
test_argmax
(
self
):
rel
=
schema
.
TTest
()
# get the tuples corresponding to maximum value
mx
=
(
rel
*
dj
.
U
().
aggr
(
rel
,
mx
=
'max(value)'
))
&
'mx=value'
assert_equal
(
mx
.
fetch
(
'value'
)[
0
],
max
(
rel
.
fetch
(
'value'
)))
def
test_aggr
(
self
):
rel
=
schema_simple
.
ArgmaxTest
()
amax1
=
(
dj
.
U
(
'val'
)
*
rel
)
&
dj
.
U
(
'secondary_key'
).
aggr
(
rel
,
val
=
'min(val)'
)
amax2
=
(
dj
.
U
(
'val'
)
*
rel
)
*
dj
.
U
(
'secondary_key'
).
aggr
(
rel
,
val
=
'min(val)'
)
assert_true
(
len
(
amax1
)
==
len
(
amax2
)
==
rel
.
n
,
'Aggregated argmax with join and restriction does not yield same length.'
)
Back
|
FazBrowse Home
|
New Git URL