brintos

brintos / llvm-project-archived public Read only

0
0
Text · 993 B · 22e8c2a Raw
30 lines · python
1# -*- coding: utf-8 -*-2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3# See https://llvm.org/LICENSE.txt for license information.4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5 6import libear as sut7import unittest8import os.path9 10 11class TemporaryDirectoryTest(unittest.TestCase):12    def test_creates_directory(self):13        dirname = None14        with sut.TemporaryDirectory() as tmpdir:15            self.assertTrue(os.path.isdir(tmpdir))16            dirname = tmpdir17        self.assertIsNotNone(dirname)18        self.assertFalse(os.path.exists(dirname))19 20    def test_removes_directory_when_exception(self):21        dirname = None22        try:23            with sut.TemporaryDirectory() as tmpdir:24                self.assertTrue(os.path.isdir(tmpdir))25                dirname = tmpdir26                raise RuntimeError("message")27        except:28            self.assertIsNotNone(dirname)29            self.assertFalse(os.path.exists(dirname))30