Skip to content

Commit d7cad83

Browse files
add jsonline test
1 parent 8704bff commit d7cad83

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/io/test_file.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ def test_write_lines(example_lines):
8383
os.remove(filename)
8484

8585

86+
def test_jsonline(example_json):
87+
dirname = tempfile.gettempdir() + '/'
88+
filename = dirname + 'a.jsonl'
89+
write_jsonline(filename, example_json)
90+
data = [json.loads(line) for line in read_lines(filename)]
91+
assert example_json == data
92+
93+
items = read_jsonline(filename)
94+
assert example_json == items
95+
96+
if os.path.exists(filename):
97+
os.remove(filename)
98+
99+
append_jsonlines(filename, example_json)
100+
items = read_jsonline(filename)
101+
assert example_json == items
102+
103+
if os.path.exists(filename):
104+
os.remove(filename)
105+
append_jsonline(filename, items)
106+
assert read_json(filename) == example_json
107+
if os.path.exists(filename):
108+
os.remove(filename)
109+
110+
86111
def test_text_file(example_lines):
87112
true_text = '\n'.join(example_lines)
88113
text_file = TextFile(TEST_DATA_DIR + 'a.txt')

0 commit comments

Comments
 (0)