File: test_tmpdir.py

package info (click to toggle)
sphinx-testing 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: python: 734; makefile: 8; sh: 7
file content (62 lines) | stat: -rw-r--r-- 1,548 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-

import sys
import shutil
from sphinx_testing.path import path
from sphinx_testing.tmpdir import mkdtemp, with_tmpdir

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest


class TestTmpdir(unittest.TestCase):
    def test_mkdtemp(self):
        try:
            tmpdir = mkdtemp()
            self.assertIsInstance(tmpdir, path)
        finally:
            shutil.rmtree(tmpdir)

        # prefix option
        try:
            tmpdir = mkdtemp(prefix='sphinx')
            self.assertTrue(tmpdir.basename().startswith('sphinx'))
        finally:
            tmpdir.rmtree()

        # suffix option
        try:
            tmpdir = mkdtemp(suffix='sphinx')
            self.assertTrue(tmpdir.basename().endswith('sphinx'))
        finally:
            tmpdir.rmtree()

        # dir option
        try:
            parent = mkdtemp()
            tmpdir = mkdtemp(dir=parent)
            self.assertTrue(parent, tmpdir.dirname())
        finally:
            parent.rmtree()

    def test_with_tmpdir(self):
        @with_tmpdir
        def testcase1(tmpdir):
            self.assertTrue(tmpdir.isdir())
            return tmpdir

        tmpdir = testcase1()
        self.assertFalse(tmpdir.isdir())

        @with_tmpdir
        def testcase2(tmpdir):
            self.assertTrue(tmpdir.isdir())
            raise Exception(tmpdir)

        try:
            testcase2()
        except Exception as exc:
            tmpdir = exc.args[0]
            self.assertFalse(tmpdir.isdir())