@@ 106-127 (lines=22) @@ | ||
103 | assert proxy(2) == 2 + VALUE + 1 |
|
104 | ||
105 | ||
106 | def test_proxy_as_instance(): |
|
107 | from typing import Callable |
|
108 | ||
109 | from software_patterns import Proxy |
|
110 | ||
111 | RemoteCall = Callable[[int], int] |
|
112 | ||
113 | remote_call: RemoteCall = lambda x: x + 1 |
|
114 | ||
115 | # Code that the developer writes |
|
116 | VALUE = 10 |
|
117 | ||
118 | class ClientProxy(Proxy[RemoteCall]): |
|
119 | def __call__(self, x: int): |
|
120 | return self._proxy_subject(x + VALUE) |
|
121 | ||
122 | proxy: ClientProxy = ClientProxy(remote_call) |
|
123 | ||
124 | assert remote_call(2) == 2 + 1 |
|
125 | assert proxy(2) == 2 + VALUE + 1 |
|
126 | ||
127 | assert hash(proxy) == hash(remote_call) |
|
128 | ||
129 | ||
130 | def test_mapping_proxy(): |
|
@@ 85-103 (lines=19) @@ | ||
82 | assert result == 'ClientSubject' |
|
83 | ||
84 | ||
85 | def test_simple_proxy(): |
|
86 | from typing import Callable |
|
87 | ||
88 | from software_patterns import Proxy |
|
89 | ||
90 | RemoteCall = Callable[[int], int] |
|
91 | remote_call: RemoteCall = lambda x: x + 1 |
|
92 | ||
93 | # Code that the developer writes |
|
94 | VALUE = 10 |
|
95 | ||
96 | class ClientProxy(Proxy[RemoteCall]): |
|
97 | def __call__(self, x: int): |
|
98 | return self._proxy_subject(x + VALUE) |
|
99 | ||
100 | proxy: ClientProxy = ClientProxy(remote_call) |
|
101 | ||
102 | assert remote_call(2) == 2 + 1 |
|
103 | assert proxy(2) == 2 + VALUE + 1 |
|
104 | ||
105 | ||
106 | def test_proxy_as_instance(): |