Coverage for src/prosemark/adapters/fake_clock.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-24 18:08 +0000

1# Copyright (c) 2024 Prosemark Contributors 

2# This software is licensed under the MIT License 

3 

4"""Fake clock adapter for testing time-dependent operations.""" 

5 

6from prosemark.ports.clock import Clock 

7 

8 

9class FakeClock(Clock): 

10 """In-memory fake implementation of Clock for testing. 

11 

12 Provides deterministic timestamp generation for tests by returning 

13 a fixed ISO8601 timestamp. Can be initialized with a specific 

14 timestamp or uses a default value. 

15 

16 This fake always returns the same timestamp value, ensuring 

17 reproducible test behavior for time-dependent operations. 

18 

19 Examples: 

20 >>> clock = FakeClock() 

21 >>> clock.now_iso() 

22 '2025-09-13T12:00:00Z' 

23 >>> custom_clock = FakeClock('2025-01-01T00:00:00Z') 

24 >>> custom_clock.now_iso() 

25 '2025-01-01T00:00:00Z' 

26 

27 """ 

28 

29 def __init__(self, fixed_time: str = '2025-09-13T12:00:00Z') -> None: 

30 """Initialize fake clock with a fixed timestamp. 

31 

32 Args: 

33 fixed_time: ISO8601 formatted timestamp to always return. 

34 Defaults to '2025-09-13T12:00:00Z'. 

35 

36 """ 

37 self._fixed_time = fixed_time 

38 

39 def now_iso(self) -> str: 

40 """Return the fixed timestamp. 

41 

42 Returns: 

43 The fixed ISO8601 timestamp provided at initialization. 

44 

45 """ 

46 return self._fixed_time