Skip to content

Commit f9f4c93

Browse files
committed
add more test
1 parent 0dfedf8 commit f9f4c93

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

jsoncsv/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010

1111
def separator_type(sep):
1212
if len(sep) != 1:
13-
raise click.BadOptionUsage('separator can only be a char')
13+
raise click.BadOptionUsage(
14+
option_name='separator',
15+
message='separator can only be a char')
1416
if sep == unit_char:
15-
raise click.BadOptionUsage('separator can not be `\\` ')
17+
raise click.BadOptionUsage(
18+
option_name='separator',
19+
message='separator can not be `\\` ')
1620
return sep
1721

1822

tests/test_jsoncsv.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,29 @@
1010

1111

1212
class Testjsoncsv(unittest.TestCase):
13-
1413
def test_jsoncsv_expand(self):
1514
runner = CliRunner()
16-
args = ['-e', 'fixture/files/raw.0.json', 'fixture/files/tmp.expand.0.json']
15+
args = ['-e', 'fixture/files/raw.0.json',
16+
'fixture/files/tmp.expand.0.json']
1717
result = runner.invoke(jsoncsv, args=args)
1818
assert result.exit_code == 0
1919

2020
def test_jsoncsv_expand_with_json_array(self):
2121
runner = CliRunner()
22-
args = ['-e', 'fixture/files/raw.1.json', 'fixture/files/tmp.expand.1.json', '-A']
22+
args = ['-e', 'fixture/files/raw.1.json',
23+
'fixture/files/tmp.expand.1.json', '-A']
2324
result = runner.invoke(jsoncsv, args=args)
2425
assert result.exit_code == 0
2526

2627
def test_jsoncsv_expand_restore(self):
2728
runner = CliRunner(echo_stdin=True)
28-
result = runner.invoke(jsoncsv, args=['-e', 'fixture/files/raw.2.json', 'fixture/files/tmp.expand.2.json'])
29+
result = runner.invoke(jsoncsv,
30+
args=['-e', 'fixture/files/raw.2.json',
31+
'fixture/files/tmp.expand.2.json'])
2932
assert result.exit_code == 0
30-
result = runner.invoke(jsoncsv, args=['-r', 'fixture/files/tmp.expand.2.json', 'fixture/files/tmp.restore.2.json'])
33+
result = runner.invoke(jsoncsv,
34+
args=['-r', 'fixture/files/tmp.expand.2.json',
35+
'fixture/files/tmp.restore.2.json'])
3136
assert result.exit_code == 0
3237

3338
with io.open('fixture/files/raw.2.json', 'r') as f:
@@ -37,3 +42,17 @@ def test_jsoncsv_expand_restore(self):
3742
resotre_data = [json.loads(line) for line in f]
3843

3944
self.assertEqual(input_data, resotre_data)
45+
46+
def test_jsoncsv_with_error_args(self):
47+
runner = CliRunner()
48+
args = ['-s', 'aa', '-e', 'fixture/files/raw.0.json',
49+
'fixture/files/tmp.expand.0.json']
50+
result = runner.invoke(jsoncsv, args=args)
51+
assert result.exit_code != 0
52+
53+
def test_jsoncsv_with_error_args_expand_and_restore(self):
54+
runner = CliRunner()
55+
args = ['-r', '-e', 'fixture/files/raw.0.json',
56+
'fixture/files/tmp.expand.0.json']
57+
result = runner.invoke(jsoncsv, args=args)
58+
assert result.exit_code != 0

0 commit comments

Comments
 (0)