def test_posix_backend_failed_write(self):
        """Test writing to a failed file."""
        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.write = mock.MagicMock(
            side_effect=IOError('Unable to Write!'))
        # pylint: enable=protected-access
        with self.assertRaises(ArchiveInterfaceError) as exc:
            backend.write('write stuff')
        self.assertTrue(
            "Can't write posix file with error" in str(exc.exception))
        backend.close()
 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()