MCPcopy
hub / github.com/django/django / test_touch

Method test_touch

tests/cache/tests.py:1882–1902  ·  view source on GitHub ↗

Override to manually advance time since file access can be slow.

(self)

Source from the content-addressed store, hash-verified

1880 mocked_open.assert_called_once()
1881
1882 def test_touch(self):
1883 """Override to manually advance time since file access can be slow."""
1884
1885 class ManualTickingTime:
1886 def __init__(self):
1887 # Freeze time, calling `sleep` will manually advance it.
1888 self._time = time.time()
1889
1890 def time(self):
1891 return self._time
1892
1893 def sleep(self, seconds):
1894 self._time += seconds
1895
1896 mocked_time = ManualTickingTime()
1897 with (
1898 mock.patch("django.core.cache.backends.filebased.time", new=mocked_time),
1899 mock.patch("django.core.cache.backends.base.time", new=mocked_time),
1900 mock.patch("cache.tests.time", new=mocked_time),
1901 ):
1902 super().test_touch()
1903
1904
1905@unittest.skipUnless(RedisCache_params, "Redis backend not configured")

Callers

nothing calls this directly

Calls 3

ManualTickingTimeClass · 0.85
patchMethod · 0.45
test_touchMethod · 0.45

Tested by

no test coverage detected