class TestCSV(unittest.TestCase): def setUp(self): self.c = CSV() self.f1 = self.c.openFile('f1.csv', 'rt') self.f2 = self.c.openFile('f2.csv', 'rt') def testFileNotFoundError(self): self.assertRaises(FileNotFoundError, self.c.openFile, "f3.csv", "rt") def testSniffDialect(self): assert(self.c.sniffDialect(self.f1).delimiter == ';') def testReadFile(self): list = self.c.readFile(self.f1,self.c.sniffDialect(self.f1)) assert(list==[['1', '2', '3', '5', '']]) def testWriteFile(self): out = self.c.openFile('o.csv', "wt") self.c.writeFile(out, [['1', '2', '3', '5', '']],'Pipe','|') out = self.c.openFile('o.csv', "rt") l2 = self.c.readFile(out,self.c.sniffDialect(out)) print(l2) assert(l2==[['1', '2', '3', '5', ''],[]]) def testCloseFile(self): self.assertRaises(AttributeError, self.c.closeFile, "f3.csv")