MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / Traveller

Class Traveller

src/pendulum/testing/traveller.py:64–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 if time_machine is not None:
63
64 class Traveller(BaseTraveller):
65 def __init__(self, datetime_class: type[DateTime] = DateTime) -> None:
66 super().__init__(datetime_class)
67
68 self._started: bool = False
69 self._traveller: time_machine.travel | None = None
70 self._coordinates: time_machine.Coordinates | None = None
71
72 def freeze(self) -> Self:
73 if self._started:
74 cast("time_machine.Coordinates", self._coordinates).move_to(
75 self._datetime_class.now(), tick=False
76 )
77 else:
78 self._start(freeze=True)
79
80 return self
81
82 def travel_back(self) -> Self:
83 if not self._started:
84 return self
85
86 cast("time_machine.travel", self._traveller).stop()
87 self._coordinates = None
88 self._traveller = None
89 self._started = False
90
91 return self
92
93 def travel(
94 self,
95 years: int = 0,
96 months: int = 0,
97 weeks: int = 0,
98 days: int = 0,
99 hours: int = 0,
100 minutes: int = 0,
101 seconds: int = 0,
102 microseconds: int = 0,
103 *,
104 freeze: bool = False,
105 ) -> Self:
106 self._start(freeze=freeze)
107
108 cast("time_machine.Coordinates", self._coordinates).move_to(
109 self._datetime_class.now().add(
110 years=years,
111 months=months,
112 weeks=weeks,
113 days=days,
114 hours=hours,
115 minutes=minutes,
116 seconds=seconds,
117 microseconds=microseconds,
118 )
119 )
120
121 return self

Callers 2

__init__.pyFile · 0.90
_travellerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…