Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.backend.python
Commits
0666b89d
Commit
0666b89d
authored
May 10, 2019
by
Samuel GAIST
Browse files
[tests] Cleanup asserts
Use nose.tools assert everywhere
parent
cc7c1c91
Pipeline
#30086
passed with stage
in 11 minutes and 9 seconds
Changes
9
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
beat/backend/python/test/test_format_array.py
View file @
0666b89d
...
...
@@ -42,115 +42,130 @@ from ..dataformat import DataFormat
from
.
import
prefix
#----------------------------------------------------------
#
----------------------------------------------------------
def
doit
(
format
):
df
=
DataFormat
(
prefix
,
format
)
assert
df
.
valid
,
df
.
errors
nose
.
tools
.
assert_true
(
df
.
valid
,
df
.
errors
)
ftype
=
df
.
type
obj
=
ftype
()
assert
isinstance
(
obj
.
value
,
numpy
.
ndarray
)
nose
.
tools
.
eq_
(
obj
.
value
.
ndim
,
len
(
ftype
.
value
)
-
1
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value
,
numpy
.
ndarray
)
)
nose
.
tools
.
eq_
(
obj
.
value
.
ndim
,
len
(
ftype
.
value
)
-
1
)
nose
.
tools
.
eq_
(
obj
.
value
.
shape
,
tuple
(
ftype
.
value
[:
-
1
]))
if
ftype
.
value
[
-
1
]
!=
str
:
nose
.
tools
.
eq_
(
obj
.
value
.
dtype
,
ftype
.
value
[
-
1
])
else
:
assert
issubclass
(
obj
.
value
.
dtype
.
type
,
object
)
#element for strings
nose
.
tools
.
assert_true
(
issubclass
(
obj
.
value
.
dtype
.
type
,
object
)
)
# element for strings
# checks JSON enconding
copy
=
ftype
(
**
obj
.
as_dict
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
# checks binary encoding
copy
=
ftype
()
copy
.
unpack
(
obj
.
pack
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_1d_array_of_integers
():
doit
(
'
user/empty_1d_array_of_integers/1
'
)
doit
(
"
user/empty_1d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_2d_array_of_integers
():
doit
(
'
user/empty_2d_array_of_integers/1
'
)
doit
(
"
user/empty_2d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_3d_array_of_integers
():
doit
(
'
user/empty_3d_array_of_integers/1
'
)
doit
(
"
user/empty_3d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_fixed_2d_array_of_integers
():
doit
(
'
user/empty_2d_fixed_array_of_integers/1
'
)
doit
(
"
user/empty_2d_fixed_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_1d_array_of_integers
():
doit
(
'
user/1d_array_of_integers/1
'
)
doit
(
"
user/1d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_2d_array_of_integers
():
doit
(
'
user/2d_array_of_integers/1
'
)
doit
(
"
user/2d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_integers
():
doit
(
'
user/3d_array_of_integers/1
'
)
doit
(
"
user/3d_array_of_integers/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_integers_pack_unpack
():
df
=
DataFormat
(
prefix
,
'
user/3d_array_of_integers/1
'
)
assert
df
.
valid
,
df
.
errors
df
=
DataFormat
(
prefix
,
"
user/3d_array_of_integers/1
"
)
nose
.
tools
.
assert_true
(
df
.
valid
,
df
.
errors
)
ftype
=
df
.
type
obj
=
ftype
()
limits
=
numpy
.
iinfo
(
obj
.
value
.
dtype
)
obj
.
value
=
numpy
.
random
.
randint
(
low
=
limits
.
min
,
high
=
limits
.
max
,
size
=
obj
.
value
.
shape
).
astype
(
obj
.
value
.
dtype
)
obj
.
value
=
numpy
.
random
.
randint
(
low
=
limits
.
min
,
high
=
limits
.
max
,
size
=
obj
.
value
.
shape
).
astype
(
obj
.
value
.
dtype
)
# checks JSON enconding
copy
=
ftype
(
**
obj
.
as_dict
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
# checks binary encoding
copy
=
ftype
()
copy
.
unpack
(
obj
.
pack
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_floats_pack_unpack
():
df
=
DataFormat
(
prefix
,
'
user/3d_array_of_floats/1
'
)
assert
df
.
valid
,
df
.
errors
df
=
DataFormat
(
prefix
,
"
user/3d_array_of_floats/1
"
)
nose
.
tools
.
assert_true
(
df
.
valid
,
df
.
errors
)
ftype
=
df
.
type
obj
=
ftype
()
...
...
@@ -158,21 +173,27 @@ def test_3d_array_of_floats_pack_unpack():
# checks JSON enconding
copy
=
ftype
(
**
obj
.
as_dict
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
# checks binary encoding
copy
=
ftype
()
copy
.
unpack
(
obj
.
pack
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_complexes_pack_unpack
():
df
=
DataFormat
(
prefix
,
'
user/3d_array_of_complexes/1
'
)
assert
df
.
valid
,
df
.
errors
df
=
DataFormat
(
prefix
,
"
user/3d_array_of_complexes/1
"
)
nose
.
tools
.
assert_true
(
df
.
valid
,
df
.
errors
)
ftype
=
df
.
type
obj
=
ftype
()
...
...
@@ -181,128 +202,134 @@ def test_3d_array_of_complexes_pack_unpack():
# checks JSON enconding
copy
=
ftype
(
**
obj
.
as_dict
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
# checks binary encoding
copy
=
ftype
()
copy
.
unpack
(
obj
.
pack
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_1d_array_of_objects
():
doit
(
'
user/empty_1d_array_of_objects/1
'
)
doit
(
"
user/empty_1d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_2d_array_of_objects
():
doit
(
'
user/empty_2d_array_of_objects/1
'
)
doit
(
"
user/empty_2d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_3d_array_of_objects
():
doit
(
'
user/empty_3d_array_of_objects/1
'
)
doit
(
"
user/empty_3d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_fixed_2d_array_of_objects
():
doit
(
'
user/empty_2d_fixed_array_of_objects/1
'
)
doit
(
"
user/empty_2d_fixed_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_1d_array_of_objects
():
doit
(
'
user/1d_array_of_objects/1
'
)
doit
(
"
user/1d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_2d_array_of_objects
():
doit
(
'
user/2d_array_of_objects/1
'
)
doit
(
"
user/2d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_objects
():
doit
(
'
user/3d_array_of_objects/1
'
)
doit
(
"
user/3d_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_1d_array_of_external_reference
():
doit
(
'
user/empty_1d_array_of_dataformat/1
'
)
doit
(
"
user/empty_1d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_2d_array_of_external_reference
():
doit
(
'
user/empty_2d_array_of_dataformat/1
'
)
doit
(
"
user/empty_2d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_3d_array_of_external_reference
():
doit
(
'
user/empty_3d_array_of_dataformat/1
'
)
doit
(
"
user/empty_3d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_fixed_2d_array_of_external_reference
():
doit
(
'
user/empty_2d_fixed_array_of_dataformat/1
'
)
doit
(
"
user/empty_2d_fixed_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_1d_array_of_external_reference
():
doit
(
'
user/1d_array_of_dataformat/1
'
)
doit
(
"
user/1d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_2d_array_of_external_reference
():
doit
(
'
user/2d_array_of_dataformat/1
'
)
doit
(
"
user/2d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_3d_array_of_external_reference
():
doit
(
'
user/3d_array_of_dataformat/1
'
)
doit
(
"
user/3d_array_of_dataformat/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_1d_array_of_external_reference_with_empty_array_of_objects
():
doit
(
'
user/empty_1d_array_of_dataformat_with_empty_array_of_objects/1
'
)
doit
(
"
user/empty_1d_array_of_dataformat_with_empty_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_empty_1d_array_of_external_reference_with_array_of_objects
():
doit
(
'
user/empty_1d_array_of_dataformat_with_array_of_objects/1
'
)
doit
(
"
user/empty_1d_array_of_dataformat_with_array_of_objects/1
"
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_1d_array_of_strings
():
doit
(
'
user/1d_array_of_strings/1
'
)
doit
(
"
user/1d_array_of_strings/1
"
)
beat/backend/python/test/test_format_extends.py
View file @
0666b89d
...
...
@@ -42,13 +42,13 @@ from ..dataformat import DataFormat
from
.
import
prefix
#----------------------------------------------------------
#
----------------------------------------------------------
def
doit
(
format
):
df
=
DataFormat
(
prefix
,
format
)
assert
df
.
valid
,
'
\n
* %s
'
%
'
\n
*
'
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
ftype
=
df
.
type
obj
=
ftype
()
...
...
@@ -56,55 +56,61 @@ def doit(format):
# checks JSON enconding
copy
=
ftype
()
copy
.
from_dict
(
obj
.
as_dict
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
# checks binary encoding
copy
=
ftype
()
copy
.
unpack
(
obj
.
pack
())
assert
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
())
nose
.
tools
.
assert_true
(
copy
.
isclose
(
obj
),
"%r is not close enough to %r"
%
(
copy
.
as_dict
(),
obj
.
as_dict
()),
)
return
obj
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_valid
():
obj
=
doit
(
'
user/extended/1
'
)
obj
=
doit
(
"
user/extended/1
"
)
assert
hasattr
(
obj
,
'
value
'
)
assert
isinstance
(
obj
.
value
,
numpy
.
int32
)
assert
hasattr
(
obj
,
'
value2
'
)
assert
isinstance
(
obj
.
value2
,
numpy
.
bool_
)
nose
.
tools
.
assert_true
(
hasattr
(
obj
,
"
value
"
)
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value
,
numpy
.
int32
)
)
nose
.
tools
.
assert_true
(
hasattr
(
obj
,
"
value2
"
)
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value2
,
numpy
.
bool_
)
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_extension_of_extended
():
obj
=
doit
(
'
user/extended2/1
'
)
obj
=
doit
(
"
user/extended2/1
"
)
assert
hasattr
(
obj
,
'
value
'
)
assert
isinstance
(
obj
.
value
,
numpy
.
int32
)
assert
hasattr
(
obj
,
'
value2
'
)
assert
isinstance
(
obj
.
value2
,
numpy
.
bool_
)
assert
hasattr
(
obj
,
'
value3
'
)
assert
isinstance
(
obj
.
value3
,
numpy
.
float32
)
nose
.
tools
.
assert_true
(
hasattr
(
obj
,
"
value
"
)
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value
,
numpy
.
int32
)
)
nose
.
tools
.
assert_true
(
hasattr
(
obj
,
"
value2
"
)
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value2
,
numpy
.
bool_
)
)
nose
.
tools
.
assert_true
(
hasattr
(
obj
,
"
value3
"
)
)
nose
.
tools
.
assert_true
(
isinstance
(
obj
.
value3
,
numpy
.
float32
)
)
#----------------------------------------------------------
#
----------------------------------------------------------
def
test_issubclass
():
first
=
DataFormat
(
prefix
,
'
user/single_integer/1
'
)
assert
first
.
valid
,
'
\n
* %s
'
%
'
\n
*
'
.
join
(
first
.
errors
)
first
=
DataFormat
(
prefix
,
"
user/single_integer/1
"
)
nose
.
tools
.
assert_true
(
first
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
first
.
errors
)
)
middle
=
DataFormat
(
prefix
,
'
user/extended/1
'
)
assert
middle
.
valid
,
'
\n
* %s
'
%
'
\n
*
'
.
join
(
middle
.
errors
)
middle
=
DataFormat
(
prefix
,
"
user/extended/1
"
)
nose
.
tools
.
assert_true
(
middle
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
middle
.
errors
)
)
last
=
DataFormat
(
prefix
,
'
user/extended2/1
'
)
assert
last
.
valid
,
'
\n
* %s
'
%
'
\n
*
'
.
join
(
last
.
errors
)
last
=
DataFormat
(
prefix
,
"
user/extended2/1
"
)
nose
.
tools
.
assert_true
(
last
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
last
.
errors
)
)
assert
first
.
isparent
(
middle
)
assert
middle
.
isparent
(
last
)
assert
first
.
isparent
(
last
)
#two hops
nose
.
tools
.
assert_true
(
first
.
isparent
(
middle
)
)
nose
.
tools
.
assert_true
(
middle
.
isparent
(
last
)
)
nose
.
tools
.
assert_true
(
first
.
isparent
(
last
)
)
#
two hops
beat/backend/python/test/test_format_missing_attributes.py
View file @
0666b89d
...
...
@@ -41,228 +41,228 @@ from ..dataformat import DataFormat
from
.
import
prefix
#----------------------------------------------------------
#
----------------------------------------------------------
def
doit
(
format
,
data
):
df
=
DataFormat
(
prefix
,
format
)
assert
df
.
valid
nose
.
tools
.
assert_true
(
df
.
valid
,
df
.
errors
)
obj
=
df
.
type
()
obj
.
from_dict
(
data
,
casting
=
'
unsafe
'
,
add_defaults
=
False
)
obj
.
from_dict
(
data
,
casting
=
"
unsafe
"
,
add_defaults
=
False
)
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_integer
():
doit
(
'
user/single_integer/1
'
,
{})
doit
(
"
user/single_integer/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_float
():
doit
(
'
user/single_float/1
'
,
{})
doit
(
"
user/single_float/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_boolean
():
doit
(
'
user/single_boolean/1
'
,
{})
doit
(
"
user/single_boolean/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_string
():
doit
(
'
user/single_string/1
'
,
{})
doit
(
"
user/single_string/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_object
():
doit
(
'
user/single_object/1
'
,
{})
doit
(
"
user/single_object/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_single_object_field
():
doit
(
'
user/single_object/1
'
,
dict
(
obj
=
{}))
doit
(
"
user/single_object/1
"
,
dict
(
obj
=
{}))
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_hierarchy_of_objects
():
doit
(
'
user/hierarchy_of_objects/1
'
,
dict
(
obj1
=
dict
(
obj2
=
{})))
doit
(
"
user/hierarchy_of_objects/1
"
,
dict
(
obj1
=
dict
(
obj2
=
{})))
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_hierarchy_of_objects_field
():
doit
(
'
user/hierarchy_of_objects/1
'
,
dict
(
obj1
=
dict
(
obj2
=
dict
(
obj3
=
{}))))
doit
(
"
user/hierarchy_of_objects/1
"
,
dict
(
obj1
=
dict
(
obj2
=
dict
(
obj3
=
{}))))
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_empty_1d_array_of_integers
():
doit
(
'
user/empty_1d_array_of_integers/1
'
,
{})
doit
(
"
user/empty_1d_array_of_integers/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)
def
test_empty_2d_array_of_integers
():
doit
(
'
user/empty_2d_array_of_integers/1
'
,
{})
doit
(
"
user/empty_2d_array_of_integers/1
"
,
{})
#----------------------------------------------------------
#
----------------------------------------------------------
@
nose
.
tools
.
raises
(
AttributeError
)