def testGetSourceName(self): firstPath = os.path.join(self.__dirPath, "resources/first") secondPath = os.path.join(self.__dirPath, "resources/second") readerNameFS = ReaderNameFS([firstPath, secondPath]) fileSource = FileSource() fileSourceCustom = FileSourceCustom() for itemFile in readerNameFS.getSourceCustom(): fileSourceCustom.custom = itemFile openSource = fileSource.openSource(fileSourceCustom.custom) self.assertIsNotNone(fileSource.getName(openSource), "filename is not to be a None object") fileSource.closeSource(openSource)
class TestFileSource(unittest.TestCase): def setUp(self): self.__fileSource = FileSource() self.__dirPath = os.path.abspath(os.curdir) def testGetSource(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) self.assertIsNotNone(source, "not open source") self.__fileSource.closeSource(source) def testGetSourceThrowIOError(self): filePath = os.path.join(self.__dirPath, "resources/not_exist_file") self.assertRaises(IOError, self.__fileSource.openSource, filePath) def testRead(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) for line in self.__fileSource.read(source): self.assertIsNotNone(line) self.__fileSource.closeSource(source) def testGetName(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) self.assertIsNotNone(self.__fileSource.getName(source)) self.__fileSource.closeSource(source) def testGetSourceSize(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) self.assertIsNotNone(self.__fileSource.getSourceSize(source)) self.__fileSource.closeSource(source) def testGetSourceDateCreated(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) self.assertIsNotNone(self.__fileSource.getSourceDateCreated(source)) self.__fileSource.closeSource(source) def testGetSourceDateModified(self): filePath = os.path.join(self.__dirPath, "resources/test_read_file") source = self.__fileSource.openSource(filePath) self.assertIsNotNone(self.__fileSource.getSourceDateModified(source)) self.__fileSource.closeSource(source)