mock_now() — langchain Function Reference
Architecture documentation for the mock_now() function in utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 134db6ff_44dc_a037_5d16_5637e58f9750["mock_now()"] b77fd012_b825_e350_c8f5_a8f1b44997d9["utils.py"] 134db6ff_44dc_a037_5d16_5637e58f9750 -->|defined in| b77fd012_b825_e350_c8f5_a8f1b44997d9 a7fdd325_2e44_73a8_fe05_2212f3ba1948["now()"] 134db6ff_44dc_a037_5d16_5637e58f9750 -->|calls| a7fdd325_2e44_73a8_fe05_2212f3ba1948 style 134db6ff_44dc_a037_5d16_5637e58f9750 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/utils.py lines 74–113
def mock_now(dt_value: datetime.datetime) -> Iterator[type]:
"""Context manager for mocking out datetime.now() in unit tests.
Args:
dt_value: The datetime value to use for datetime.now().
Yields:
The mocked datetime class.
Example:
```python
with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):
assert datetime.datetime.now() == datetime.datetime(2011, 2, 3, 10, 11)
```
"""
class MockDateTime(datetime.datetime):
"""Mock datetime.datetime.now() with a fixed datetime."""
@classmethod
@override
def now(cls, tz: datetime.tzinfo | None = None) -> "MockDateTime":
# Create a copy of dt_value.
return MockDateTime(
dt_value.year,
dt_value.month,
dt_value.day,
dt_value.hour,
dt_value.minute,
dt_value.second,
dt_value.microsecond,
dt_value.tzinfo,
)
real_datetime = datetime.datetime
datetime.datetime = MockDateTime # type: ignore[misc]
try:
yield datetime.datetime
finally:
datetime.datetime = real_datetime # type: ignore[misc]
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does mock_now() do?
mock_now() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/utils.py.
Where is mock_now() defined?
mock_now() is defined in libs/core/langchain_core/utils/utils.py at line 74.
What does mock_now() call?
mock_now() calls 1 function(s): now.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free