Commit 776cc240 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][utils] Factor out comparison code

parent c285113e
......@@ -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")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment