Skip to content

Commit 82898f0

Browse files
committed
Fix tests for cross-platform compatibility.
1 parent fb9178f commit 82898f0

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

tests/test_cli.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
from codicefiscale.cli import run, run_with_args
99

1010

11-
def assert_output(command, expected_output):
11+
def assert_command_output(command, expected_output):
1212
output = subprocess.check_output(command, shell=True).decode("utf-8").strip()
13-
assert output == expected_output
13+
# normalize line endings for cross-platform compatibility
14+
output = output.replace("\r\n", "\n").strip()
15+
assert output == expected_output.replace("\r\n", "\n").strip()
16+
return output
1417

1518

1619
def test_version():
@@ -25,7 +28,7 @@ def test_version():
2528

2629

2730
def test_version_from_command_line():
28-
assert_output("python -m codicefiscale --version", __version__)
31+
assert_command_output("python -m codicefiscale --version", __version__)
2932

3033

3134
def test_main_without_args():
@@ -37,7 +40,7 @@ def test_main_without_args():
3740

3841

3942
def test_main_without_args_from_command_line():
40-
assert_output(
43+
assert_command_output(
4144
"python -m codicefiscale",
4245
"For more info run: 'python -m codicefiscale --help'",
4346
)
@@ -59,7 +62,7 @@ def test_encode():
5962

6063

6164
def test_encode_from_command_line():
62-
assert_output(
65+
assert_command_output(
6366
(
6467
"python -m codicefiscale encode "
6568
"--firstname Mario "
@@ -168,10 +171,7 @@ def test_decode_without_omocodes():
168171

169172
def test_decode_without_omocodes_from_command_line():
170173
cmd = "python -m codicefiscale decode 'RSSMRA90A01H501W'"
171-
output = subprocess.check_output(cmd, shell=True).decode("UTF-8").strip()
172-
assert (
173-
output
174-
== """
174+
expected_output = """
175175
{
176176
"code": "RSSMRA90A01H501W",
177177
"gender": "M",
@@ -202,9 +202,8 @@ def test_decode_without_omocodes_from_command_line():
202202
"cin": "W"
203203
}
204204
}
205-
""".strip()
206-
)
207-
205+
"""
206+
output = assert_command_output(cmd, expected_output)
208207
output_data = json.loads(output)
209208
assert output_data == {
210209
"code": "RSSMRA90A01H501W",
@@ -599,8 +598,7 @@ def test_validate():
599598

600599
def test_validate_from_command_line():
601600
cmd = "python -m codicefiscale validate 'RSSMRA90A01H501W'"
602-
output = subprocess.check_output(cmd, shell=True).decode("UTF-8").strip()
603-
assert output == "✅"
601+
assert_command_output(cmd, "✅")
604602

605603

606604
def test_validate_with_wrong_code():
@@ -616,5 +614,4 @@ def test_validate_with_wrong_code():
616614

617615
def test_validate_with_wrong_code_from_command_line():
618616
cmd = "python -m codicefiscale validate 'RSSMRA90A01H501X'"
619-
output = subprocess.check_output(cmd, shell=True).decode("UTF-8").strip()
620-
assert output == "❌"
617+
assert_command_output(cmd, "❌")

0 commit comments

Comments
 (0)