-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_file.py
36 lines (27 loc) · 1.32 KB
/
test_file.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
import unittest, os
from csvhelp import printError, CsvHelperModule
class TestCSVHelperMethods(unittest.TestCase):
readerCSV = 'csv_test_file/testfile.csv'
writeCSV = 'csv_test_file/output.csv'
csvReadDict = {'LastName': 'Seyi', 'City': 'Lagos', 'Country': 'Nigeria', 'FirstName': 'Obaweya'}
csvReadList = ['Obaweya','Seyi','Nigeria','Lagos']
csvreadHeader = ['FirstName','LastName','Country','City']
def test_csvDictReader_Helper(self):
readerDict, headers = CsvHelperModule.readCsvAsDict(self.readerCSV)
self.assertEqual(headers, self.csvreadHeader)
self.assertEqual(readerDict[0], self.csvReadDict)
def test_csvReader_Helper(self):
readerList, headerList = CsvHelperModule.readCsvAsList(self.readerCSV)
self.assertEqual(headerList,self.csvreadHeader)
self.assertEqual(readerList[0], self.csvReadList)
def test_csvDictWriter_Helper(self):
CsvHelperModule.writeCsvDict(self.writeCSV, self.csvreadHeader,[self.csvReadDict,self.csvReadDict])
def test_csvWriter_Helper(self):
CsvHelperModule.writeCsvList(self.writeCSV, self.csvreadHeader, [self.csvReadList, self.csvReadList])
def tearDown(self):
try:
os.remove(self.writeCSV)
except FileNotFoundError:
pass
if __name__ == '__main__':
unittest.main()