def test_posix_backend_failed_stage(self): """Test reading a file from posix backend.""" backend = PosixBackendArchive('/tmp/') backend.open('1234', 'w') backend.close() backend.open('1234', 'r') # easiest way to unit test is look at class variable # pylint: disable=protected-access backend._file.stage = mock.MagicMock( side_effect=IOError('Unable to Stage!')) # pylint: enable=protected-access with self.assertRaises(ArchiveInterfaceError) as exc: backend.stage() self.assertTrue( 'Can\'t stage posix file with error' in str(exc.exception)) backend.close()
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))