-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_reader.py
More file actions
34 lines (25 loc) · 894 Bytes
/
test_reader.py
File metadata and controls
34 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# test_reader.py
# Run with: python3 -m pytest test_reader.py -v
from reader import read_csv
def test_simple_file_row_count():
result = read_csv('data/simple.csv')
assert len(result) == 2
def test_simple_file_keys():
result = read_csv('data/simple.csv')
assert list(result[0].keys()) == ['name', 'age', 'city']
def test_simple_file_values():
result = read_csv('data/simple.csv')
assert result[0]['name'] == 'Ada'
assert result[0]['city'] == 'Nashville'
def test_empty_file():
result = read_csv('data/empty.csv')
assert result == []
def test_messy_file_skips_blank_rows():
result = read_csv('data/messy.csv')
assert len(result) == 2
def test_whitespace_stripped():
result = read_csv('data/messy.csv')
assert result[0]['name'] == 'Ada'
def test_header_only_file():
result = read_csv('data/header_only.csv')
assert result == []