Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / tests / test_sandbox.py @ 1a305335

History | View | Annotate | Download (1.68 KB)

1
"""develop tests
2
"""
3
import sys
4
import os
5
import shutil
6
import unittest
7
import tempfile
8

    
9
from setuptools.sandbox import DirectorySandbox, SandboxViolation
10

    
11
def has_win32com():
12
    """
13
    Run this to determine if the local machine has win32com, and if it
14
    does, include additional tests.
15
    """
16
    if not sys.platform.startswith('win32'):
17
        return False
18
    try:
19
        mod = __import__('win32com')
20
    except ImportError:
21
        return False
22
    return True
23

    
24
class TestSandbox(unittest.TestCase):
25

    
26
    def setUp(self):
27
        self.dir = tempfile.mkdtemp()
28

    
29
    def tearDown(self):
30
        shutil.rmtree(self.dir)
31

    
32
    def test_devnull(self):
33
        if sys.version < '2.4':
34
            return
35
        sandbox = DirectorySandbox(self.dir)
36
        sandbox.run(self._file_writer(os.devnull))
37

    
38
    def _file_writer(path):
39
        def do_write():
40
            f = open(path, 'w')
41
            f.write('xxx')
42
            f.close()
43
        return do_write
44

    
45
    _file_writer = staticmethod(_file_writer)
46

    
47
    if has_win32com():
48
        def test_win32com(self):
49
            """
50
            win32com should not be prevented from caching COM interfaces
51
            in gen_py.
52
            """
53
            import win32com
54
            gen_py = win32com.__gen_path__
55
            target = os.path.join(gen_py, 'test_write')
56
            sandbox = DirectorySandbox(self.dir)
57
            try:
58
                try:
59
                    sandbox.run(self._file_writer(target))
60
                except SandboxViolation:
61
                    self.fail("Could not create gen_py file due to SandboxViolation")
62
            finally:
63
                if os.path.exists(target): os.remove(target)
64

    
65
if __name__ == '__main__':
66
    unittest.main()