diff --git a/test/fixtures/reverse.csv b/test/fixtures/reverse.csv new file mode 100644 index 0000000..93d2e2b --- /dev/null +++ b/test/fixtures/reverse.csv @@ -0,0 +1 @@ +1,51.9526622,7.6324709 \ No newline at end of file diff --git a/test/test_cli_args.py b/test/test_cli_args.py index 0f918ab..c75b776 100644 --- a/test/test_cli_args.py +++ b/test/test_cli_args.py @@ -6,7 +6,7 @@ @pytest.fixture(autouse=True) def around(): yield - pathlib.Path("test/fixtures/output.txt").unlink(True) + pathlib.Path("test/fixtures/output.csv").unlink(True) def assert_parse_args_error(args, message, capfd): with pytest.raises(SystemExit): @@ -27,7 +27,7 @@ def test_invalid_api_key(capfd): [ "--api-key", "invalid", "--input", "test/fixtures/input.txt", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", "--forward" ], 'invalid API key', @@ -51,7 +51,7 @@ def test_requires_forward_or_reverse(capfd): [ "--api-key", "oc_gc_12345678901234567890123456789012", "--input", "test/fixtures/input.txt", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", ], 'one of the arguments --forward --reverse is required', capfd @@ -62,7 +62,7 @@ def test_argument_range(capfd): [ "--api-key", "oc_gc_12345678901234567890123456789012", "--input", "test/fixtures/input.txt", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", "--forward", "--workers", "200" ], @@ -74,7 +74,7 @@ def test_full_argument_list(): args = parse_args([ "--api-key", "oc_gc_12345678901234567890123456789012", "--input", "test/fixtures/input.txt", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", "--reverse", "--has-header", "--input-columns", "1,2", @@ -92,7 +92,7 @@ def test_full_argument_list(): assert args.api_key == "oc_gc_12345678901234567890123456789012" assert args.input.name == "test/fixtures/input.txt" - assert args.output.name == "test/fixtures/output.txt" + assert args.output.name == "test/fixtures/output.csv" assert args.reverse is True assert args.forward is False assert args.has_headers is True @@ -112,7 +112,7 @@ def test_defaults(): args = parse_args([ "--api-key", "12345678901234567890123456789012", "--input", "test/fixtures/input.txt", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", "--reverse" ]) diff --git a/test/test_cli_run.py b/test/test_cli_run.py index b2039ca..85f67f4 100644 --- a/test/test_cli_run.py +++ b/test/test_cli_run.py @@ -8,21 +8,44 @@ @pytest.fixture(autouse=True) def around(): yield - pathlib.Path("test/fixtures/output.txt").unlink(True) + pathlib.Path("test/fixtures/output.csv").unlink(True) -@pytest.mark.asyncio -def test_main(): +def assert_output(path, length, lines): + assert pathlib.Path(path).exists() + + with open(path, "r") as f: + actual = f.readlines() + assert len(actual) == length + + for i, expected in enumerate(lines): + assert actual[i].strip() == expected + +def test_forward(): main([ "--api-key", "6d0e711d72d74daeb2b0bfd2a5cdfdba", "--input", "test/fixtures/forward.csv", - "--output", "test/fixtures/output.txt", + "--output", "test/fixtures/output.csv", "--forward", "--input-columns", "2,3,4", ]) - assert pathlib.Path("test/fixtures/output.txt").exists() + assert_output( + path="test/fixtures/output.csv", + length=3, + lines=['1,51.9526622,7.6324709,social_facility,Germany,,Münster,48153,Friedrich-Ebert-Straße,7,9,"Chance e.V., Friedrich-Ebert-Straße 7, 48153 Münster, Germany"'] + ) + +def test_reverse(): + main([ + "--api-key", "6d0e711d72d74daeb2b0bfd2a5cdfdba", + "--input", "test/fixtures/reverse.csv", + "--output", "test/fixtures/output.csv", + "--reverse", + "--add-columns", "city,postcode" + ]) - with open("test/fixtures/output.txt", "r") as f: - lines = f.readlines() - assert len(lines) == 3 - assert lines[0].strip() == '1,51.9526622,7.6324709,social_facility,Germany,,Münster,48153,Friedrich-Ebert-Straße,7,9,"Chance e.V., Friedrich-Ebert-Straße 7, 48153 Münster, Germany"' + assert_output( + path="test/fixtures/output.csv", + length=1, + lines=['1,51.9526622,7.6324709,Münster,48153'] + )