@@ -34,37 +34,6 @@ def test_is_enabled(sentry_init, capture_events, uninstall_integration):
3434 }
3535
3636
37- def test_get_variant (sentry_init , capture_events , uninstall_integration ):
38- uninstall_integration (UnleashIntegration .identifier )
39-
40- with mock_unleash_client ():
41- client = UnleashClient () # type: ignore[arg-type]
42- sentry_init (integrations = [UnleashIntegration ()])
43- client .get_variant ("no_payload_feature" )
44- client .get_variant ("no_variant_feature" )
45- client .get_variant ("string_feature" )
46- client .get_variant ("json_feature" )
47- client .get_variant ("csv_feature" )
48- client .get_variant ("number_feature" )
49- client .get_variant ("unknown_feature" )
50-
51- events = capture_events ()
52- sentry_sdk .capture_exception (Exception ("something wrong!" ))
53-
54- assert len (events ) == 1
55- assert events [0 ]["contexts" ]["flags" ] == {
56- "values" : [
57- {"flag" : "no_payload_feature" , "result" : True },
58- {"flag" : "no_variant_feature" , "result" : True },
59- {"flag" : "string_feature" , "result" : True },
60- {"flag" : "json_feature" , "result" : True },
61- {"flag" : "csv_feature" , "result" : True },
62- {"flag" : "number_feature" , "result" : True },
63- {"flag" : "unknown_feature" , "result" : False },
64- ]
65- }
66-
67-
6837def test_is_enabled_threaded (sentry_init , capture_events , uninstall_integration ):
6938 uninstall_integration (UnleashIntegration .identifier )
7039
@@ -114,55 +83,6 @@ def task(flag_key):
11483 }
11584
11685
117- def test_get_variant_threaded (sentry_init , capture_events , uninstall_integration ):
118- uninstall_integration (UnleashIntegration .identifier )
119-
120- with mock_unleash_client ():
121- client = UnleashClient () # type: ignore[arg-type]
122- sentry_init (integrations = [UnleashIntegration ()])
123- events = capture_events ()
124-
125- def task (flag_key ):
126- # Creates a new isolation scope for the thread.
127- # This means the evaluations in each task are captured separately.
128- with sentry_sdk .isolation_scope ():
129- client .get_variant (flag_key )
130- # use a tag to identify to identify events later on
131- sentry_sdk .set_tag ("task_id" , flag_key )
132- sentry_sdk .capture_exception (Exception ("something wrong!" ))
133-
134- # Capture an eval before we split isolation scopes.
135- client .get_variant ("hello" )
136-
137- with cf .ThreadPoolExecutor (max_workers = 2 ) as pool :
138- pool .map (task , ["no_payload_feature" , "other" ])
139-
140- # Capture error in original scope
141- sentry_sdk .set_tag ("task_id" , "0" )
142- sentry_sdk .capture_exception (Exception ("something wrong!" ))
143-
144- assert len (events ) == 3
145- events .sort (key = lambda e : e ["tags" ]["task_id" ])
146-
147- assert events [0 ]["contexts" ]["flags" ] == {
148- "values" : [
149- {"flag" : "hello" , "result" : False },
150- ]
151- }
152- assert events [1 ]["contexts" ]["flags" ] == {
153- "values" : [
154- {"flag" : "hello" , "result" : False },
155- {"flag" : "no_payload_feature" , "result" : True },
156- ]
157- }
158- assert events [2 ]["contexts" ]["flags" ] == {
159- "values" : [
160- {"flag" : "hello" , "result" : False },
161- {"flag" : "other" , "result" : False },
162- ]
163- }
164-
165-
16686@pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "requires python3.7 or higher" )
16787def test_is_enabled_asyncio (sentry_init , capture_events , uninstall_integration ):
16888 asyncio = pytest .importorskip ("asyncio" )
@@ -214,66 +134,12 @@ async def runner():
214134 }
215135
216136
217- @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "requires python3.7 or higher" )
218- def test_get_variant_asyncio (sentry_init , capture_events , uninstall_integration ):
219- asyncio = pytest .importorskip ("asyncio" )
220-
221- uninstall_integration (UnleashIntegration .identifier )
222-
223- with mock_unleash_client ():
224- client = UnleashClient () # type: ignore[arg-type]
225- sentry_init (integrations = [UnleashIntegration ()])
226- events = capture_events ()
227-
228- async def task (flag_key ):
229- with sentry_sdk .isolation_scope ():
230- client .get_variant (flag_key )
231- # use a tag to identify to identify events later on
232- sentry_sdk .set_tag ("task_id" , flag_key )
233- sentry_sdk .capture_exception (Exception ("something wrong!" ))
234-
235- async def runner ():
236- return asyncio .gather (task ("no_payload_feature" ), task ("other" ))
237-
238- # Capture an eval before we split isolation scopes.
239- client .get_variant ("hello" )
240-
241- asyncio .run (runner ())
242-
243- # Capture error in original scope
244- sentry_sdk .set_tag ("task_id" , "0" )
245- sentry_sdk .capture_exception (Exception ("something wrong!" ))
246-
247- assert len (events ) == 3
248- events .sort (key = lambda e : e ["tags" ]["task_id" ])
249-
250- assert events [0 ]["contexts" ]["flags" ] == {
251- "values" : [
252- {"flag" : "hello" , "result" : False },
253- ]
254- }
255- assert events [1 ]["contexts" ]["flags" ] == {
256- "values" : [
257- {"flag" : "hello" , "result" : False },
258- {"flag" : "no_payload_feature" , "result" : True },
259- ]
260- }
261- assert events [2 ]["contexts" ]["flags" ] == {
262- "values" : [
263- {"flag" : "hello" , "result" : False },
264- {"flag" : "other" , "result" : False },
265- ]
266- }
267-
268-
269137def test_wraps_original (sentry_init , uninstall_integration ):
270138 with mock_unleash_client ():
271139 client = UnleashClient () # type: ignore[arg-type]
272140
273141 mock_is_enabled = mock .Mock (return_value = random () < 0.5 )
274- mock_get_variant = mock .Mock (return_value = {"enabled" : random () < 0.5 })
275142 client .is_enabled = mock_is_enabled
276- client .get_variant = mock_get_variant
277143
278144 uninstall_integration (UnleashIntegration .identifier )
279145 sentry_init (integrations = [UnleashIntegration ()]) # type: ignore
@@ -285,26 +151,16 @@ def test_wraps_original(sentry_init, uninstall_integration):
285151 {"kwarg" : 1 },
286152 )
287153
288- res = client .get_variant ("test-flag" , "arg" , kwarg = 1 )
289- assert res == mock_get_variant .return_value
290- assert mock_get_variant .call_args == (
291- ("test-flag" , "arg" ),
292- {"kwarg" : 1 },
293- )
294-
295154
296155def test_wrapper_attributes (sentry_init , uninstall_integration ):
297156 with mock_unleash_client ():
298157 client = UnleashClient () # type: ignore[arg-type]
299158
300159 original_is_enabled = client .is_enabled
301- original_get_variant = client .get_variant
302160
303161 uninstall_integration (UnleashIntegration .identifier )
304162 sentry_init (integrations = [UnleashIntegration ()]) # type: ignore
305163
306164 # Mock clients methods have not lost their qualified names after decoration.
307165 assert client .is_enabled .__name__ == "is_enabled"
308166 assert client .is_enabled .__qualname__ == original_is_enabled .__qualname__
309- assert client .get_variant .__name__ == "get_variant"
310- assert client .get_variant .__qualname__ == original_get_variant .__qualname__
0 commit comments