Skip to content

Commit

Permalink
update all tests to use the new omit none control parameter. All test…
Browse files Browse the repository at this point in the history
…s omit the none value from json because the static test structures used to compare the results also do not include nones / nulls #71
  • Loading branch information
jh-RLI committed Jan 19, 2024
1 parent 3b02795 commit 6da0b9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/test_cli/test_cli_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
from omi.cli import translate
import json


def test_cli_translation():
@click.command()
@click.argument('name')
@click.argument("name")
def hello(name):
click.echo('Hello %s!' % name)
click.echo("Hello %s!" % name)

runner = CliRunner()
result = runner.invoke(translate, ["-f", "oep-v1.3", "-t", "oep-v1.4", "tests/data/metadata_v13.json"])
result = runner.invoke(
translate,
["-f", "oep-v1.3", "-t", "oep-v1.4", "-omit_nones", "True", "tests/data/metadata_v13.json"],
)
with open("tests/data/metadata_v13_converted.json") as expected_file:
expected = json.loads(expected_file.read())
print(result)
assert result.exit_code == 0
assert json.loads(result.output) == expected
4 changes: 4 additions & 0 deletions tests/test_dialects/test_oep/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

def test_compiler_v1_5():
compiler = JSONCompilerOEM15()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v15.json", "r", encoding="utf-8") as _input_file:
expected_result = json.load(_input_file)
result = compiler.visit(metadata_v_1_5)
Expand All @@ -15,6 +17,8 @@ def test_compiler_v1_5():

def test_compiler_v1_4():
compiler = JSONCompiler()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v14.json", "r", encoding="utf-8") as _input_file:
expected_result = json.load(_input_file)
result = compiler.visit(metadata_v_1_4)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dialects/test_oep/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
def test_translation_1_3_to_1_4():
parser = JSONParser_1_3()
compiler = JSONCompiler()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v13_minimal.json", "r") as _input_file:
input_string = _input_file.read()
# Step 1: Parse JSON to internal structure
Expand Down

0 comments on commit 6da0b9b

Please sign in to comment.