Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
beat
beat.core
Commits
66f07e52
Commit
66f07e52
authored
6 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[test][test_format_load] Code cleanup
parent
3c358e74
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!62
Code cleanup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/core/test/test_format_load.py
+42
-40
42 additions, 40 deletions
beat/core/test/test_format_load.py
with
42 additions
and
40 deletions
beat/core/test/test_format_load.py
+
42
−
40
View file @
66f07e52
...
@@ -34,8 +34,6 @@
...
@@ -34,8 +34,6 @@
###################################################################################
###################################################################################
import
os
import
six
import
six
import
numpy
import
numpy
import
nose.tools
import
nose.tools
...
@@ -49,31 +47,31 @@ from .utils import cleanup
...
@@ -49,31 +47,31 @@ from .utils import cleanup
def
test_load_default_format
():
def
test_load_default_format
():
df
=
DataFormat
(
prefix
,
data
=
None
)
df
=
DataFormat
(
prefix
,
data
=
None
)
assert
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
def
test_load_unknown_format
():
def
test_load_unknown_format
():
df
=
DataFormat
(
prefix
,
"
user/unknown/1
"
)
df
=
DataFormat
(
prefix
,
"
user/unknown/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
assert
df
.
errors
nose
.
tools
.
assert_true
(
df
.
errors
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
assert
df
.
errors
[
0
].
find
(
"
file not found
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
file not found
"
)
,
-
1
)
def
test_load_invalid_format
():
def
test_load_invalid_format
():
df
=
DataFormat
(
prefix
,
"
user/invalid/1
"
)
df
=
DataFormat
(
prefix
,
"
user/invalid/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
assert
df
.
errors
nose
.
tools
.
assert_true
(
df
.
errors
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
assert
df
.
errors
[
0
].
find
(
"
invalid JSON code
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
invalid JSON code
"
)
,
-
1
)
def
test_load_valid_format
():
def
test_load_valid_format
():
df
=
DataFormat
(
prefix
,
"
user/single_integer/1
"
)
df
=
DataFormat
(
prefix
,
"
user/single_integer/1
"
)
assert
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
0
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
0
)
...
@@ -81,88 +79,92 @@ def test_load_valid_format():
...
@@ -81,88 +79,92 @@ def test_load_valid_format():
def
test_fail_to_create_data_of_unknown_format
():
def
test_fail_to_create_data_of_unknown_format
():
df
=
DataFormat
(
prefix
,
"
user/unknown/1
"
)
df
=
DataFormat
(
prefix
,
"
user/unknown/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
assert
df
.
type
nose
.
tools
.
assert_true
(
df
.
type
)
def
test_fail_to_load_format_with_several_invalid_types
():
def
test_fail_to_load_format_with_several_invalid_types
():
df
=
DataFormat
(
prefix
,
"
user/errors/1
"
)
df
=
DataFormat
(
prefix
,
"
user/errors/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
assert
df
.
errors
[
0
].
find
(
"
is not valid under any of the given schemas
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
is not valid under any of the given schemas
"
),
-
1
)
def
test_load_valid_format_from_JSON_declaration
():
def
test_load_valid_format_from_JSON_declaration
():
df
=
DataFormat
(
prefix
,
dict
(
value
=
"
int32
"
))
df
=
DataFormat
(
prefix
,
dict
(
value
=
"
int32
"
))
assert
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
assert
df
.
name
==
"
__unnamed_dataformat__
"
nose
.
tools
.
eq_
(
df
.
name
,
"
__unnamed_dataformat__
"
)
def
test_load_versioned_format
():
def
test_load_versioned_format
():
df1
=
DataFormat
(
prefix
,
"
user/versioned/1
"
)
df1
=
DataFormat
(
prefix
,
"
user/versioned/1
"
)
assert
df1
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df1
.
errors
)
nose
.
tools
.
assert_true
(
df1
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df1
.
errors
)
)
nose
.
tools
.
eq_
(
df1
.
name
,
"
user/versioned/1
"
)
nose
.
tools
.
eq_
(
df1
.
name
,
"
user/versioned/1
"
)
df2
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
df2
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
assert
df2
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df2
.
errors
)
nose
.
tools
.
assert_true
(
df2
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df2
.
errors
)
)
nose
.
tools
.
eq_
(
df2
.
name
,
"
user/versioned/2
"
)
nose
.
tools
.
eq_
(
df2
.
name
,
"
user/versioned/2
"
)
ftype
=
df2
.
type
ftype
=
df2
.
type
instance
=
ftype
(
value
=
numpy
.
float32
(
32
))
instance
=
ftype
(
value
=
numpy
.
float32
(
32
))
assert
isinstance
(
instance
.
value
,
numpy
.
float32
)
nose
.
tools
.
assert_true
(
isinstance
(
instance
.
value
,
numpy
.
float32
)
)
def
test_no_description
():
def
test_no_description
():
df
=
DataFormat
(
prefix
,
"
user/versioned/1
"
)
df
=
DataFormat
(
prefix
,
"
user/versioned/1
"
)
assert
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
assert
df
.
description
is
None
nose
.
tools
.
assert_is_none
(
df
.
description
)
assert
df
.
documentation
is
None
nose
.
tools
.
assert_is_none
(
df
.
documentation
)
description
=
"
This is my descriptor
"
description
=
"
This is my descriptor
"
df
.
description
=
description
df
.
description
=
description
assert
isinstance
(
df
.
description
,
six
.
string_types
)
nose
.
tools
.
assert_true
(
isinstance
(
df
.
description
,
six
.
string_types
)
)
nose
.
tools
.
eq_
(
df
.
description
,
description
)
nose
.
tools
.
eq_
(
df
.
description
,
description
)
def
test_with_description
():
def
test_with_description
():
df
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
df
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
assert
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
nose
.
tools
.
assert_true
(
df
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df
.
errors
)
)
assert
isinstance
(
df
.
description
,
six
.
string_types
)
nose
.
tools
.
assert_true
(
isinstance
(
df
.
description
,
six
.
string_types
)
)
assert
len
(
df
.
description
)
!=
0
nose
.
tools
.
assert_not_equal
(
len
(
df
.
description
)
,
0
)
assert
df
.
documentation
is
None
nose
.
tools
.
assert_is_none
(
df
.
documentation
)
def
test_description_does_not_affect_hash
():
def
test_description_does_not_affect_hash
():
df2
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
df2
=
DataFormat
(
prefix
,
"
user/versioned/2
"
)
assert
df2
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df2
.
errors
)
nose
.
tools
.
assert_true
(
df2
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df2
.
errors
)
)
df3
=
DataFormat
(
prefix
,
"
user/versioned/3
"
)
# the same, but no description
df3
=
DataFormat
(
prefix
,
"
user/versioned/3
"
)
# the same, but no description
assert
df3
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df3
.
errors
)
nose
.
tools
.
assert_true
(
df3
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
df3
.
errors
)
)
assert
df2
.
hash
()
==
df3
.
hash
()
nose
.
tools
.
eq_
(
df2
.
hash
()
,
df3
.
hash
()
)
def
test_load_direct_recursion
():
def
test_load_direct_recursion
():
df
=
DataFormat
(
prefix
,
"
user/direct_recursion/1
"
)
df
=
DataFormat
(
prefix
,
"
user/direct_recursion/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
assert
df
.
errors
nose
.
tools
.
assert_true
(
df
.
errors
)
assert
df
.
errors
[
0
].
find
(
"
recursion for
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
recursion for
"
)
,
-
1
)
assert
df
.
errors
[
0
].
find
(
"
user/direct_recursion/1
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
user/direct_recursion/1
"
)
,
-
1
)
def
test_load_indirect_recursion
():
def
test_load_indirect_recursion
():
df
=
DataFormat
(
prefix
,
"
user/indirect_recursion_top/1
"
)
df
=
DataFormat
(
prefix
,
"
user/indirect_recursion_top/1
"
)
assert
df
.
valid
is
False
nose
.
tools
.
assert_false
(
df
.
valid
)
assert
df
.
errors
nose
.
tools
.
assert_true
(
df
.
errors
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
df
.
errors
),
1
)
assert
df
.
errors
[
0
].
find
(
"
is invalid
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
is invalid
"
),
-
1
)
assert
df
.
errors
[
0
].
find
(
"
user/indirect_recursion_bottom/1
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
df
.
errors
[
0
].
find
(
"
user/indirect_recursion_bottom/1
"
),
-
1
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
...
@@ -170,10 +172,10 @@ def test_export():
...
@@ -170,10 +172,10 @@ def test_export():
name
=
"
user/composed/1
"
name
=
"
user/composed/1
"
obj
=
DataFormat
(
prefix
,
name
)
obj
=
DataFormat
(
prefix
,
name
)
assert
obj
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
obj
.
errors
)
nose
.
tools
.
assert_true
(
obj
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
obj
.
errors
)
)
obj
.
export
(
tmp_prefix
)
obj
.
export
(
tmp_prefix
)
# load from tmp_prefix and validates
# load from tmp_prefix and validates
exported
=
DataFormat
(
tmp_prefix
,
name
)
exported
=
DataFormat
(
tmp_prefix
,
name
)
assert
exported
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
exported
.
errors
)
nose
.
tools
.
assert_true
(
exported
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
exported
.
errors
)
)
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