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.editor
Commits
776cc240
Commit
776cc240
authored
Jan 10, 2019
by
Samuel GAIST
Browse files
[test][utils] Factor out comparison code
parent
c285113e
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_utils.py
View file @
776cc240
...
...
@@ -38,11 +38,18 @@ from .. import utils
DATA_PATH
=
pkg_resources
.
resource_filename
(
"beat.editor.test"
,
"reference_data"
)
def
compare_with_reference
(
generated
,
reference_file_name
):
""" Compare the given generated code with the content of the reference file
"""
with
open
(
os
.
path
.
join
(
DATA_PATH
,
reference_file_name
))
as
reference_file
:
reference
=
reference_file
.
read
()
return
generated
==
reference
def
test_generate_empty_database
():
database
=
utils
.
generate_database
()
with
open
(
os
.
path
.
join
(
DATA_PATH
,
"empty_database.py"
))
as
db_file
:
empty_db
=
db_file
.
read
()
assert
database
==
empty_db
assert
compare_with_reference
(
database
,
"empty_database.py"
)
def
test_generate_empty_algorithm
():
...
...
@@ -51,13 +58,9 @@ def test_generate_empty_algorithm():
"contents"
:
{
"splittable"
:
True
,
"groups"
:
[],
"uses"
:
{}},
}
algorithm
=
utils
.
generate_algorithm
(
alg
[
"contents"
])
with
open
(
os
.
path
.
join
(
DATA_PATH
,
"empty_algorithm.py"
))
as
db_file
:
empty_alg
=
db_file
.
read
()
assert
algorithm
==
empty_alg
assert
compare_with_reference
(
algorithm
,
"empty_algorithm.py"
)
def
test_generate_empty_library
():
library
=
utils
.
generate_library
()
with
open
(
os
.
path
.
join
(
DATA_PATH
,
"empty_library.py"
))
as
db_file
:
empty_lib
=
db_file
.
read
()
assert
library
==
empty_lib
assert
compare_with_reference
(
library
,
"empty_library.py"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment