@@ 394-408 (lines=15) @@ | ||
391 | assert Test.ns.meta_var == 1 |
|
392 | assert Test.ns.cls_var == 2 |
|
393 | assert Test().ns.cls_var == 2 |
|
394 | with pytest.raises(AttributeError): |
|
395 | Test().ns.meta_var |
|
396 | with pytest.raises(AttributeError): |
|
397 | Test.ns.var |
|
398 | with pytest.raises(AttributeError): |
|
399 | Meta.ns.cls_var |
|
400 | Test.var = 3 |
|
401 | assert Test.var == 3 |
|
402 | Meta.var = 4 |
|
403 | assert Meta.var == 4 |
|
404 | ||
405 | ||
406 | def test_classmethod_basic(namespaces): |
|
407 | class Test(namespaces.Namespaceable): |
|
408 | with namespaces.Namespace() as ns: |
|
409 | @classmethod |
|
410 | def cls_mthd(cls): |
|
411 | return 'called' |
|
@@ 319-330 (lines=12) @@ | ||
316 | assert test.ns.foo == 2 |
|
317 | del test.ns.foo |
|
318 | assert test.ns.foo() == 1 |
|
319 | Test.ns.foo = 3 |
|
320 | assert Test.ns.foo == 3 |
|
321 | assert test.ns.foo == 3 |
|
322 | ||
323 | ||
324 | def test_can_t_preload_with_namespace(namespaces): |
|
325 | with pytest.raises(ValueError): |
|
326 | namespaces.Namespace(ns=namespaces.Namespace()) |
|
327 | ||
328 | ||
329 | def test_add_later(namespaces): |
|
330 | class Test(namespaces.Namespaceable): |
|
331 | pass |
|
332 | ||
333 | ns = namespaces.Namespace() |
|
@@ 206-218 (lines=13) @@ | ||
203 | bar = 1 |
|
204 | assert not hasattr(DoubleSubclass().ns, 'foo') |
|
205 | ||
206 | ||
207 | def test_overlap(namespaces): |
|
208 | class Test(namespaces.Namespaceable): |
|
209 | with namespaces.Namespace() as ns: |
|
210 | foo = 2 |
|
211 | ||
212 | class Subclass(Test): |
|
213 | with namespaces.Namespace() as ns: |
|
214 | bar = 3 |
|
215 | assert Subclass().ns.foo == 2 |
|
216 | assert Subclass().ns.bar == 3 |
|
217 | ||
218 | ||
219 | def test_advanced_overlap(namespaces): |
|
220 | class Test(namespaces.Namespaceable): |
|
221 | with namespaces.Namespace() as ns: |