Skip to content

Commit befaa0c

Browse files
committed
Extra tests for TSV, refs #4
1 parent 140fe0d commit befaa0c

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Diff for: tests/test_cli.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
from click.testing import CliRunner
22
from csv_diff import cli
3-
from .test_csv_diff import ONE, TWO, THREE, FIVE
3+
import pytest
4+
from .test_csv_diff import ONE, ONE_TSV, TWO, TWO_TSV, THREE, FIVE
45
import json
56
from textwrap import dedent
67

78

9+
@pytest.fixture
10+
def tsv_files(tmpdir):
11+
one = tmpdir / "one.tsv"
12+
one.write(ONE_TSV)
13+
two = tmpdir / "two.tsv"
14+
two.write(TWO_TSV)
15+
return str(one), str(two)
16+
17+
818
def test_human_cli(tmpdir):
919
one = tmpdir / "one.csv"
1020
one.write(ONE)
@@ -74,3 +84,39 @@ def test_human_cli_json(tmpdir):
7484
"columns_added": [],
7585
"columns_removed": [],
7686
} == json.loads(result.output.strip())
87+
88+
89+
def test_tsv_files(tsv_files):
90+
one, two = tsv_files
91+
result = CliRunner().invoke(
92+
cli.cli, [one, two, "--key", "id", "--json", "--format", "tsv"]
93+
)
94+
assert 0 == result.exit_code
95+
assert {
96+
"added": [],
97+
"removed": [],
98+
"changed": [{"key": "1", "changes": {"age": ["4", "5"]}}],
99+
"columns_added": [],
100+
"columns_removed": [],
101+
} == json.loads(result.output.strip())
102+
103+
104+
def test_sniff_format(tsv_files):
105+
one, two = tsv_files
106+
result = CliRunner().invoke(cli.cli, [one, two, "--key", "id", "--json"])
107+
assert 0 == result.exit_code
108+
assert {
109+
"added": [],
110+
"removed": [],
111+
"changed": [{"key": "1", "changes": {"age": ["4", "5"]}}],
112+
"columns_added": [],
113+
"columns_removed": [],
114+
} == json.loads(result.output.strip())
115+
116+
117+
def test_format_overrides_sniff(tsv_files):
118+
one, two = tsv_files
119+
result = CliRunner().invoke(
120+
cli.cli, [one, two, "--key", "id", "--json", "--format", "csv"]
121+
)
122+
assert 1 == result.exit_code

Diff for: tests/test_csv_diff.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
1,Cleo,4
66
2,Pancakes,2"""
77

8+
ONE_TSV = """id\tname\tage
9+
1\tCleo\t4
10+
2\tPancakes\t2"""
11+
812
TWO = """id,name,age
913
1,Cleo,5
1014
2,Pancakes,2"""

0 commit comments

Comments
 (0)