コード例 #1
0
    def test_posix_backend_failed_stat(self):
        """Test status to a failed file."""
        backend = PosixBackendArchive('/tmp/')
        backend.open('1234', 'w')
        backend.close()
        # test failed write
        backend.open('1234', 'r')

        # easiest way to unit test is look at class variable
        # pylint: disable=protected-access
        backend._file.status = mock.MagicMock(
            side_effect=IOError('Unable to Read!'))
        # pylint: enable=protected-access
        with self.assertRaises(ArchiveInterfaceError) as exc:
            backend.status()
        self.assertTrue(
            "Can't get posix file status with error" in str(exc.exception))
        backend.close()
コード例 #2
0
    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))