Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dios
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RDM
dios
Commits
55d530e4
Commit
55d530e4
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
structured tests
parent
9cc3a151
No related branches found
No related tags found
1 merge request
!2
Develop
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
test/test_magic_methods.py
+17
-0
17 additions, 0 deletions
test/test_magic_methods.py
test/test_methods.py
+40
-0
40 additions, 0 deletions
test/test_methods.py
test/test_ops.py
+69
-0
69 additions, 0 deletions
test/test_ops.py
test/test_setup.py
+57
-0
57 additions, 0 deletions
test/test_setup.py
with
183 additions
and
0 deletions
test/test_magic_methods.py
0 → 100644
+
17
−
0
View file @
55d530e4
from
test.test_setup
import
*
def
test__len__
(
datetime_series
,
maxlen
=
10
):
dios
=
DictOfSeries
()
assert
len
(
dios
)
==
0
for
i
in
range
(
maxlen
):
dios
[
f
'
c
{
i
}
'
]
=
datetime_series
.
copy
()
assert
len
(
dios
)
==
i
+
1
for
i
in
reversed
(
range
(
maxlen
)):
assert
len
(
dios
)
==
i
+
1
del
dios
[
f
'
c
{
i
}
'
]
assert
len
(
dios
)
==
0
This diff is collapsed.
Click to expand it.
test/test_methods.py
0 → 100644
+
40
−
0
View file @
55d530e4
from
test.test_setup
import
*
def
test_copy_copy_empty
(
getDtDiosAligned
):
dios
=
getDtDiosAligned
.
copy
()
shallow
=
dios
.
copy
(
deep
=
False
)
deep
=
dios
.
copy
(
deep
=
True
)
empty
=
dios
.
copy_empty
()
assert
dios
is
not
shallow
assert
dios
is
not
deep
assert
dios
is
not
empty
assert
dios
.
itype
==
shallow
.
itype
assert
dios
.
itype
==
deep
.
itype
assert
dios
.
itype
==
empty
.
itype
for
i
in
dios
:
assert
dios
[
i
].
index
is
shallow
[
i
].
index
assert
dios
[
i
].
index
is
not
deep
[
i
].
index
dios
[
i
][
0
]
=
999999
assert
dios
[
i
][
0
]
==
shallow
[
i
][
0
]
assert
dios
[
i
][
0
]
!=
deep
[
i
][
0
]
@pytest.mark.parametrize
(
'
left
'
,
diosFromMatr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
op
'
,
OPCOMP
)
def
test_all
(
left
,
op
):
# we use comp ops just to get some noise in the data
a
=
left
ser
=
(
op
(
a
,
a
)).
all
()
assert
isinstance
(
ser
,
pd
.
Series
)
res
=
[
e
for
e
in
ser
]
exp
=
[
op
(
a
[
col
],
a
[
col
])
for
col
in
a
]
for
i
in
range
(
len
(
res
)):
assert
isinstance
(
exp
[
i
],
pd
.
Series
)
assert
(
res
[
i
]
==
exp
[
i
]).
all
()
This diff is collapsed.
Click to expand it.
test/test_
di
os.py
→
test/test_o
p
s.py
+
69
−
0
View file @
55d530e4
#!/usr/bin/env python
import
pytest
from
dios
import
*
from
dios.lib
import
_OP1_MAP
,
_OP2_DIV_MAP
,
_OP2_ARITH_MAP
,
_OP2_BOOL_MAP
,
_OP2_COMP_MAP
from
test.test_setup
import
*
import
pandas
as
pd
import
numpy
as
np
from
copy
import
deepcopy
from
pandas.tests.series.conftest
import
datetime_series
__author__
=
"
Bert Palm
"
__email__
=
"
bert.palm@ufz.de
"
__copyright__
=
"
Copyright 2018, Helmholtz-Centrum für Umweltforschung GmbH - UFC
"
def
get_dios
(
ser
,
i
):
dios
=
DictOfSeries
()
for
i
in
range
(
i
):
dios
[
f
'
c
{
i
}
'
]
=
ser
.
copy
()
*
(
i
+
1
)
//
2
return
dios
O
=
[[
0
,
0
,
0
],
[
0
,
0
,
0
]]
I
=
[[
1
,
1
,
1
],
[
1
,
1
,
1
]]
A
=
[[
1
,
2
,
3
],
[
4
,
5
,
6
]]
B
=
[[
0
,
2
,
2
],
[
5
,
5
,
5
]]
C
=
[[
3
,
2
,
0
],
[
1
,
0
,
3
]]
D
=
[[
6
,
5
,
4
],
[
3
,
2
,
1
]]
DATA_ALIGNED
=
[
O
,
I
,
A
,
B
,
C
,
D
]
# outer lists could have differnet length, but this would
# make the checks to complicated
EEE
=
[[],
[],
[]]
O
=
[[
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
,
0
]]
I
=
[[
1
,
1
,
1
],
[
1
,
1
,
1
],
[
1
]]
A
=
[[
1
],
[
2
,
3
],
[
4
,
5
,
6
]]
B
=
[[
0
,
2
,
2
],
[
5
],
[
5
,
5
]]
C
=
[[
3
,
2
,
0
],
[
1
,
0
,
3
],
[
0
,
0
,
0
]]
D
=
[[
6
],
[
2
],
[
9
]]
DATA_UNALIGNED
=
[
O
,
I
,
A
,
B
,
C
,
D
,
EEE
]
# only use if a single matrix is used
ALL
=
DATA_ALIGNED
+
DATA_UNALIGNED
OPCOMP
=
list
(
_OP2_COMP_MAP
)
OPNOCOMP
=
list
(
_OP2_ARITH_MAP
)
+
list
(
_OP2_BOOL_MAP
)
+
list
(
_OP2_DIV_MAP
)
OP2
=
OPCOMP
+
OPNOCOMP
OP1
=
list
(
_OP1_MAP
)
def
_diosmatr
(
mlist
):
l
=
[]
for
m
in
mlist
:
m
=
np
.
array
(
m
)
l
.
append
(
DictOfSeries
(
m
.
copy
()))
return
tuple
(
l
)
@pytest.fixture
()
def
dictofseries
(
datetime_series
):
return
get_dios
(
datetime_series
,
5
)
def
test_len__len__
(
datetime_series
,
maxlen
=
10
):
dios
=
DictOfSeries
()
assert
len
(
dios
)
==
0
for
i
in
range
(
maxlen
):
dios
[
f
'
c
{
i
}
'
]
=
datetime_series
.
copy
()
assert
len
(
dios
)
==
i
+
1
for
i
in
reversed
(
range
(
maxlen
)):
assert
len
(
dios
)
==
i
+
1
del
dios
[
f
'
c
{
i
}
'
]
assert
len
(
dios
)
==
0
def
test_copy_copy_empty__copy__
(
dictofseries
):
dios
=
dictofseries
.
copy
()
shallow
=
dios
.
copy
(
deep
=
False
)
deep
=
dios
.
copy
(
deep
=
True
)
empty
=
dios
.
copy_empty
()
assert
dios
is
not
shallow
assert
dios
is
not
deep
assert
dios
is
not
empty
assert
dios
.
itype
==
shallow
.
itype
assert
dios
.
itype
==
deep
.
itype
assert
dios
.
itype
==
empty
.
itype
for
i
in
dios
:
assert
dios
[
i
].
index
is
shallow
[
i
].
index
assert
dios
[
i
].
index
is
not
deep
[
i
].
index
dios
[
i
][
0
]
=
999999
assert
dios
[
i
][
0
]
==
shallow
[
i
][
0
]
assert
dios
[
i
][
0
]
!=
deep
[
i
][
0
]
@pytest.mark.parametrize
(
'
left
'
,
_diosmatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
_diosmatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
left
'
,
diosFromMatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
diosFromMatr
(
DATA_ALIGNED
))
def
test__eq__
(
left
,
right
):
a
,
b
=
left
,
right
_test
=
a
==
b
...
...
@@ -112,22 +21,8 @@ def test__eq__(left, right):
assert
res
==
exp
@pytest.mark.parametrize
(
'
left
'
,
_diosmatr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
op
'
,
OPCOMP
)
def
test_all
(
left
,
op
):
# we use comp ops just to get some noise in the data
a
=
left
ser
=
(
op
(
a
,
a
)).
all
()
assert
isinstance
(
ser
,
pd
.
Series
)
res
=
[
e
for
e
in
ser
]
exp
=
[
op
(
a
[
col
],
a
[
col
])
for
col
in
a
]
for
i
in
range
(
len
(
res
)):
assert
isinstance
(
exp
[
i
],
pd
.
Series
)
assert
(
res
[
i
]
==
exp
[
i
]).
all
()
@pytest.mark.parametrize
(
'
left
'
,
_diosmatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
_diosmatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
left
'
,
diosFromMatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
diosFromMatr
(
DATA_ALIGNED
))
@pytest.mark.parametrize
(
'
op
'
,
OP2
)
def
test__op2__aligningops
(
left
,
right
,
op
):
a
,
b
=
left
,
right
...
...
@@ -143,8 +38,8 @@ def test__op2__aligningops(left, right, op):
assert
res
==
exp
@pytest.mark.parametrize
(
'
left
'
,
_
dios
m
atr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
_
dios
m
atr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
left
'
,
dios
FromM
atr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
right
'
,
dios
FromM
atr
(
DATA_UNALIGNED
))
@pytest.mark.parametrize
(
'
op
'
,
OPNOCOMP
)
def
test__op2__UNaligningops
(
left
,
right
,
op
):
try
:
...
...
@@ -163,7 +58,7 @@ def test__op2__UNaligningops(left, right, op):
pytest
.
skip
(
'
ZeroDivisionError
'
)
@pytest.mark.parametrize
(
'
data
'
,
_
dios
m
atr
(
ALL
))
@pytest.mark.parametrize
(
'
data
'
,
dios
FromM
atr
(
ALL
))
@pytest.mark.parametrize
(
'
op
'
,
OP1
)
def
test__op1__
(
data
,
op
):
test
=
op
(
data
)
...
...
This diff is collapsed.
Click to expand it.
test/test_setup.py
0 → 100644
+
57
−
0
View file @
55d530e4
import
pytest
from
dios
import
*
from
dios.lib
import
_OP1_MAP
,
_OP2_DIV_MAP
,
_OP2_ARITH_MAP
,
_OP2_BOOL_MAP
,
_OP2_COMP_MAP
import
pandas
as
pd
import
numpy
as
np
from
copy
import
deepcopy
from
pandas.tests.series.conftest
import
datetime_series
O
=
[[
0
,
0
,
0
],
[
0
,
0
,
0
]]
I
=
[[
1
,
1
,
1
],
[
1
,
1
,
1
]]
A
=
[[
1
,
2
,
3
],
[
4
,
5
,
6
]]
B
=
[[
0
,
2
,
2
],
[
5
,
5
,
5
]]
C
=
[[
3
,
2
,
0
],
[
1
,
0
,
3
]]
D
=
[[
6
,
5
,
4
],
[
3
,
2
,
1
]]
DATA_ALIGNED
=
[
O
,
I
,
A
,
B
,
C
,
D
]
# outer lists could have differnet length, but this would
# make the checks to complicated
EEE
=
[[],
[],
[]]
O
=
[[
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
,
0
]]
I
=
[[
1
,
1
,
1
],
[
1
,
1
,
1
],
[
1
]]
A
=
[[
1
],
[
2
,
3
],
[
4
,
5
,
6
]]
B
=
[[
0
,
2
,
2
],
[
5
],
[
5
,
5
]]
C
=
[[
3
,
2
,
0
],
[
1
,
0
,
3
],
[
0
,
0
,
0
]]
D
=
[[
6
],
[
2
],
[
9
]]
DATA_UNALIGNED
=
[
O
,
I
,
A
,
B
,
C
,
D
,
EEE
]
# only use if a single matrix is used
ALL
=
DATA_ALIGNED
+
DATA_UNALIGNED
OPCOMP
=
list
(
_OP2_COMP_MAP
)
OPNOCOMP
=
list
(
_OP2_ARITH_MAP
)
+
list
(
_OP2_BOOL_MAP
)
+
list
(
_OP2_DIV_MAP
)
OP2
=
OPCOMP
+
OPNOCOMP
OP1
=
list
(
_OP1_MAP
)
def
diosFromMatr
(
mlist
):
l
=
[]
for
m
in
mlist
:
m
=
np
.
array
(
m
)
l
.
append
(
DictOfSeries
(
m
.
copy
()))
return
tuple
(
l
)
def
_get_dios
(
ser
,
i
):
dios
=
DictOfSeries
()
for
i
in
range
(
i
):
dios
[
f
'
c
{
i
}
'
]
=
ser
.
copy
()
*
(
i
+
1
)
//
2
return
dios
@pytest.fixture
()
def
getDtDiosAligned
(
datetime_series
):
return
_get_dios
(
datetime_series
,
5
)
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