Skip to content

Commit

Permalink
Better unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Feb 6, 2024
1 parent adea12a commit 176f46f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/uwtools/config/atparse_to_jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def convert(

with readable(input_file) as f:
lines = f.read().split("\n")
jinja2 = "\n".join(_replace(line) for line in lines).rstrip()
jinja2 = re.sub(r"\n$", "", "\n".join(_replace(line) for line in lines), count=1)
if dry_run:
for line in jinja2.split("\n"):
log.info(line)
Expand Down
10 changes: 7 additions & 3 deletions src/uwtools/tests/config/test_atparse_to_jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,32 @@ def test_convert_input_file_to_stdout(atparsefile, capsys, txt_jinja2):

def test_convert_preserve_whitespace(tmp_path):
atparse = """
@[first_entry]
@[second_entry]
@[third_entry]
@[fourth_entry]
@[fifth_entry]
""".strip()
"""
infile = tmp_path / "atparse"
with open(infile, "w", encoding="utf-8") as f:
f.write(atparse)
outfile = tmp_path / "jinja2"
atparse_to_jinja2.convert(input_file=infile, output_file=outfile)
expected = """
{{ first_entry }}
{{ second_entry }}
{{ third_entry }}
{{ fourth_entry }}
{{ fifth_entry }}
""".strip()
"""
with open(outfile, "r", encoding="utf-8") as f:
assert f.read().strip() == expected
assert f.read() == expected


def test_convert_stdin_to_file(txt_atparse, capsys, txt_jinja2, tmp_path):
Expand Down

0 comments on commit 176f46f

Please sign in to comment.