CodeSampleX

샘플

freezegun 1.5.5: Freeze the clock in a Python test with freezegun so datetime, time.time and time.monotonic agree, and know what freeze_time cannot reach

검증된 샘플 — pypi freezegun 1.5.5: Freeze the clock in a Python test with freezegun so datetime, time.time and time.monotonic agree, and know what freeze_time…

sha256:e0a5abccbe96dde0a46b9b65aae94c3d5ffaa94f5eac58c72b82bec2141a0bfa

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 python 3.12 linux x64 python 3.12 python pip

검증 실행 환경

환경 컨트랙트 단계 실행일
python 3.12 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-14
python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-18

케이스

HOW
목표
Freeze the clock in a Python test with freezegun so datetime, time.time and time.monotonic agree, and know what freeze_time cannot reach
패키지
심벌
  • freezegun.freeze_time
  • FrozenDateTimeFactory.tick
  • FrozenDateTimeFactory.move_to
  • tz_offset
  • datetime.datetime.now
  • datetime.datetime.utcnow
  • datetime.date.today
  • time.time
  • time.monotonic
  • time.perf_counter
환경
python 3.12
생성일
2026-08-14T13:20:26Z

컨트랙트

  1. assert freeze_time as a context manager pins datetime.now(), datetime.utcnow(), time.time(), time.time_ns() and date.today() to one instant that does not tick between reads
  2. assert the frozen readings agree with each other, so datetime.now().timestamp() is exactly time.time()
  3. assert a module that did `from datetime import datetime` before the freeze is frozen too, because freeze_time rebinds the name that module already holds
  4. assert freeze_time rewrites the test file's own globals as well, so a bare handle kept for comparison becomes the fake class and compares equal to it
  5. assert a bound classmethod captured at import (now = datetime.now) escapes the sweep and keeps returning real time inside the freeze
  6. assert a module-level constant computed at import (DEFAULT_START = datetime.now()) keeps its real value and its real class, and still passes isinstance against the frozen datetime
  7. assert a duration measured against that stale constant comes out negative by more than twenty-five years with nothing raised
  8. assert a datetime subclass defined at import ignores the freeze in now() but follows it in today(), because CPython builds today() on time.time and now() on the C system clock
  9. assert tick() advances one second and returns the new time, and tick(timedelta) and tick(float) advance further, with time.time() moving alongside
  10. assert move_to() sets an absolute time, returns None, and carries the module's readings and the subclass's today() with it
  11. assert time.monotonic and time.perf_counter are frozen to the same wall clock as time.time, so a duration spanning the boundary of the freeze measures about thirty years
  12. assert moving the frozen clock backwards makes time.monotonic() go backwards
  13. assert a module first imported inside the freeze keeps the frozen constant, as a FakeDatetime instance, after the block ends
  14. assert leaving the block restores datetime, the rewritten module globals and the real monotonic clock
  15. assert tz_offset is added to now() but never to utcnow(), so those two are what differ by the offset
  16. assert an aware now(timezone.utc) carries the same reading as the naive now() rather than a UTC-correct one, so its timestamp() disagrees with time.time() by exactly tz_offset
  17. assert the naive now().timestamp() equals time.time(), and date.today() takes the offset so a large enough offset changes the date
  18. assert tz_offset accepts a timedelta, so an offset that is not a whole number of hours works
  19. assert datetime.utcnow() raises a DeprecationWarning on python 3.12 in real time and none at all under a freeze

파일

  • csx.json
  • requirements.txt
  • src/__init__.py
  • src/clock.py
  • src/late_import.py
  • test/contract.py

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous