44#
55# SPDX-License-Identifier: GPL-2.0-or-later
66
7+ import io
78import os
9+ import sys
810import json
911import random
1012import 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
4955def 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+
7086def 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+
79104def test_debug (tmpdir , capsys ):
80105 filename = str (tmpdir .join ('foo.json' ))
81106 with open (filename , 'w' ) as f :
0 commit comments