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
c450aa3b
Commit
c450aa3b
authored
6 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[test][lib] Code cleanup
parent
5de3888b
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_lib.py
+92
-89
92 additions, 89 deletions
beat/core/test/test_lib.py
with
92 additions
and
89 deletions
beat/core/test/test_lib.py
+
92
−
89
View file @
c450aa3b
...
@@ -46,70 +46,73 @@ from ..library import Library, Storage
...
@@ -46,70 +46,73 @@ from ..library import Library, Storage
def
test_valid
():
def
test_valid
():
l
=
Library
(
prefix
,
"
user/valid/1
"
)
l
ib
=
Library
(
prefix
,
"
user/valid/1
"
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
0
)
# tries to call the function `f()' on that library
# tries to call the function `f()' on that library
module
=
l
.
load
()
module
=
l
ib
.
load
()
assert
isinstance
(
module
,
types
.
ModuleType
)
nose
.
tools
.
assert_true
(
isinstance
(
module
,
types
.
ModuleType
)
)
nose
.
tools
.
eq_
(
module
.
f
(),
"
OK
"
)
nose
.
tools
.
eq_
(
module
.
f
(),
"
OK
"
)
nose
.
tools
.
eq_
(
module
.
pyver
(),
"
%d.%d
"
%
sys
.
version_info
[:
2
])
nose
.
tools
.
eq_
(
module
.
pyver
(),
"
%d.%d
"
%
sys
.
version_info
[:
2
])
def
test_nested_1
():
def
test_nested_1
():
l
=
Library
(
prefix
,
"
user/nest1/1
"
)
l
ib
=
Library
(
prefix
,
"
user/nest1/1
"
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
1
)
# tries to call the function `f()' on that library
# tries to call the function `f()' on that library
module
=
l
.
load
()
module
=
l
ib
.
load
()
assert
isinstance
(
module
,
types
.
ModuleType
)
nose
.
tools
.
assert_true
(
isinstance
(
module
,
types
.
ModuleType
)
)
nose
.
tools
.
eq_
(
module
.
f
(
"
-extra
"
),
"
OK-extra
"
)
nose
.
tools
.
eq_
(
module
.
f
(
"
-extra
"
),
"
OK-extra
"
)
nose
.
tools
.
eq_
(
module
.
pyver
(
"
-extra
"
),
"
%d.%d-extra
"
%
sys
.
version_info
[:
2
])
nose
.
tools
.
eq_
(
module
.
pyver
(
"
-extra
"
),
"
%d.%d-extra
"
%
sys
.
version_info
[:
2
])
def
test_nested_2
():
def
test_nested_2
():
l
=
Library
(
prefix
,
"
user/nest2/1
"
)
l
ib
=
Library
(
prefix
,
"
user/nest2/1
"
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
1
)
# tries to call the function `f()' on that library
# tries to call the function `f()' on that library
module
=
l
.
load
()
module
=
l
ib
.
load
()
assert
isinstance
(
module
,
types
.
ModuleType
)
nose
.
tools
.
assert_true
(
isinstance
(
module
,
types
.
ModuleType
)
)
nose
.
tools
.
eq_
(
module
.
f
(
"
-x
"
),
"
OK-x-x
"
)
nose
.
tools
.
eq_
(
module
.
f
(
"
-x
"
),
"
OK-x-x
"
)
nose
.
tools
.
eq_
(
module
.
pyver
(
"
-x
"
),
"
%d.%d-x-x
"
%
sys
.
version_info
[:
2
])
nose
.
tools
.
eq_
(
module
.
pyver
(
"
-x
"
),
"
%d.%d-x-x
"
%
sys
.
version_info
[:
2
])
def
test_direct_recursion
():
def
test_direct_recursion
():
l
=
Library
(
prefix
,
"
user/direct_recursion/1
"
)
lib
=
Library
(
prefix
,
"
user/direct_recursion/1
"
)
assert
not
l
.
valid
nose
.
tools
.
assert_false
(
lib
.
valid
)
nose
.
tools
.
eq_
(
len
(
l
.
errors
),
1
)
assert
l
.
errors
[
0
].
find
(
"
recursion for library
"
)
!=
-
1
nose
.
tools
.
eq_
(
len
(
lib
.
errors
),
1
)
assert
l
.
errors
[
0
].
find
(
l
.
name
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
recursion for library
"
),
-
1
)
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
lib
.
name
),
-
1
)
def
test_indirect_recursion
():
def
test_indirect_recursion
():
l
=
Library
(
prefix
,
"
user/indirect_recursion/1
"
)
lib
=
Library
(
prefix
,
"
user/indirect_recursion/1
"
)
assert
not
l
.
valid
nose
.
tools
.
assert_false
(
lib
.
valid
)
nose
.
tools
.
eq_
(
len
(
l
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
lib
.
errors
),
1
)
assert
l
.
errors
[
0
].
find
(
"
referred library
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
referred library
"
),
-
1
)
assert
l
.
errors
[
0
].
find
(
"
user/indirect_recursion_next/1
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
user/indirect_recursion_next/1
"
),
-
1
)
def
test_invalid_mix
():
def
test_invalid_mix
():
l
=
Library
(
prefix
,
"
user/invalid_mix/1
"
)
l
ib
=
Library
(
prefix
,
"
user/invalid_mix/1
"
)
assert
not
l
.
valid
nose
.
tools
.
assert_false
(
lib
.
valid
)
nose
.
tools
.
eq_
(
len
(
l
.
errors
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
errors
),
1
)
assert
l
.
errors
[
0
].
find
(
"
differs from current language
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
differs from current language
"
)
,
-
1
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
...
@@ -118,79 +121,79 @@ def test_dependencies():
...
@@ -118,79 +121,79 @@ def test_dependencies():
name
=
"
user/for_dep/1
"
name
=
"
user/for_dep/1
"
dep_name
=
"
user/dep/1
"
dep_name
=
"
user/dep/1
"
l
=
Library
(
prefix
,
name
)
l
ib
=
Library
(
prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
0
)
# Save to temporary storage, so we can test modifications on it
# Save to temporary storage, so we can test modifications on it
new_storage
=
Storage
(
tmp_prefix
,
name
)
new_storage
=
Storage
(
tmp_prefix
,
name
)
l
.
write
(
new_storage
)
l
ib
.
write
(
new_storage
)
l_dep
=
Library
(
prefix
,
dep_name
)
l_dep
=
Library
(
prefix
,
dep_name
)
assert
l_dep
.
valid
nose
.
tools
.
assert_true
(
l_dep
.
valid
)
new_dep_storage
=
Storage
(
tmp_prefix
,
dep_name
)
new_dep_storage
=
Storage
(
tmp_prefix
,
dep_name
)
l_dep
.
write
(
new_dep_storage
)
l_dep
.
write
(
new_dep_storage
)
# Reload
# Reload
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
l_dep
=
Library
(
tmp_prefix
,
dep_name
)
l_dep
=
Library
(
tmp_prefix
,
dep_name
)
assert
l_dep
.
valid
nose
.
tools
.
assert_true
(
l_dep
.
valid
)
l
.
uses
[
"
dep1
"
]
=
l_dep
.
name
l
ib
.
uses
[
"
dep1
"
]
=
l_dep
.
name
l
.
write
()
# rewrite
l
ib
.
write
()
# rewrite
# Re-validate
# Re-validate
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
1
)
nose
.
tools
.
eq_
(
list
(
l
.
uses
.
keys
())[
0
],
"
dep1
"
)
nose
.
tools
.
eq_
(
list
(
l
ib
.
uses
.
keys
())[
0
],
"
dep1
"
)
nose
.
tools
.
eq_
(
list
(
l
.
uses
.
values
())[
0
],
"
user/dep/1
"
)
nose
.
tools
.
eq_
(
list
(
l
ib
.
uses
.
values
())[
0
],
"
user/dep/1
"
)
l
.
uses
=
{}
# reset
l
ib
.
uses
=
{}
# reset
l
.
uses
[
"
mod1
"
]
=
l_dep
.
name
l
ib
.
uses
[
"
mod1
"
]
=
l_dep
.
name
l
.
write
()
# rewrite
l
ib
.
write
()
# rewrite
# Re-validate
# Re-validate
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
1
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
1
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
1
)
nose
.
tools
.
eq_
(
list
(
l
.
uses
.
keys
())[
0
],
"
mod1
"
)
nose
.
tools
.
eq_
(
list
(
l
ib
.
uses
.
keys
())[
0
],
"
mod1
"
)
nose
.
tools
.
eq_
(
list
(
l
.
uses
.
values
())[
0
],
"
user/dep/1
"
)
nose
.
tools
.
eq_
(
list
(
l
ib
.
uses
.
values
())[
0
],
"
user/dep/1
"
)
l
.
uses
=
{}
# reset
l
ib
.
uses
=
{}
# reset
l
.
write
()
# rewrite
l
ib
.
write
()
# rewrite
# Re-validate
# Re-validate
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
0
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
def
test_adding_self
():
def
test_adding_self
():
name
=
"
user/for_dep/1
"
name
=
"
user/for_dep/1
"
l
=
Library
(
prefix
,
name
)
l
ib
=
Library
(
prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
0
)
l
.
uses
[
"
dep
"
]
=
l
.
name
l
ib
.
uses
[
"
dep
"
]
=
l
ib
.
name
new_storage
=
Storage
(
tmp_prefix
,
name
)
new_storage
=
Storage
(
tmp_prefix
,
name
)
l
.
write
(
new_storage
)
# rewrite
l
ib
.
write
(
new_storage
)
# rewrite
# Re-validate
# Re-validate
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
not
l
.
valid
nose
.
tools
.
assert_false
(
lib
.
valid
)
assert
l
.
errors
[
0
].
find
(
"
recursion
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
recursion
"
)
,
-
1
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
...
@@ -199,33 +202,33 @@ def test_invalid_dependencies():
...
@@ -199,33 +202,33 @@ def test_invalid_dependencies():
name
=
"
user/for_dep/1
"
name
=
"
user/for_dep/1
"
dep_name
=
"
user/invalid_dep/1
"
dep_name
=
"
user/invalid_dep/1
"
l
=
Library
(
prefix
,
name
)
l
ib
=
Library
(
prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
nose
.
tools
.
eq_
(
len
(
l
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
uses
),
0
)
nose
.
tools
.
eq_
(
len
(
l
.
libraries
),
0
)
nose
.
tools
.
eq_
(
len
(
l
ib
.
libraries
),
0
)
# Save to temporary storage, so we can test modifications on it
# Save to temporary storage, so we can test modifications on it
new_storage
=
Storage
(
tmp_prefix
,
name
)
new_storage
=
Storage
(
tmp_prefix
,
name
)
l
.
write
(
new_storage
)
l
ib
.
write
(
new_storage
)
l_dep
=
Library
(
prefix
,
dep_name
)
l_dep
=
Library
(
prefix
,
dep_name
)
assert
l_dep
.
valid
nose
.
tools
.
assert_true
(
l_dep
.
valid
)
new_dep_storage
=
Storage
(
tmp_prefix
,
dep_name
)
new_dep_storage
=
Storage
(
tmp_prefix
,
dep_name
)
l_dep
.
write
(
new_dep_storage
)
l_dep
.
write
(
new_dep_storage
)
# Reload
# Reload
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
l
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
.
errors
)
nose
.
tools
.
assert_true
(
lib
.
valid
,
"
\n
* %s
"
%
"
\n
*
"
.
join
(
l
ib
.
errors
)
)
l_dep
=
Library
(
tmp_prefix
,
dep_name
)
l_dep
=
Library
(
tmp_prefix
,
dep_name
)
assert
l_dep
.
valid
nose
.
tools
.
assert_true
(
l_dep
.
valid
)
l
.
uses
[
"
dep1
"
]
=
l_dep
.
name
l
ib
.
uses
[
"
dep1
"
]
=
l_dep
.
name
l
.
write
()
# rewrite
l
ib
.
write
()
# rewrite
# Re-validate
# Re-validate
l
=
Library
(
tmp_prefix
,
name
)
l
ib
=
Library
(
tmp_prefix
,
name
)
assert
not
l
.
valid
nose
.
tools
.
assert_false
(
lib
.
valid
)
assert
l
.
errors
[
0
].
find
(
"
differs from current language
"
)
!=
-
1
nose
.
tools
.
assert_not_equal
(
lib
.
errors
[
0
].
find
(
"
differs from current language
"
)
,
-
1
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
@nose.tools.with_setup
(
teardown
=
cleanup
)
...
@@ -233,10 +236,10 @@ def test_export():
...
@@ -233,10 +236,10 @@ def test_export():
name
=
"
user/nest2/1
"
name
=
"
user/nest2/1
"
obj
=
Library
(
prefix
,
name
)
obj
=
Library
(
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
=
Library
(
tmp_prefix
,
name
)
exported
=
Library
(
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