Home | History | Annotate | Download | only in unit
      1 # -*- coding: utf-8 -*-
      2 #                     The LLVM Compiler Infrastructure
      3 #
      4 # This file is distributed under the University of Illinois Open Source
      5 # License. See LICENSE.TXT for details.
      6 
      7 import libear as sut
      8 import unittest
      9 import os.path
     10 
     11 
     12 class TemporaryDirectoryTest(unittest.TestCase):
     13     def test_creates_directory(self):
     14         dirname = None
     15         with sut.TemporaryDirectory() as tmpdir:
     16             self.assertTrue(os.path.isdir(tmpdir))
     17             dirname = tmpdir
     18         self.assertIsNotNone(dirname)
     19         self.assertFalse(os.path.exists(dirname))
     20 
     21     def test_removes_directory_when_exception(self):
     22         dirname = None
     23         try:
     24             with sut.TemporaryDirectory() as tmpdir:
     25                 self.assertTrue(os.path.isdir(tmpdir))
     26                 dirname = tmpdir
     27                 raise RuntimeError('message')
     28         except:
     29             self.assertIsNotNone(dirname)
     30             self.assertFalse(os.path.exists(dirname))
     31