testing/mozbase/mozfile/tests/test_tempdir.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/env python
     3 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this
     5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 """
     8 tests for mozfile.TemporaryDirectory
     9 """
    11 from mozfile import TemporaryDirectory
    12 import os
    13 import unittest
    16 class TestTemporaryDirectory(unittest.TestCase):
    18     def test_removed(self):
    19         """ensure that a TemporaryDirectory gets removed"""
    20         path = None
    21         with TemporaryDirectory() as tmp:
    22             path = tmp
    23             self.assertTrue(os.path.isdir(tmp))
    24             tmpfile = os.path.join(tmp, "a_temp_file")
    25             open(tmpfile, "w").write("data")
    26             self.assertTrue(os.path.isfile(tmpfile))
    27         self.assertFalse(os.path.isdir(path))
    28         self.assertFalse(os.path.exists(path))
    30     def test_exception(self):
    31         """ensure that TemporaryDirectory handles exceptions"""
    32         path = None
    33         with self.assertRaises(Exception):
    34             with TemporaryDirectory() as tmp:
    35                 path = tmp
    36                 self.assertTrue(os.path.isdir(tmp))
    37                 raise Exception("oops")
    38         self.assertFalse(os.path.isdir(path))
    39         self.assertFalse(os.path.exists(path))
    41 if __name__ == '__main__':
    42     unittest.main()

mercurial