@@ -25,19 +25,26 @@ def target():
2525exec_ (OBJECTS_CODE , objects .__dict__ , objects .__dict__ )
2626
2727
28- @pytest .fixture (scope = "module" , params = ["pure-python" , "c-extension" ])
28+ @pytest .fixture (scope = "module" , params = [
29+ "slots" , "cext" ,
30+ # "external-django", "external-objproxies"
31+ ])
2932def lazy_object_proxy (request ):
3033 class mod :
31- if request .param == "pure-python " :
32- from lazy_object_proxy .proxy import Proxy
33- elif request .param == "c-extension " :
34+ if request .param == "slots " :
35+ from lazy_object_proxy .slots import Proxy
36+ elif request .param == "cext " :
3437 try :
35- from lazy_object_proxy ._proxy import Proxy
38+ from lazy_object_proxy .cext import Proxy
3639 except ImportError :
3740 if PYPY :
3841 pytest .skip (msg = "C Extension not available." )
3942 else :
4043 raise
44+ elif request .param == "external-objproxies" :
45+ Proxy = pytest .importorskip ("objproxies" ).LazyProxy
46+ elif request .param == "external-django" :
47+ Proxy = pytest .importorskip ("django.utils.functional" ).SimpleLazyObject
4148 else :
4249 raise RuntimeError ("Unsupported param: %r." % request .param )
4350
@@ -73,7 +80,7 @@ def function1(*args, **kwargs):
7380 function2 = lazy_object_proxy .Proxy (lambda : function1 )
7481
7582 assert function2 == function1
76- assert function2 .__wrapped__ == function1
83+ assert function2 .__wrapped__ is function1
7784 assert function2 .__name__ == function1 .__name__
7885
7986 if PY3 :
@@ -84,7 +91,7 @@ def function1(*args, **kwargs):
8491 assert not hasattr (function1 , '__wrapped__' )
8592
8693 assert function2 == None
87- assert function2 .__wrapped__ == None
94+ assert function2 .__wrapped__ is None
8895 assert not hasattr (function2 , '__name__' )
8996
9097 if PY3 :
@@ -1555,7 +1562,6 @@ def test_proxy_is_callable(lazy_object_proxy):
15551562 assert not callable (proxy )
15561563
15571564
1558- @skipcallable
15591565def test_callable_proxy_hasattr_call (lazy_object_proxy ):
15601566 proxy = lazy_object_proxy .Proxy (lambda : None )
15611567
@@ -1569,7 +1575,6 @@ def test_callable_proxy_getattr_call(lazy_object_proxy):
15691575 assert getattr (proxy , '__call__' , None ) is None
15701576
15711577
1572- @skipcallable
15731578def test_callable_proxy_is_callable (lazy_object_proxy ):
15741579 proxy = lazy_object_proxy .Proxy (lambda : None )
15751580
@@ -1625,29 +1630,34 @@ def test_fractions_round(lazy_object_proxy):
16251630 assert round (instance ) == round (proxy )
16261631
16271632
1633+ def test_readonly (lazy_object_proxy ):
1634+ proxy = lazy_object_proxy .Proxy (lambda : object )
1635+ assert proxy .__qualname__ .endswith ('object' )
1636+
16281637def test_new (lazy_object_proxy ):
16291638 a = lazy_object_proxy .Proxy .__new__ (lazy_object_proxy .Proxy )
16301639 b = lazy_object_proxy .Proxy .__new__ (lazy_object_proxy .Proxy )
16311640 # NOW KISS
1632- pytest .raises (ValueError , lambda : a .__wrapped__ )
16331641 pytest .raises (ValueError , lambda : a + b )
16341642 # no segfault, yay
1643+ pytest .raises (ValueError , lambda : a .__wrapped__ )
16351644
16361645
16371646def test_lazy_object_proxy (lazy_object_proxy , benchmark ):
16381647 obj = "foobar"
16391648 proxied = lazy_object_proxy .Proxy (lambda : obj )
16401649 with benchmark :
1641- result = str ( proxied )
1650+ result = "%s" % proxied
16421651 assert result == obj
16431652
16441653
16451654def test_django_simplelazyobject (benchmark ):
1655+ from django .utils .functional import SimpleLazyObject
16461656 SimpleLazyObject = pytest .importorskip ("django.utils.functional" ).SimpleLazyObject
16471657 obj = "foobar"
16481658 proxied = SimpleLazyObject (lambda : obj )
16491659 with benchmark :
1650- result = str ( proxied )
1660+ result = "%s" % proxied
16511661 assert result == obj
16521662
16531663
@@ -1656,6 +1666,5 @@ def test_objproxies(benchmark):
16561666 obj = "foobar"
16571667 proxied = LazyProxy (lambda : obj )
16581668 with benchmark :
1659- result = str ( proxied )
1669+ result = "%s" % proxied
16601670 assert result == obj
1661-
0 commit comments