Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/setuptools/tests/test_sandbox.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 """develop tests | |
2 """ | |
3 import os | |
4 import types | |
5 | |
6 import pytest | |
7 | |
8 import pkg_resources | |
9 import setuptools.sandbox | |
10 from setuptools.sandbox import DirectorySandbox | |
11 | |
12 | |
13 class TestSandbox: | |
14 | |
15 def test_devnull(self, tmpdir): | |
16 sandbox = DirectorySandbox(str(tmpdir)) | |
17 sandbox.run(self._file_writer(os.devnull)) | |
18 | |
19 @staticmethod | |
20 def _file_writer(path): | |
21 def do_write(): | |
22 with open(path, 'w') as f: | |
23 f.write('xxx') | |
24 return do_write | |
25 | |
26 def test_win32com(self, tmpdir): | |
27 """ | |
28 win32com should not be prevented from caching COM interfaces | |
29 in gen_py. | |
30 """ | |
31 win32com = pytest.importorskip('win32com') | |
32 gen_py = win32com.__gen_path__ | |
33 target = os.path.join(gen_py, 'test_write') | |
34 sandbox = DirectorySandbox(str(tmpdir)) | |
35 try: | |
36 # attempt to create gen_py file | |
37 sandbox.run(self._file_writer(target)) | |
38 finally: | |
39 if os.path.exists(target): | |
40 os.remove(target) | |
41 | |
42 def test_setup_py_with_BOM(self): | |
43 """ | |
44 It should be possible to execute a setup.py with a Byte Order Mark | |
45 """ | |
46 target = pkg_resources.resource_filename(__name__, | |
47 'script-with-bom.py') | |
48 namespace = types.ModuleType('namespace') | |
49 setuptools.sandbox._execfile(target, vars(namespace)) | |
50 assert namespace.result == 'passed' | |
51 | |
52 def test_setup_py_with_CRLF(self, tmpdir): | |
53 setup_py = tmpdir / 'setup.py' | |
54 with setup_py.open('wb') as stream: | |
55 stream.write(b'"degenerate script"\r\n') | |
56 setuptools.sandbox._execfile(str(setup_py), globals()) | |
57 | |
58 | |
59 class TestExceptionSaver: | |
60 def test_exception_trapped(self): | |
61 with setuptools.sandbox.ExceptionSaver(): | |
62 raise ValueError("details") | |
63 | |
64 def test_exception_resumed(self): | |
65 with setuptools.sandbox.ExceptionSaver() as saved_exc: | |
66 raise ValueError("details") | |
67 | |
68 with pytest.raises(ValueError) as caught: | |
69 saved_exc.resume() | |
70 | |
71 assert isinstance(caught.value, ValueError) | |
72 assert str(caught.value) == 'details' | |
73 | |
74 def test_exception_reconstructed(self): | |
75 orig_exc = ValueError("details") | |
76 | |
77 with setuptools.sandbox.ExceptionSaver() as saved_exc: | |
78 raise orig_exc | |
79 | |
80 with pytest.raises(ValueError) as caught: | |
81 saved_exc.resume() | |
82 | |
83 assert isinstance(caught.value, ValueError) | |
84 assert caught.value is not orig_exc | |
85 | |
86 def test_no_exception_passes_quietly(self): | |
87 with setuptools.sandbox.ExceptionSaver() as saved_exc: | |
88 pass | |
89 | |
90 saved_exc.resume() | |
91 | |
92 def test_unpickleable_exception(self): | |
93 class CantPickleThis(Exception): | |
94 "This Exception is unpickleable because it's not in globals" | |
95 | |
96 with setuptools.sandbox.ExceptionSaver() as saved_exc: | |
97 raise CantPickleThis('detail') | |
98 | |
99 with pytest.raises(setuptools.sandbox.UnpickleableException) as caught: | |
100 saved_exc.resume() | |
101 | |
102 assert str(caught.value) == "CantPickleThis('detail',)" |