def test_context_manager_failure_case(self):
        tempdir = tempfile.mkdtemp()
        try:
            dir_one = os.path.join(tempdir, 'dir_one')
            # This tests creating files inside created dirs:
            file_one = os.path.join(dir_one, 'one.txt')

            file_two = os.path.join(tempdir, 'two.txt')
            file_three = os.path.join(tempdir, 'three.txt')

            # file_two will be pre-existing
            open(file_two, 'w').close()

            try:
                with util.AtomicFileCreator() as afc:
                    afc.create_file('dir', dir_one, None)
                    afc.create_file('file', file_one, 'abc')
                    afc.create_file('file', file_two, 'def')
                    afc.create_file('file', file_three, 'ghi')
            except __HOLE__:
                assert afc._files_created == [
                    ('dir', dir_one, None),
                    ('file', file_one, 'abc'),
                ]
                # Test that everything was rolled back, except for the
                # pre-existing file.
                assert not os.path.exists(dir_one)
                assert not os.path.exists(file_one)
                assert os.path.exists(file_two)
                assert not os.path.exists(file_three)
            else:
                # No IOError, fail the test
                assert False, "Expected IOError not raised"
        finally:
            shutil.rmtree(tempdir)
dataset/ETHPy150Open zerovm/zerovm-cli/zpmlib/tests/test_util.py/TestAtomicFileCreator.test_context_manager_failure_case