def test_posix_backend_error(self): """Test opening a file from posix backend.""" with self.assertRaises(ArchiveInterfaceError): backend = PosixBackendArchive('/tmp') # easiest way to unit test is look at class variable # pylint: disable=protected-access backend._file = 'none file object' backend.open('1234', 'w')
def test_posix_backend_failed_fd(self): """Test reading to a failed file fd.""" backend = PosixBackendArchive('/tmp/') # test failed write backend.open('1234', 'w') # easiest way to unit test is look at class variable # pylint: disable=protected-access backend._file = None # pylint: enable=protected-access with self.assertRaises(ArchiveInterfaceError) as exc: backend.write('Something to write') self.assertTrue('Internal file handle invalid' in str(exc.exception)) with self.assertRaises(ArchiveInterfaceError) as exc: backend.read(1024) self.assertTrue('Internal file handle invalid' in str(exc.exception)) with self.assertRaises(ArchiveInterfaceError) as exc: backend.stage() self.assertTrue('Internal file handle invalid' in str(exc.exception)) with self.assertRaises(ArchiveInterfaceError) as exc: backend.status() self.assertTrue('Internal file handle invalid' in str(exc.exception))