@@ -30,26 +30,26 @@ def test_cli(tdc_cli, command):
30
30
tdc_cli .invoke (command )
31
31
32
32
33
- def test_check (tdc_cli , test_data_path , tmp_store ):
33
+ CHECK_ARGS = [
34
+ "--structure=dataflow" ,
35
+ "--structure-id=FOO" ,
36
+ "--action=I" ,
37
+ "--sheets=sheet_2" ,
38
+ "Dataflow=TDCI:EMBER_001(1.0.0)" ,
39
+ ]
40
+
41
+
42
+ def test_check0 (tdc_cli , test_data_path , tmp_store ):
43
+ """Check a successful read of a .xlsx file."""
34
44
ember_dfd (tmp_store )
35
45
36
- result = tdc_cli .invoke (
37
- [
38
- "check" ,
39
- "--sheets=sheet_2" ,
40
- "--structure=dataflow" ,
41
- "--structure-id=FOO" ,
42
- "--action=I" ,
43
- "Dataflow=TDCI:EMBER_001(1.0.0)" ,
44
- str (test_data_path .joinpath ("read-csv-2.xlsx" )),
45
- ]
46
- )
46
+ path = test_data_path .joinpath ("read-csv-2.xlsx" )
47
+ result = tdc_cli .invoke (["check" ] + CHECK_ARGS + [str (path )])
47
48
48
49
# Command runs without error
49
50
assert 0 == result .exit_code , result .output
50
51
51
52
# Data was located, converted to CSV, read, and summary displayed
52
- print (result .output )
53
53
assert re .fullmatch (
54
54
r"""
55
55
File: .*read-csv-2.xlsx
@@ -64,6 +64,40 @@ def test_check(tdc_cli, test_data_path, tmp_store):
64
64
)
65
65
66
66
67
+ @pytest .mark .parametrize (
68
+ "args, exit_code, text" ,
69
+ (
70
+ (["X" ], 1 , "line 1, field 1" ), # Omit all options and URN
71
+ (CHECK_ARGS [:1 ] + ["X" ], 1 , "line 1, field 2" ), # Only --structure=
72
+ (CHECK_ARGS [:2 ] + ["X" ], 1 , "'X' could not be loaded" ), # Invalid structure URN
73
+ (CHECK_ARGS + ["-v" ], 0 , "..." ), # Show pd.DataFrame abbreviated string repr
74
+ (CHECK_ARGS + ["-vv" ], 0 , "" ), # Show pd.DataFrame full string repr
75
+ ),
76
+ )
77
+ def test_check1 (tdc_cli , test_data_path , tmp_store , args , exit_code , text ):
78
+ """Check various other argument combinations."""
79
+ ember_dfd (tmp_store )
80
+
81
+ path = test_data_path .joinpath ("read-csv-1.csv" )
82
+ result = tdc_cli .invoke (["check" ] + args + [str (path )])
83
+
84
+ # Command gives the expected exit code
85
+ assert exit_code == result .exit_code , result .output
86
+
87
+ # Expected text is contained in the output
88
+ if text :
89
+ assert text in result .output
90
+
91
+
92
+ def test_check2 (tdc_cli , tmp_path ):
93
+ path = tmp_path .joinpath ("foo.txt" )
94
+ path .touch ()
95
+ result = tdc_cli .invoke (["check" , "X" , str (path )])
96
+
97
+ assert 2 == result .exit_code , result .output
98
+ assert "Unsupported file extension" in result .output
99
+
100
+
67
101
# ‘Script’ of CLI input to produce a data structure definition
68
102
SCRIPT = [
69
103
# Maintainer ID: accept the default (TDCI)
0 commit comments