commit | author | age
|
7f1e1e
|
1 |
import unittest |
56df90
|
2 |
import os |
bc37a5
|
3 |
from pyramid.compat import PY2 |
56df90
|
4 |
|
CM |
5 |
here = os.path.abspath(os.path.dirname(__file__)) |
7f1e1e
|
6 |
|
0c29cf
|
7 |
|
7f1e1e
|
8 |
class TestCallerPath(unittest.TestCase): |
d9a76e
|
9 |
def tearDown(self): |
dd3cc8
|
10 |
from . import test_path |
0c29cf
|
11 |
|
cba2e1
|
12 |
if hasattr(test_path, '__abspath__'): |
CM |
13 |
del test_path.__abspath__ |
d9a76e
|
14 |
|
CM |
15 |
def _callFUT(self, path, level=2): |
b60bdb
|
16 |
from pyramid.path import caller_path |
0c29cf
|
17 |
|
d9a76e
|
18 |
return caller_path(path, level) |
7f1e1e
|
19 |
|
CM |
20 |
def test_isabs(self): |
d9a76e
|
21 |
result = self._callFUT('/a/b/c') |
CM |
22 |
self.assertEqual(result, '/a/b/c') |
7f1e1e
|
23 |
|
CM |
24 |
def test_pkgrelative(self): |
|
25 |
import os |
0c29cf
|
26 |
|
d9a76e
|
27 |
result = self._callFUT('a/b/c') |
CM |
28 |
self.assertEqual(result, os.path.join(here, 'a/b/c')) |
7f1e1e
|
29 |
|
cba2e1
|
30 |
def test_memoization_has_abspath(self): |
7f1e1e
|
31 |
import os |
dd3cc8
|
32 |
from . import test_path |
0c29cf
|
33 |
|
cba2e1
|
34 |
test_path.__abspath__ = '/foo/bar' |
d9a76e
|
35 |
result = self._callFUT('a/b/c') |
CM |
36 |
self.assertEqual(result, os.path.join('/foo/bar', 'a/b/c')) |
7f1e1e
|
37 |
|
CM |
38 |
def test_memoization_success(self): |
|
39 |
import os |
dd3cc8
|
40 |
from . import test_path |
0c29cf
|
41 |
|
d9a76e
|
42 |
result = self._callFUT('a/b/c') |
CM |
43 |
self.assertEqual(result, os.path.join(here, 'a/b/c')) |
cba2e1
|
44 |
self.assertEqual(test_path.__abspath__, here) |
d9a76e
|
45 |
|
0c29cf
|
46 |
|
d9a76e
|
47 |
class TestCallerModule(unittest.TestCase): |
a56564
|
48 |
def _callFUT(self, *arg, **kw): |
b60bdb
|
49 |
from pyramid.path import caller_module |
0c29cf
|
50 |
|
a56564
|
51 |
return caller_module(*arg, **kw) |
d9a76e
|
52 |
|
CM |
53 |
def test_it_level_1(self): |
dd3cc8
|
54 |
from . import test_path |
0c29cf
|
55 |
|
d9a76e
|
56 |
result = self._callFUT(1) |
CM |
57 |
self.assertEqual(result, test_path) |
|
58 |
|
|
59 |
def test_it_level_2(self): |
dd3cc8
|
60 |
from . import test_path |
0c29cf
|
61 |
|
d9a76e
|
62 |
result = self._callFUT(2) |
CM |
63 |
self.assertEqual(result, test_path) |
|
64 |
|
|
65 |
def test_it_level_3(self): |
dd3cc8
|
66 |
from . import test_path |
0c29cf
|
67 |
|
d9a76e
|
68 |
result = self._callFUT(3) |
a1d395
|
69 |
self.assertNotEqual(result, test_path) |
5f4b80
|
70 |
|
a56564
|
71 |
def test_it_no___name__(self): |
CM |
72 |
class DummyFrame(object): |
|
73 |
f_globals = {} |
0c29cf
|
74 |
|
a56564
|
75 |
class DummySys(object): |
CM |
76 |
def _getframe(self, level): |
|
77 |
return DummyFrame() |
0c29cf
|
78 |
|
MM |
79 |
modules = {'__main__': 'main'} |
|
80 |
|
a56564
|
81 |
dummy_sys = DummySys() |
CM |
82 |
result = self._callFUT(3, sys=dummy_sys) |
|
83 |
self.assertEqual(result, 'main') |
|
84 |
|
|
85 |
|
5f4b80
|
86 |
class TestCallerPackage(unittest.TestCase): |
CM |
87 |
def _callFUT(self, *arg, **kw): |
b60bdb
|
88 |
from pyramid.path import caller_package |
0c29cf
|
89 |
|
5f4b80
|
90 |
return caller_package(*arg, **kw) |
CM |
91 |
|
|
92 |
def test_it_level_1(self): |
dd3cc8
|
93 |
import tests |
0c29cf
|
94 |
|
5f4b80
|
95 |
result = self._callFUT(1) |
CM |
96 |
self.assertEqual(result, tests) |
|
97 |
|
|
98 |
def test_it_level_2(self): |
dd3cc8
|
99 |
import tests |
0c29cf
|
100 |
|
5f4b80
|
101 |
result = self._callFUT(2) |
CM |
102 |
self.assertEqual(result, tests) |
|
103 |
|
|
104 |
def test_it_level_3(self): |
|
105 |
import unittest |
0c29cf
|
106 |
|
5f4b80
|
107 |
result = self._callFUT(3) |
CM |
108 |
self.assertEqual(result, unittest) |
|
109 |
|
|
110 |
def test_it_package(self): |
dd3cc8
|
111 |
import tests |
0c29cf
|
112 |
|
5f4b80
|
113 |
def dummy_caller_module(*arg): |
dd3cc8
|
114 |
return tests |
0c29cf
|
115 |
|
5f4b80
|
116 |
result = self._callFUT(1, caller_module=dummy_caller_module) |
dd3cc8
|
117 |
self.assertEqual(result, tests) |
0c29cf
|
118 |
|
MM |
119 |
|
d9a76e
|
120 |
class TestPackagePath(unittest.TestCase): |
CM |
121 |
def _callFUT(self, package): |
b60bdb
|
122 |
from pyramid.path import package_path |
0c29cf
|
123 |
|
d9a76e
|
124 |
return package_path(package) |
CM |
125 |
|
|
126 |
def test_it_package(self): |
dd3cc8
|
127 |
import tests |
0c29cf
|
128 |
|
d9a76e
|
129 |
package = DummyPackageOrModule(tests) |
CM |
130 |
result = self._callFUT(package) |
|
131 |
self.assertEqual(result, package.package_path) |
0c29cf
|
132 |
|
d9a76e
|
133 |
def test_it_module(self): |
dd3cc8
|
134 |
from . import test_path |
0c29cf
|
135 |
|
d9a76e
|
136 |
module = DummyPackageOrModule(test_path) |
CM |
137 |
result = self._callFUT(module) |
|
138 |
self.assertEqual(result, module.package_path) |
|
139 |
|
|
140 |
def test_memoization_success(self): |
dd3cc8
|
141 |
from . import test_path |
0c29cf
|
142 |
|
d9a76e
|
143 |
module = DummyPackageOrModule(test_path) |
9a038d
|
144 |
self._callFUT(module) |
cba2e1
|
145 |
self.assertEqual(module.__abspath__, module.package_path) |
0c29cf
|
146 |
|
7f1e1e
|
147 |
def test_memoization_fail(self): |
dd3cc8
|
148 |
from . import test_path |
0c29cf
|
149 |
|
d9a76e
|
150 |
module = DummyPackageOrModule(test_path, raise_exc=TypeError) |
CM |
151 |
result = self._callFUT(module) |
a1d395
|
152 |
self.assertFalse(hasattr(module, '__abspath__')) |
d9a76e
|
153 |
self.assertEqual(result, module.package_path) |
6efd81
|
154 |
|
0c29cf
|
155 |
|
39480c
|
156 |
class TestPackageOf(unittest.TestCase): |
CM |
157 |
def _callFUT(self, package): |
b60bdb
|
158 |
from pyramid.path import package_of |
0c29cf
|
159 |
|
39480c
|
160 |
return package_of(package) |
CM |
161 |
|
|
162 |
def test_it_package(self): |
dd3cc8
|
163 |
import tests |
0c29cf
|
164 |
|
39480c
|
165 |
package = DummyPackageOrModule(tests) |
CM |
166 |
result = self._callFUT(package) |
|
167 |
self.assertEqual(result, tests) |
|
168 |
|
|
169 |
def test_it_module(self): |
dd3cc8
|
170 |
import tests.test_path |
MM |
171 |
import tests |
0c29cf
|
172 |
|
dd3cc8
|
173 |
package = DummyPackageOrModule(tests.test_path) |
39480c
|
174 |
result = self._callFUT(package) |
CM |
175 |
self.assertEqual(result, tests) |
|
176 |
|
0c29cf
|
177 |
|
6efd81
|
178 |
class TestPackageName(unittest.TestCase): |
CM |
179 |
def _callFUT(self, package): |
b60bdb
|
180 |
from pyramid.path import package_name |
0c29cf
|
181 |
|
6efd81
|
182 |
return package_name(package) |
CM |
183 |
|
|
184 |
def test_it_package(self): |
dd3cc8
|
185 |
import tests |
0c29cf
|
186 |
|
6efd81
|
187 |
package = DummyPackageOrModule(tests) |
CM |
188 |
result = self._callFUT(package) |
dd3cc8
|
189 |
self.assertEqual(result, 'tests') |
c062d5
|
190 |
|
DH |
191 |
def test_it_namespace_package(self): |
dd3cc8
|
192 |
import tests |
0c29cf
|
193 |
|
c062d5
|
194 |
package = DummyNamespacePackage(tests) |
DH |
195 |
result = self._callFUT(package) |
dd3cc8
|
196 |
self.assertEqual(result, 'tests') |
0c29cf
|
197 |
|
6efd81
|
198 |
def test_it_module(self): |
dd3cc8
|
199 |
from . import test_path |
0c29cf
|
200 |
|
6efd81
|
201 |
module = DummyPackageOrModule(test_path) |
CM |
202 |
result = self._callFUT(module) |
dd3cc8
|
203 |
self.assertEqual(result, 'tests') |
45d08c
|
204 |
|
CM |
205 |
def test_it_None(self): |
|
206 |
result = self._callFUT(None) |
|
207 |
self.assertEqual(result, '__main__') |
d79d13
|
208 |
|
MM |
209 |
def test_it_main(self): |
|
210 |
import __main__ |
0c29cf
|
211 |
|
d79d13
|
212 |
result = self._callFUT(__main__) |
MM |
213 |
self.assertEqual(result, '__main__') |
0c29cf
|
214 |
|
56df90
|
215 |
|
078859
|
216 |
class TestResolver(unittest.TestCase): |
CM |
217 |
def _getTargetClass(self): |
|
218 |
from pyramid.path import Resolver |
0c29cf
|
219 |
|
078859
|
220 |
return Resolver |
CM |
221 |
|
|
222 |
def _makeOne(self, package): |
|
223 |
return self._getTargetClass()(package) |
|
224 |
|
|
225 |
def test_get_package_caller_package(self): |
dd3cc8
|
226 |
import tests |
078859
|
227 |
from pyramid.path import CALLER_PACKAGE |
0c29cf
|
228 |
|
MM |
229 |
self.assertEqual(self._makeOne(CALLER_PACKAGE).get_package(), tests) |
078859
|
230 |
|
CM |
231 |
def test_get_package_name_caller_package(self): |
|
232 |
from pyramid.path import CALLER_PACKAGE |
0c29cf
|
233 |
|
MM |
234 |
self.assertEqual( |
|
235 |
self._makeOne(CALLER_PACKAGE).get_package_name(), 'tests' |
|
236 |
) |
078859
|
237 |
|
CM |
238 |
def test_get_package_string(self): |
dd3cc8
|
239 |
import tests |
0c29cf
|
240 |
|
MM |
241 |
self.assertEqual(self._makeOne('tests').get_package(), tests) |
078859
|
242 |
|
CM |
243 |
def test_get_package_name_string(self): |
0c29cf
|
244 |
self.assertEqual(self._makeOne('tests').get_package_name(), 'tests') |
MM |
245 |
|
078859
|
246 |
|
56df90
|
247 |
class TestAssetResolver(unittest.TestCase): |
CM |
248 |
def _getTargetClass(self): |
|
249 |
from pyramid.path import AssetResolver |
0c29cf
|
250 |
|
56df90
|
251 |
return AssetResolver |
CM |
252 |
|
dd3cc8
|
253 |
def _makeOne(self, package='tests'): |
56df90
|
254 |
return self._getTargetClass()(package) |
CM |
255 |
|
|
256 |
def test_ctor_as_package(self): |
|
257 |
import sys |
0c29cf
|
258 |
|
dd3cc8
|
259 |
tests = sys.modules['tests'] |
56df90
|
260 |
inst = self._makeOne(tests) |
CM |
261 |
self.assertEqual(inst.package, tests) |
|
262 |
|
|
263 |
def test_ctor_as_str(self): |
|
264 |
import sys |
0c29cf
|
265 |
|
dd3cc8
|
266 |
tests = sys.modules['tests'] |
MM |
267 |
inst = self._makeOne('tests') |
56df90
|
268 |
self.assertEqual(inst.package, tests) |
CM |
269 |
|
|
270 |
def test_resolve_abspath(self): |
|
271 |
from pyramid.path import FSAssetDescriptor |
0c29cf
|
272 |
|
56df90
|
273 |
inst = self._makeOne(None) |
CM |
274 |
r = inst.resolve(os.path.join(here, 'test_asset.py')) |
|
275 |
self.assertEqual(r.__class__, FSAssetDescriptor) |
660225
|
276 |
self.assertTrue(r.exists()) |
56df90
|
277 |
|
CM |
278 |
def test_resolve_absspec(self): |
|
279 |
from pyramid.path import PkgResourcesAssetDescriptor |
0c29cf
|
280 |
|
56df90
|
281 |
inst = self._makeOne(None) |
dd3cc8
|
282 |
r = inst.resolve('tests:test_asset.py') |
56df90
|
283 |
self.assertEqual(r.__class__, PkgResourcesAssetDescriptor) |
660225
|
284 |
self.assertTrue(r.exists()) |
56df90
|
285 |
|
CM |
286 |
def test_resolve_relspec_with_pkg(self): |
|
287 |
from pyramid.path import PkgResourcesAssetDescriptor |
0c29cf
|
288 |
|
dd3cc8
|
289 |
inst = self._makeOne('tests') |
56df90
|
290 |
r = inst.resolve('test_asset.py') |
CM |
291 |
self.assertEqual(r.__class__, PkgResourcesAssetDescriptor) |
660225
|
292 |
self.assertTrue(r.exists()) |
56df90
|
293 |
|
CM |
294 |
def test_resolve_relspec_no_package(self): |
|
295 |
inst = self._makeOne(None) |
|
296 |
self.assertRaises(ValueError, inst.resolve, 'test_asset.py') |
078859
|
297 |
|
CM |
298 |
def test_resolve_relspec_caller_package(self): |
|
299 |
from pyramid.path import PkgResourcesAssetDescriptor |
|
300 |
from pyramid.path import CALLER_PACKAGE |
0c29cf
|
301 |
|
078859
|
302 |
inst = self._makeOne(CALLER_PACKAGE) |
CM |
303 |
r = inst.resolve('test_asset.py') |
|
304 |
self.assertEqual(r.__class__, PkgResourcesAssetDescriptor) |
660225
|
305 |
self.assertTrue(r.exists()) |
0c29cf
|
306 |
|
MM |
307 |
|
56df90
|
308 |
class TestPkgResourcesAssetDescriptor(unittest.TestCase): |
CM |
309 |
def _getTargetClass(self): |
|
310 |
from pyramid.path import PkgResourcesAssetDescriptor |
0c29cf
|
311 |
|
56df90
|
312 |
return PkgResourcesAssetDescriptor |
CM |
313 |
|
dd3cc8
|
314 |
def _makeOne(self, pkg='tests', path='test_asset.py'): |
56df90
|
315 |
return self._getTargetClass()(pkg, path) |
CM |
316 |
|
02ce7d
|
317 |
def test_class_conforms_to_IAssetDescriptor(self): |
56df90
|
318 |
from pyramid.interfaces import IAssetDescriptor |
CM |
319 |
from zope.interface.verify import verifyClass |
0c29cf
|
320 |
|
02ce7d
|
321 |
verifyClass(IAssetDescriptor, self._getTargetClass()) |
0c29cf
|
322 |
|
02ce7d
|
323 |
def test_instance_conforms_to_IAssetDescriptor(self): |
56df90
|
324 |
from pyramid.interfaces import IAssetDescriptor |
CM |
325 |
from zope.interface.verify import verifyObject |
0c29cf
|
326 |
|
02ce7d
|
327 |
verifyObject(IAssetDescriptor, self._makeOne()) |
56df90
|
328 |
|
CM |
329 |
def test_absspec(self): |
|
330 |
inst = self._makeOne() |
dd3cc8
|
331 |
self.assertEqual(inst.absspec(), 'tests:test_asset.py') |
56df90
|
332 |
|
CM |
333 |
def test_abspath(self): |
|
334 |
inst = self._makeOne() |
|
335 |
self.assertEqual(inst.abspath(), os.path.join(here, 'test_asset.py')) |
|
336 |
|
|
337 |
def test_stream(self): |
|
338 |
inst = self._makeOne() |
|
339 |
inst.pkg_resources = DummyPkgResource() |
|
340 |
inst.pkg_resources.resource_stream = lambda x, y: '%s:%s' % (x, y) |
fee381
|
341 |
s = inst.stream() |
0c29cf
|
342 |
self.assertEqual(s, '%s:%s' % ('tests', 'test_asset.py')) |
56df90
|
343 |
|
CM |
344 |
def test_isdir(self): |
|
345 |
inst = self._makeOne() |
|
346 |
inst.pkg_resources = DummyPkgResource() |
|
347 |
inst.pkg_resources.resource_isdir = lambda x, y: '%s:%s' % (x, y) |
0c29cf
|
348 |
self.assertEqual(inst.isdir(), '%s:%s' % ('tests', 'test_asset.py')) |
56df90
|
349 |
|
CM |
350 |
def test_listdir(self): |
|
351 |
inst = self._makeOne() |
|
352 |
inst.pkg_resources = DummyPkgResource() |
|
353 |
inst.pkg_resources.resource_listdir = lambda x, y: '%s:%s' % (x, y) |
0c29cf
|
354 |
self.assertEqual(inst.listdir(), '%s:%s' % ('tests', 'test_asset.py')) |
56df90
|
355 |
|
CM |
356 |
def test_exists(self): |
|
357 |
inst = self._makeOne() |
|
358 |
inst.pkg_resources = DummyPkgResource() |
|
359 |
inst.pkg_resources.resource_exists = lambda x, y: '%s:%s' % (x, y) |
0c29cf
|
360 |
self.assertEqual(inst.exists(), '%s:%s' % ('tests', 'test_asset.py')) |
MM |
361 |
|
56df90
|
362 |
|
CM |
363 |
class TestFSAssetDescriptor(unittest.TestCase): |
|
364 |
def _getTargetClass(self): |
|
365 |
from pyramid.path import FSAssetDescriptor |
0c29cf
|
366 |
|
56df90
|
367 |
return FSAssetDescriptor |
CM |
368 |
|
|
369 |
def _makeOne(self, path=os.path.join(here, 'test_asset.py')): |
|
370 |
return self._getTargetClass()(path) |
|
371 |
|
02ce7d
|
372 |
def test_class_conforms_to_IAssetDescriptor(self): |
56df90
|
373 |
from pyramid.interfaces import IAssetDescriptor |
CM |
374 |
from zope.interface.verify import verifyClass |
0c29cf
|
375 |
|
02ce7d
|
376 |
verifyClass(IAssetDescriptor, self._getTargetClass()) |
0c29cf
|
377 |
|
02ce7d
|
378 |
def test_instance_conforms_to_IAssetDescriptor(self): |
56df90
|
379 |
from pyramid.interfaces import IAssetDescriptor |
CM |
380 |
from zope.interface.verify import verifyObject |
0c29cf
|
381 |
|
02ce7d
|
382 |
verifyObject(IAssetDescriptor, self._makeOne()) |
56df90
|
383 |
|
CM |
384 |
def test_absspec(self): |
|
385 |
inst = self._makeOne() |
|
386 |
self.assertRaises(NotImplementedError, inst.absspec) |
|
387 |
|
|
388 |
def test_abspath(self): |
|
389 |
inst = self._makeOne() |
|
390 |
self.assertEqual(inst.abspath(), os.path.join(here, 'test_asset.py')) |
|
391 |
|
|
392 |
def test_stream(self): |
|
393 |
inst = self._makeOne() |
fee381
|
394 |
s = inst.stream() |
CM |
395 |
val = s.read() |
|
396 |
s.close() |
56df90
|
397 |
self.assertTrue(b'asset' in val) |
CM |
398 |
|
|
399 |
def test_isdir_False(self): |
|
400 |
inst = self._makeOne() |
|
401 |
self.assertFalse(inst.isdir()) |
|
402 |
|
|
403 |
def test_isdir_True(self): |
|
404 |
inst = self._makeOne(here) |
|
405 |
self.assertTrue(inst.isdir()) |
|
406 |
|
|
407 |
def test_listdir(self): |
|
408 |
inst = self._makeOne(here) |
|
409 |
self.assertTrue(inst.listdir()) |
|
410 |
|
|
411 |
def test_exists(self): |
|
412 |
inst = self._makeOne() |
|
413 |
self.assertTrue(inst.exists()) |
|
414 |
|
0c29cf
|
415 |
|
56df90
|
416 |
class TestDottedNameResolver(unittest.TestCase): |
CM |
417 |
def _makeOne(self, package=None): |
|
418 |
from pyramid.path import DottedNameResolver |
0c29cf
|
419 |
|
56df90
|
420 |
return DottedNameResolver(package) |
CM |
421 |
|
|
422 |
def config_exc(self, func, *arg, **kw): |
|
423 |
try: |
|
424 |
func(*arg, **kw) |
|
425 |
except ValueError as e: |
|
426 |
return e |
|
427 |
else: |
0c29cf
|
428 |
raise AssertionError('Invalid not raised') # pragma: no cover |
56df90
|
429 |
|
CM |
430 |
def test_zope_dottedname_style_resolve_builtin(self): |
|
431 |
typ = self._makeOne() |
bc37a5
|
432 |
if PY2: |
078859
|
433 |
result = typ._zope_dottedname_style('__builtin__.str', None) |
bc37a5
|
434 |
else: |
MM |
435 |
result = typ._zope_dottedname_style('builtins.str', None) |
56df90
|
436 |
self.assertEqual(result, str) |
CM |
437 |
|
|
438 |
def test_zope_dottedname_style_resolve_absolute(self): |
|
439 |
typ = self._makeOne() |
|
440 |
result = typ._zope_dottedname_style( |
0c29cf
|
441 |
'tests.test_path.TestDottedNameResolver', None |
MM |
442 |
) |
56df90
|
443 |
self.assertEqual(result, self.__class__) |
CM |
444 |
|
|
445 |
def test_zope_dottedname_style_irrresolveable_absolute(self): |
|
446 |
typ = self._makeOne() |
0c29cf
|
447 |
self.assertRaises( |
MM |
448 |
ImportError, |
|
449 |
typ._zope_dottedname_style, |
|
450 |
'pyramid.test_path.nonexisting_name', |
|
451 |
None, |
|
452 |
) |
56df90
|
453 |
|
CM |
454 |
def test__zope_dottedname_style_resolve_relative(self): |
dd3cc8
|
455 |
import tests |
0c29cf
|
456 |
|
078859
|
457 |
typ = self._makeOne() |
56df90
|
458 |
result = typ._zope_dottedname_style( |
0c29cf
|
459 |
'.test_path.TestDottedNameResolver', tests |
MM |
460 |
) |
56df90
|
461 |
self.assertEqual(result, self.__class__) |
CM |
462 |
|
|
463 |
def test__zope_dottedname_style_resolve_relative_leading_dots(self): |
dd3cc8
|
464 |
import tests.test_path |
0c29cf
|
465 |
|
078859
|
466 |
typ = self._makeOne() |
56df90
|
467 |
result = typ._zope_dottedname_style( |
0c29cf
|
468 |
'..tests.test_path.TestDottedNameResolver', tests |
MM |
469 |
) |
56df90
|
470 |
self.assertEqual(result, self.__class__) |
CM |
471 |
|
|
472 |
def test__zope_dottedname_style_resolve_relative_is_dot(self): |
dd3cc8
|
473 |
import tests |
0c29cf
|
474 |
|
078859
|
475 |
typ = self._makeOne() |
dd3cc8
|
476 |
result = typ._zope_dottedname_style('.', tests) |
MM |
477 |
self.assertEqual(result, tests) |
56df90
|
478 |
|
CM |
479 |
def test__zope_dottedname_style_irresolveable_relative_is_dot(self): |
|
480 |
typ = self._makeOne() |
078859
|
481 |
e = self.config_exc(typ._zope_dottedname_style, '.', None) |
56df90
|
482 |
self.assertEqual( |
0c29cf
|
483 |
e.args[0], "relative name '.' irresolveable without package" |
MM |
484 |
) |
56df90
|
485 |
|
CM |
486 |
def test_zope_dottedname_style_resolve_relative_nocurrentpackage(self): |
|
487 |
typ = self._makeOne() |
078859
|
488 |
e = self.config_exc(typ._zope_dottedname_style, '.whatever', None) |
56df90
|
489 |
self.assertEqual( |
CM |
490 |
e.args[0], |
0c29cf
|
491 |
"relative name '.whatever' irresolveable without package", |
MM |
492 |
) |
56df90
|
493 |
|
CM |
494 |
def test_zope_dottedname_style_irrresolveable_relative(self): |
dd3cc8
|
495 |
import tests |
0c29cf
|
496 |
|
078859
|
497 |
typ = self._makeOne() |
0c29cf
|
498 |
self.assertRaises( |
MM |
499 |
ImportError, typ._zope_dottedname_style, '.notexisting', tests |
|
500 |
) |
56df90
|
501 |
|
CM |
502 |
def test__zope_dottedname_style_resolveable_relative(self): |
dd3cc8
|
503 |
import tests |
0c29cf
|
504 |
|
078859
|
505 |
typ = self._makeOne() |
dd3cc8
|
506 |
result = typ._zope_dottedname_style('.', tests) |
56df90
|
507 |
self.assertEqual(result, tests) |
CM |
508 |
|
|
509 |
def test__zope_dottedname_style_irresolveable_absolute(self): |
|
510 |
typ = self._makeOne() |
|
511 |
self.assertRaises( |
0c29cf
|
512 |
ImportError, typ._zope_dottedname_style, 'pyramid.fudge.bar', None |
MM |
513 |
) |
56df90
|
514 |
|
CM |
515 |
def test__zope_dottedname_style_resolveable_absolute(self): |
|
516 |
typ = self._makeOne() |
|
517 |
result = typ._zope_dottedname_style( |
0c29cf
|
518 |
'tests.test_path.TestDottedNameResolver', None |
MM |
519 |
) |
56df90
|
520 |
self.assertEqual(result, self.__class__) |
CM |
521 |
|
|
522 |
def test__pkg_resources_style_resolve_absolute(self): |
|
523 |
typ = self._makeOne() |
|
524 |
result = typ._pkg_resources_style( |
0c29cf
|
525 |
'tests.test_path:TestDottedNameResolver', None |
MM |
526 |
) |
56df90
|
527 |
self.assertEqual(result, self.__class__) |
CM |
528 |
|
|
529 |
def test__pkg_resources_style_irrresolveable_absolute(self): |
|
530 |
typ = self._makeOne() |
0c29cf
|
531 |
self.assertRaises( |
MM |
532 |
ImportError, typ._pkg_resources_style, 'tests:nonexisting', None |
|
533 |
) |
56df90
|
534 |
|
CM |
535 |
def test__pkg_resources_style_resolve_relative(self): |
dd3cc8
|
536 |
import tests |
0c29cf
|
537 |
|
078859
|
538 |
typ = self._makeOne() |
56df90
|
539 |
result = typ._pkg_resources_style( |
0c29cf
|
540 |
'.test_path:TestDottedNameResolver', tests |
MM |
541 |
) |
56df90
|
542 |
self.assertEqual(result, self.__class__) |
CM |
543 |
|
|
544 |
def test__pkg_resources_style_resolve_relative_is_dot(self): |
dd3cc8
|
545 |
import tests |
0c29cf
|
546 |
|
078859
|
547 |
typ = self._makeOne() |
dd3cc8
|
548 |
result = typ._pkg_resources_style('.', tests) |
MM |
549 |
self.assertEqual(result, tests) |
56df90
|
550 |
|
CM |
551 |
def test__pkg_resources_style_resolve_relative_nocurrentpackage(self): |
|
552 |
typ = self._makeOne() |
0c29cf
|
553 |
self.assertRaises( |
MM |
554 |
ValueError, typ._pkg_resources_style, '.whatever', None |
|
555 |
) |
56df90
|
556 |
|
CM |
557 |
def test__pkg_resources_style_irrresolveable_relative(self): |
|
558 |
import pyramid |
0c29cf
|
559 |
|
078859
|
560 |
typ = self._makeOne() |
0c29cf
|
561 |
self.assertRaises( |
MM |
562 |
ImportError, typ._pkg_resources_style, ':notexisting', pyramid |
|
563 |
) |
56df90
|
564 |
|
CM |
565 |
def test_resolve_not_a_string(self): |
|
566 |
typ = self._makeOne() |
|
567 |
e = self.config_exc(typ.resolve, None) |
|
568 |
self.assertEqual(e.args[0], 'None is not a string') |
|
569 |
|
|
570 |
def test_resolve_using_pkgresources_style(self): |
|
571 |
typ = self._makeOne() |
0c29cf
|
572 |
result = typ.resolve('tests.test_path:TestDottedNameResolver') |
56df90
|
573 |
self.assertEqual(result, self.__class__) |
CM |
574 |
|
|
575 |
def test_resolve_using_zope_dottedname_style(self): |
|
576 |
typ = self._makeOne() |
0c29cf
|
577 |
result = typ.resolve('tests.test_path:TestDottedNameResolver') |
56df90
|
578 |
self.assertEqual(result, self.__class__) |
CM |
579 |
|
|
580 |
def test_resolve_missing_raises(self): |
|
581 |
typ = self._makeOne() |
|
582 |
self.assertRaises(ImportError, typ.resolve, 'cant.be.found') |
|
583 |
|
078859
|
584 |
def test_resolve_caller_package(self): |
CM |
585 |
from pyramid.path import CALLER_PACKAGE |
0c29cf
|
586 |
|
078859
|
587 |
typ = self._makeOne(CALLER_PACKAGE) |
0c29cf
|
588 |
self.assertEqual( |
MM |
589 |
typ.resolve('.test_path.TestDottedNameResolver'), self.__class__ |
|
590 |
) |
078859
|
591 |
|
CM |
592 |
def test_maybe_resolve_caller_package(self): |
|
593 |
from pyramid.path import CALLER_PACKAGE |
0c29cf
|
594 |
|
078859
|
595 |
typ = self._makeOne(CALLER_PACKAGE) |
0c29cf
|
596 |
self.assertEqual( |
MM |
597 |
typ.maybe_resolve('.test_path.TestDottedNameResolver'), |
|
598 |
self.__class__, |
|
599 |
) |
078859
|
600 |
|
56df90
|
601 |
def test_ctor_string_module_resolveable(self): |
dd3cc8
|
602 |
import tests |
0c29cf
|
603 |
|
dd3cc8
|
604 |
typ = self._makeOne('tests.test_path') |
MM |
605 |
self.assertEqual(typ.package, tests) |
56df90
|
606 |
|
CM |
607 |
def test_ctor_string_package_resolveable(self): |
dd3cc8
|
608 |
import tests |
0c29cf
|
609 |
|
dd3cc8
|
610 |
typ = self._makeOne('tests') |
MM |
611 |
self.assertEqual(typ.package, tests) |
56df90
|
612 |
|
CM |
613 |
def test_ctor_string_irresolveable(self): |
|
614 |
self.assertRaises(ValueError, self._makeOne, 'cant.be.found') |
|
615 |
|
|
616 |
def test_ctor_module(self): |
dd3cc8
|
617 |
import tests |
MM |
618 |
from . import test_path |
0c29cf
|
619 |
|
dd3cc8
|
620 |
typ = self._makeOne(test_path) |
MM |
621 |
self.assertEqual(typ.package, tests) |
56df90
|
622 |
|
CM |
623 |
def test_ctor_package(self): |
dd3cc8
|
624 |
import tests |
0c29cf
|
625 |
|
dd3cc8
|
626 |
typ = self._makeOne(tests) |
MM |
627 |
self.assertEqual(typ.package, tests) |
56df90
|
628 |
|
CM |
629 |
def test_ctor_None(self): |
|
630 |
typ = self._makeOne(None) |
|
631 |
self.assertEqual(typ.package, None) |
|
632 |
|
0c29cf
|
633 |
|
56df90
|
634 |
class DummyPkgResource(object): |
CM |
635 |
pass |
0c29cf
|
636 |
|
56df90
|
637 |
|
d9a76e
|
638 |
class DummyPackageOrModule: |
CM |
639 |
def __init__(self, real_package_or_module, raise_exc=None): |
|
640 |
self.__dict__['raise_exc'] = raise_exc |
|
641 |
self.__dict__['__name__'] = real_package_or_module.__name__ |
7f1e1e
|
642 |
import os |
0c29cf
|
643 |
|
d9a76e
|
644 |
self.__dict__['package_path'] = os.path.dirname( |
0c29cf
|
645 |
os.path.abspath(real_package_or_module.__file__) |
MM |
646 |
) |
6efd81
|
647 |
self.__dict__['__file__'] = real_package_or_module.__file__ |
d9a76e
|
648 |
|
CM |
649 |
def __setattr__(self, key, val): |
|
650 |
if self.raise_exc is not None: |
|
651 |
raise self.raise_exc |
|
652 |
self.__dict__[key] = val |
c062d5
|
653 |
|
0c29cf
|
654 |
|
c062d5
|
655 |
class DummyNamespacePackage: |
DH |
656 |
"""Has no __file__ attribute. |
|
657 |
""" |
0c29cf
|
658 |
|
c062d5
|
659 |
def __init__(self, real_package_or_module): |
DH |
660 |
self.__name__ = real_package_or_module.__name__ |
|
661 |
import os |
0c29cf
|
662 |
|
c062d5
|
663 |
self.package_path = os.path.dirname( |
0c29cf
|
664 |
os.path.abspath(real_package_or_module.__file__) |
MM |
665 |
) |