Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
399a383e
Commit
399a383e
authored
3 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
added test for test_nested_equality, /close
#345
parent
af312db7
No related branches found
No related tags found
3 merge requests
!413
update release branch
,
!412
Resolve "release v2.0.0"
,
!370
Resolve "store transformation locally as file"
Pipeline
#85764
passed
3 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlair/helpers/testing.py
+4
-1
4 additions, 1 deletion
mlair/helpers/testing.py
test/test_helpers/test_testing_helpers.py
+33
-1
33 additions, 1 deletion
test/test_helpers/test_testing_helpers.py
with
37 additions
and
2 deletions
mlair/helpers/testing.py
+
4
−
1
View file @
399a383e
...
@@ -96,7 +96,7 @@ def test_nested_equality(obj1, obj2):
...
@@ -96,7 +96,7 @@ def test_nested_equality(obj1, obj2):
if
isinstance
(
obj1
,
(
tuple
,
list
)):
if
isinstance
(
obj1
,
(
tuple
,
list
)):
print
(
f
"
check length
{
len
(
obj1
)
}
and
{
len
(
obj2
)
}
"
)
print
(
f
"
check length
{
len
(
obj1
)
}
and
{
len
(
obj2
)
}
"
)
assert
len
(
obj1
)
==
len
(
obj
1
)
assert
len
(
obj1
)
==
len
(
obj
2
)
for
pos
in
range
(
len
(
obj1
)):
for
pos
in
range
(
len
(
obj1
)):
print
(
f
"
check pos
{
obj1
[
pos
]
}
and
{
obj2
[
pos
]
}
"
)
print
(
f
"
check pos
{
obj1
[
pos
]
}
and
{
obj2
[
pos
]
}
"
)
assert
test_nested_equality
(
obj1
[
pos
],
obj2
[
pos
])
is
True
assert
test_nested_equality
(
obj1
[
pos
],
obj2
[
pos
])
is
True
...
@@ -109,6 +109,9 @@ def test_nested_equality(obj1, obj2):
...
@@ -109,6 +109,9 @@ def test_nested_equality(obj1, obj2):
elif
isinstance
(
obj1
,
xr
.
DataArray
):
elif
isinstance
(
obj1
,
xr
.
DataArray
):
print
(
f
"
check xr
{
obj1
}
and
{
obj2
}
"
)
print
(
f
"
check xr
{
obj1
}
and
{
obj2
}
"
)
assert
xr
.
testing
.
assert_equal
(
obj1
,
obj2
)
is
None
assert
xr
.
testing
.
assert_equal
(
obj1
,
obj2
)
is
None
elif
isinstance
(
obj1
,
np
.
ndarray
):
print
(
f
"
check np
{
obj1
}
and
{
obj2
}
"
)
assert
np
.
testing
.
assert_array_equal
(
obj1
,
obj2
)
is
None
else
:
else
:
print
(
f
"
check equal
{
obj1
}
and
{
obj2
}
"
)
print
(
f
"
check equal
{
obj1
}
and
{
obj2
}
"
)
assert
obj1
==
obj2
assert
obj1
==
obj2
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers/test_testing_helpers.py
+
33
−
1
View file @
399a383e
from
mlair.helpers.testing
import
PyTestRegex
,
PyTestAllEqual
from
mlair.helpers.testing
import
PyTestRegex
,
PyTestAllEqual
,
test_nested_equality
import
re
import
re
import
xarray
as
xr
import
xarray
as
xr
...
@@ -46,3 +46,35 @@ class TestPyTestAllEqual:
...
@@ -46,3 +46,35 @@ class TestPyTestAllEqual:
[
xr
.
DataArray
([
1
,
2
,
3
]),
xr
.
DataArray
([
12
,
22
,
32
])]])
[
xr
.
DataArray
([
1
,
2
,
3
]),
xr
.
DataArray
([
12
,
22
,
32
])]])
assert
PyTestAllEqual
([[
"
test
"
,
"
test2
"
],
assert
PyTestAllEqual
([[
"
test
"
,
"
test2
"
],
[
"
test
"
,
"
test2
"
]])
[
"
test
"
,
"
test2
"
]])
class
TestNestedEquality
:
def
test_nested_equality_single_entries
(
self
):
assert
test_nested_equality
(
3
,
3
)
is
True
assert
test_nested_equality
(
3.9
,
3.9
)
is
True
assert
test_nested_equality
(
3.91
,
3.9
)
is
False
assert
test_nested_equality
(
"
3
"
,
3
)
is
False
assert
test_nested_equality
(
"
3
"
,
"
3
"
)
is
True
assert
test_nested_equality
(
None
,
None
)
is
True
def
test_nested_equality_xarray
(
self
):
obj1
=
xr
.
DataArray
(
np
.
random
.
randn
(
2
,
3
),
dims
=
(
'
x
'
,
'
y
'
),
coords
=
{
'
x
'
:
[
10
,
20
],
'
y
'
:
[
0
,
10
,
20
]})
obj2
=
xr
.
ones_like
(
obj1
)
*
obj1
assert
test_nested_equality
(
obj1
,
obj2
)
is
True
def
test_nested_equality_numpy
(
self
):
obj1
=
np
.
random
.
randn
(
2
,
3
)
obj2
=
obj1
*
1
assert
test_nested_equality
(
obj1
,
obj2
)
is
True
def
test_nested_equality_list_tuple
(
self
):
assert
test_nested_equality
([
3
,
3
],
[
3
,
3
])
is
True
assert
test_nested_equality
((
2
,
6
),
(
2
,
6
))
is
True
assert
test_nested_equality
([
3
,
3.5
],
[
3.5
,
3
])
is
False
assert
test_nested_equality
([
3
,
3.5
,
10
],
[
3
,
3.5
])
is
False
def
test_nested_equality_dict
(
self
):
assert
test_nested_equality
({
"
a
"
:
3
,
"
b
"
:
10
},
{
"
b
"
:
10
,
"
a
"
:
3
})
is
True
assert
test_nested_equality
({
"
a
"
:
3
,
"
b
"
:
[
10
,
100
]},
{
"
b
"
:
[
10
,
100
],
"
a
"
:
3
})
is
True
assert
test_nested_equality
({
"
a
"
:
3
,
"
b
"
:
10
,
"
c
"
:
"
c
"
},
{
"
b
"
:
10
,
"
a
"
:
3
})
is
False
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