MCPcopy Create free account
hub / github.com/rthalley/dnspython / FakeTime

Class FakeTime

tests/test_resolver.py:194–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193
194class FakeTime:
195 # Mock the clock!
196 def __init__(self, now=None, want_fake=True):
197 if now is None:
198 now = time.time()
199 self.now = now
200 self.saved_time = time.time
201 self.want_fake = want_fake
202
203 def __enter__(self):
204 if self.want_fake:
205 time.time = self.time
206 return self
207
208 def __exit__(self, exc_type, exc_value, traceback):
209 if self.want_fake:
210 time.time = self.saved_time
211 return False
212
213 def time(self):
214 if self.want_fake:
215 return self.now
216 else:
217 return time.time()
218
219 def sleep(self, offset):
220 if self.want_fake:
221 self.now += offset
222 else:
223 time.sleep(offset)
224
225
226class BaseResolverTests(unittest.TestCase):

Callers 4

testCacheExpirationMethod · 0.85
testCacheCleaningMethod · 0.85
testCacheNonCleaningMethod · 0.85
testLRUExpirationMethod · 0.85

Calls

no outgoing calls

Tested by 4

testCacheExpirationMethod · 0.68
testCacheCleaningMethod · 0.68
testCacheNonCleaningMethod · 0.68
testLRUExpirationMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…