-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
64 lines (55 loc) · 1.72 KB
/
tests.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import csv
import unittest
from imcsv.exceptions import EmptyHeadersError, InconsistentCsvDataError
from imcsv.imcsv import generate_temp_csvfile
class TestImcsvCreator(unittest.TestCase):
def test_generate_temp_csvfile_with_valid_data(self):
headers = [
"Date",
"Month",
"Year",
"Customer ID",
"Item ID",
]
rows = [
[
"5-June-2020",
"5",
"2020",
"920",
"1380",
],
]
temp_csvfile = generate_temp_csvfile(headers, rows)
with open(temp_csvfile.name) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
self.assertEqual("5-June-2020", row["Date"])
self.assertEqual("5", row["Month"])
self.assertEqual("2020", row["Year"])
self.assertEqual("920", row["Customer ID"])
self.assertEqual("1380", row["Item ID"])
self.assertIsNotNone(temp_csvfile)
def test_generate_temp_csvfile_with_valid_inconsistent_data(self):
headers = [
"Date",
"Month",
"Year",
]
rows = [
[
"5-June-2020",
"5",
"2020",
],
["0"],
]
with self.assertRaises(InconsistentCsvDataError):
_ = generate_temp_csvfile(headers, rows)
def test_generate_temp_csvfile_with_empty_headers(self):
headers = []
rows = [[]]
with self.assertRaises(EmptyHeadersError):
_ = generate_temp_csvfile(headers, rows)
if __name__ == "__main__":
unittest.main()