Skip to content

Commit 351f989

Browse files
committed
Bump cli test coverage
1 parent bd6c737 commit 351f989

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#
55
# SPDX-License-Identifier: GPL-2.0-or-later
66

7+
import io
78
import os
9+
import sys
810
import json
911
import random
1012
import datetime as dt
@@ -44,6 +46,10 @@ def test_timestamps():
4446
dt.timedelta(seconds=1), dt.datetime(2015, 3, 31))
4547
assert cli.timestamps('milliseconds since 1900-01-01') == (
4648
dt.timedelta(milliseconds=1), dt.datetime(1900, 1, 1))
49+
with pytest.raises(ValueError):
50+
cli.timestamps('')
51+
with pytest.raises(ValueError):
52+
cli.timestamps('years since 1970-01-01')
4753

4854

4955
def test_num():
@@ -67,6 +73,16 @@ def test_size():
6773
assert cli.size('1M') == 1048576
6874

6975

76+
def test_file(tmpdir):
77+
assert cli.file('-') is sys.stdin.buffer
78+
data = list(range(100))
79+
filename = str(tmpdir.join('foo.json'))
80+
with open(filename, 'w') as f:
81+
json.dump(data, f)
82+
with cli.file(filename) as f:
83+
assert isinstance(f, io.IOBase)
84+
85+
7086
def test_main(tmpdir, capsys):
7187
data = list(range(100))
7288
filename = str(tmpdir.join('foo.json'))
@@ -76,6 +92,15 @@ def test_main(tmpdir, capsys):
7692
assert capsys.readouterr().out.strip() == '[ int range=0..99 ]'
7793

7894

95+
def test_main_manual_encoding(tmpdir, capsys):
96+
data = list(range(100))
97+
filename = str(tmpdir.join('foo.json'))
98+
with open(filename, 'w', encoding='ascii') as f:
99+
json.dump(data, f)
100+
assert cli.main([filename, '--encoding', 'ascii']) == 0
101+
assert capsys.readouterr().out.strip() == '[ int range=0..99 ]'
102+
103+
79104
def test_debug(tmpdir, capsys):
80105
filename = str(tmpdir.join('foo.json'))
81106
with open(filename, 'w') as f:

0 commit comments

Comments
 (0)