@@ -46,24 +46,23 @@ def ttl(key: str) -> timedelta:
46
46
def expensive_function (** kwargs : Any ) -> int :
47
47
return 1
48
48
49
- with mock .patch .object (cache , "set" , wraps = cache .set ) as m_set :
49
+ with mock .patch .object (Cache , "set" , wraps = cache .set ) as set_mock :
50
50
assert expensive_function (a = "a" ) == 1
51
51
52
- m_set .assert_called_with (mock .ANY , mock .ANY , time_to_live = timedelta (seconds = 42 ), if_not_exists = mock .ANY )
52
+ set_mock .assert_called_with (mock .ANY , mock .ANY , time_to_live = timedelta (seconds = 42 ), if_not_exists = mock .ANY )
53
53
54
54
55
55
def test_exclude (cache : Cache [int , int ]) -> None :
56
56
@cached (
57
57
cache ,
58
58
make_key = lambda _ , arg : str (arg ),
59
- exclude = lambda key_ , value_ : int ( key_ ) + value_ < 40 ,
59
+ exclude = lambda key , _ : key == "5" ,
60
60
)
61
61
def power_function (arg : int ) -> int :
62
62
return arg ** 2
63
63
64
- with mock .patch .object (cache , "set" , wraps = cache .set ):
65
- assert power_function (5 ) == 25
66
- assert power_function (6 ) == 36
64
+ assert power_function (5 ) == 25
65
+ assert power_function (6 ) == 36
67
66
68
67
assert cache .get ("5" ) is None
69
68
assert cache .get ("6" ) == 36
0 commit comments