11from typing import List , Union
2- from unittest .mock import MagicMock
2+ from unittest .mock import patch
33
44import pytest
55from ldclient import Config , LDClient
@@ -25,13 +25,13 @@ def evaluation_context() -> EvaluationContext:
2525
2626
2727@pytest .fixture
28- def ld_client (test_data_source : TestData ) -> LDClient :
29- return LDClient ( config = Config ("example-key" , update_processor_class = test_data_source , send_events = False ) )
28+ def config (test_data_source : TestData ) -> Config :
29+ return Config ("example-key" , update_processor_class = test_data_source , send_events = False )
3030
3131
3232@pytest .fixture
33- def provider (ld_client ) -> LaunchDarklyProvider :
34- return LaunchDarklyProvider (ld_client )
33+ def provider (config ) -> LaunchDarklyProvider :
34+ return LaunchDarklyProvider (config )
3535
3636
3737def test_metadata_name_is_correct (provider : LaunchDarklyProvider ):
@@ -56,11 +56,10 @@ def test_evaluation_results_are_converted_to_details(provider: LaunchDarklyProvi
5656 assert resolution_details .error_code is None
5757
5858
59- def test_evaluation_error_results_are_converted_correctly (ld_client : LDClient , provider : LaunchDarklyProvider , evaluation_context : EvaluationContext ):
59+ def test_evaluation_error_results_are_converted_correctly (provider : LaunchDarklyProvider , evaluation_context : EvaluationContext ):
6060 detail = EvaluationDetail (True , None , {'kind' : 'ERROR' , 'errorKind' : 'CLIENT_NOT_READY' })
61- ld_client .variation_detail = MagicMock (return_value = detail ) # type: ignore[method-assign]
62-
63- resolution_details = provider .resolve_boolean_details ("flag-key" , True , evaluation_context )
61+ with patch .object (LDClient , 'variation_detail' , lambda self , _key , _context , _default : detail ):
62+ resolution_details = provider .resolve_boolean_details ("flag-key" , True , evaluation_context )
6463
6564 assert resolution_details .value is True
6665 assert resolution_details .reason == Reason .ERROR
@@ -113,14 +112,13 @@ def test_check_method_and_result_match_type(
113112 expected_value : Union [bool , str , int , float , List ],
114113 method_name : str ,
115114 # end of parameterized values
116- ld_client : LDClient ,
115+ test_data_source : TestData ,
117116 provider : LaunchDarklyProvider ,
118117 evaluation_context : EvaluationContext ):
119- detail = EvaluationDetail (return_value , 1 , {'kind' : 'FALLTHROUGH' })
120- ld_client .variation_detail = MagicMock (return_value = detail ) # type: ignore[method-assign]
118+ test_data_source .update (test_data_source .flag ("check-method-flag" ).variations (return_value ).variation_for_all (0 ))
121119
122120 method = getattr (provider , method_name )
123- resolution_details = method ("flag-key " , default_value , evaluation_context )
121+ resolution_details = method ("check-method-flag " , default_value , evaluation_context )
124122
125123 assert resolution_details .value == expected_value
126124
0 commit comments