Python test.test_support.rmdir() Examples

The following are 30 code examples of test.test_support.rmdir(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module test.test_support , or try the search function .
Example #1
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_has_no_name(self):
        # TemporaryFile creates files with no names (on this system)
        dir = tempfile.mkdtemp()
        f = tempfile.TemporaryFile(dir=dir)
        f.write('blat')

        # Sneaky: because this file has no name, it should not prevent
        # us from removing the directory it was created in.
        try:
            os.rmdir(dir)
        except:
            ei = sys.exc_info()
            # cleanup
            f.close()
            os.rmdir(dir)
            self.failOnException("rmdir", ei) 
Example #2
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_has_no_name(self):
        # TemporaryFile creates files with no names (on this system)
        dir = tempfile.mkdtemp()
        f = tempfile.TemporaryFile(dir=dir)
        f.write('blat')

        # Sneaky: because this file has no name, it should not prevent
        # us from removing the directory it was created in.
        try:
            os.rmdir(dir)
        except:
            ei = sys.exc_info()
            # cleanup
            f.close()
            os.rmdir(dir)
            self.failOnException("rmdir", ei) 
Example #3
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_usable_template(self):
        # gettempprefix returns a usable prefix string

        # Create a temp directory, avoiding use of the prefix.
        # Then attempt to create a file whose name is
        # prefix + 'xxxxxx.xxx' in that directory.
        p = tempfile.gettempprefix() + "xxxxxx.xxx"
        d = tempfile.mkdtemp(prefix="")
        try:
            p = os.path.join(d, p)
            try:
                fd = os.open(p, os.O_RDWR | os.O_CREAT)
            except:
                self.failOnException("os.open")
            os.close(fd)
            os.unlink(p)
        finally:
            os.rmdir(d) 
Example #4
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_usable_template(self):
        # gettempprefix returns a usable prefix string

        # Create a temp directory, avoiding use of the prefix.
        # Then attempt to create a file whose name is
        # prefix + 'xxxxxx.xxx' in that directory.
        p = tempfile.gettempprefix() + "xxxxxx.xxx"
        d = tempfile.mkdtemp(prefix="")
        try:
            p = os.path.join(d, p)
            try:
                fd = os.open(p, os.O_RDWR | os.O_CREAT)
            except:
                self.failOnException("os.open")
            os.close(fd)
            os.unlink(p)
        finally:
            os.rmdir(d) 
Example #5
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_mode(self):
        # mkdtemp creates directories with the proper mode
        if not has_stat:
            return            # ugh, can't use TestSkipped.
        if support.is_jython and not os._native_posix:
            # Java doesn't support stating files for permissions
            return

        dir = self.do_create()
        try:
            mode = stat.S_IMODE(os.stat(dir).st_mode)
            mode &= 0777 # Mask off sticky bits inherited from /tmp
            expected = 0700
            if (sys.platform in ('win32', 'os2emx', 'mac') or
                support.is_jython and os._name == 'nt'):
                # There's no distinction among 'user', 'group' and 'world';
                # replicate the 'user' bits.
                user = expected >> 6
                expected = user * (1 + 8 + 64)
            self.assertEqual(mode, expected)
        finally:
            os.rmdir(dir) 
Example #6
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_mode(self):
        # mkdtemp creates directories with the proper mode
        if not has_stat:
            return            # ugh, can't use TestSkipped.
        if support.is_jython and not os._native_posix:
            # Java doesn't support stating files for permissions
            return

        dir = self.do_create()
        try:
            mode = stat.S_IMODE(os.stat(dir).st_mode)
            mode &= 0777 # Mask off sticky bits inherited from /tmp
            expected = 0700
            if (sys.platform in ('win32', 'os2emx', 'mac') or
                support.is_jython and os._name == 'nt'):
                # There's no distinction among 'user', 'group' and 'world';
                # replicate the 'user' bits.
                user = expected >> 6
                expected = user * (1 + 8 + 64)
            self.assertEqual(mode, expected)
        finally:
            os.rmdir(dir) 
Example #7
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # mkdtemp can create directories in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            os.rmdir(self.do_create(dir=dir))
        finally:
            os.rmdir(dir) 
Example #8
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # _mkstemp_inner can create files in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            self.do_create(dir=dir).write("blat")
        finally:
            os.rmdir(dir)

    # XXX: Jython can't set the write mode yet 
Example #9
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_case_sensitive(self):
        # gettempdir should not flatten its case
        # even on a case-insensitive file system
        # See CPython Issue 14255 (back-ported for Jython)
        case_sensitive_tempdir = tempfile.mkdtemp("-Temp")
        _tempdir, tempfile.tempdir = tempfile.tempdir, None
        try:
            with support.EnvironmentVarGuard() as env:
                # Fake the first env var which is checked as a candidate
                env["TMPDIR"] = case_sensitive_tempdir
                self.assertEqual(tempfile.gettempdir(), case_sensitive_tempdir)
        finally:
            tempfile.tempdir = _tempdir
            support.rmdir(case_sensitive_tempdir) 
Example #10
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # mkstemp can create directories in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            self.do_create(dir=dir)
        finally:
            os.rmdir(dir) 
Example #11
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def do_create(self, dir=None, pre="", suf=""):
        if dir is None:
            dir = tempfile.gettempdir()
        try:
            name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
        except:
            self.failOnException("mkdtemp")

        try:
            self.nameCheck(name, dir, pre, suf)
            return name
        except:
            os.rmdir(name)
            raise 
Example #12
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_basic_many(self):
        # mkdtemp can create many directories (stochastic)
        extant = range(TEST_FILES)
        try:
            for i in extant:
                extant[i] = self.do_create(pre="aa")
        finally:
            for i in extant:
                if(isinstance(i, basestring)):
                    os.rmdir(i) 
Example #13
Source File: test_mailbox.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir) 
Example #14
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        if self.dir:
            os.rmdir(self.dir)
            self.dir = None 
Example #15
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_del_on_close(self):
        # A NamedTemporaryFile is deleted when closed
        dir = tempfile.mkdtemp()
        try:
            f = tempfile.NamedTemporaryFile(dir=dir)
            f.write('blat')
            f.close()
            self.assertFalse(os.path.exists(f.name),
                        "NamedTemporaryFile %s exists after close" % f.name)
        finally:
            os.rmdir(dir) 
Example #16
Source File: test_tempfile.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_del_on_close(self):
        # A SpooledTemporaryFile is deleted when closed
        dir = tempfile.mkdtemp()
        try:
            f = tempfile.SpooledTemporaryFile(max_size=10, dir=dir)
            self.assertFalse(f._rolled)
            f.write('blat ' * 5)
            self.assertTrue(f._rolled)
            filename = f.name
            f.close()
            self.assertFalse(os.path.exists(filename),
                        "SpooledTemporaryFile %s exists after close" % filename)
        finally:
            os.rmdir(dir) 
Example #17
Source File: test_mailbox.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir) 
Example #18
Source File: test_mailbox.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir) 
Example #19
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_del_on_close(self):
        # A SpooledTemporaryFile is deleted when closed
        dir = tempfile.mkdtemp()
        try:
            f = tempfile.SpooledTemporaryFile(max_size=10, dir=dir)
            self.assertFalse(f._rolled)
            f.write('blat ' * 5)
            self.assertTrue(f._rolled)
            filename = f.name
            f.close()
            self.assertFalse(os.path.exists(filename),
                        "SpooledTemporaryFile %s exists after close" % filename)
        finally:
            os.rmdir(dir) 
Example #20
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_del_on_close(self):
        # A NamedTemporaryFile is deleted when closed
        dir = tempfile.mkdtemp()
        try:
            f = tempfile.NamedTemporaryFile(dir=dir)
            f.write('blat')
            f.close()
            self.assertFalse(os.path.exists(f.name),
                        "NamedTemporaryFile %s exists after close" % f.name)
        finally:
            os.rmdir(dir) 
Example #21
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        if self.dir:
            os.rmdir(self.dir)
            self.dir = None 
Example #22
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # mkdtemp can create directories in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            os.rmdir(self.do_create(dir=dir))
        finally:
            os.rmdir(dir) 
Example #23
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_basic_many(self):
        # mkdtemp can create many directories (stochastic)
        extant = range(TEST_FILES)
        try:
            for i in extant:
                extant[i] = self.do_create(pre="aa")
        finally:
            for i in extant:
                if(isinstance(i, basestring)):
                    os.rmdir(i) 
Example #24
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def do_create(self, dir=None, pre="", suf=""):
        if dir is None:
            dir = tempfile.gettempdir()
        try:
            name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
        except:
            self.failOnException("mkdtemp")

        try:
            self.nameCheck(name, dir, pre, suf)
            return name
        except:
            os.rmdir(name)
            raise 
Example #25
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # mkstemp can create directories in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            self.do_create(dir=dir)
        finally:
            os.rmdir(dir) 
Example #26
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_case_sensitive(self):
        # gettempdir should not flatten its case
        # even on a case-insensitive file system
        # See CPython Issue 14255 (back-ported for Jython)
        case_sensitive_tempdir = tempfile.mkdtemp("-Temp")
        _tempdir, tempfile.tempdir = tempfile.tempdir, None
        try:
            with support.EnvironmentVarGuard() as env:
                # Fake the first env var which is checked as a candidate
                env["TMPDIR"] = case_sensitive_tempdir
                self.assertEqual(tempfile.gettempdir(), case_sensitive_tempdir)
        finally:
            tempfile.tempdir = _tempdir
            support.rmdir(case_sensitive_tempdir) 
Example #27
Source File: test_tempfile.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_choose_directory(self):
        # _mkstemp_inner can create files in a user-selected directory
        dir = tempfile.mkdtemp()
        try:
            self.do_create(dir=dir).write("blat")
        finally:
            os.rmdir(dir)

    # XXX: Jython can't set the write mode yet 
Example #28
Source File: test_mailbox.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir) 
Example #29
Source File: test_mailbox.py    From oss-ftp with MIT License 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir) 
Example #30
Source File: test_mailbox.py    From BinderFilter with MIT License 5 votes vote down vote up
def tearDown(self):
        map(os.unlink, self._msgfiles)
        test_support.rmdir(os.path.join(self._dir, "cur"))
        test_support.rmdir(os.path.join(self._dir, "tmp"))
        test_support.rmdir(os.path.join(self._dir, "new"))
        test_support.rmdir(self._dir)