Home / File/ test_uuid_utils.py — langchain Source File

test_uuid_utils.py — langchain Source File

Architecture documentation for test_uuid_utils.py, a python file in the langchain codebase. 3 imports, 0 dependents.

File python LangChainCore ApiManagement 3 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  0b13f3c1_fce7_e4a0_f47d_296df8868d43["test_uuid_utils.py"]
  996b2db9_46dd_901f_f7eb_068bafab4b12["time"]
  0b13f3c1_fce7_e4a0_f47d_296df8868d43 --> 996b2db9_46dd_901f_f7eb_068bafab4b12
  02f66451_d2a9_e7c3_9765_c3a7594721ad["uuid"]
  0b13f3c1_fce7_e4a0_f47d_296df8868d43 --> 02f66451_d2a9_e7c3_9765_c3a7594721ad
  1b8e06a6_5d76_aae5_0004_a39d94d0cc1d["langchain_core.utils.uuid"]
  0b13f3c1_fce7_e4a0_f47d_296df8868d43 --> 1b8e06a6_5d76_aae5_0004_a39d94d0cc1d
  style 0b13f3c1_fce7_e4a0_f47d_296df8868d43 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import time
from uuid import UUID

from langchain_core.utils.uuid import uuid7


def _uuid_v7_ms(uuid_obj: UUID | str) -> int:
    """Extract milliseconds since epoch from a UUIDv7 using string layout.

    UUIDv7 stores Unix time in ms in the first 12 hex chars of the canonical
    string representation (48 msb bits).
    """
    s = str(uuid_obj).replace("-", "")
    return int(s[:12], 16)


def test_uuid7() -> None:
    """Some simple tests."""
    # Note the sequence value increments by 1 between each of these uuid7(...) calls
    ns = time.time_ns()
    ms = ns // 1_000_000
    out1 = str(uuid7(ns))

    # Verify that the timestamp part matches
    out1_ms = _uuid_v7_ms(out1)
    assert out1_ms == ms


def test_monotonicity() -> None:
    """Test that UUIDs are monotonically increasing."""
    last = ""
    for n in range(100_000):
        i = str(uuid7())
        if n > 0 and i <= last:
            msg = f"UUIDs are not monotonic: {last} versus {i}"
            raise RuntimeError(msg)
        last = i

Domain

Subdomains

Dependencies

  • langchain_core.utils.uuid
  • time
  • uuid

Frequently Asked Questions

What does test_uuid_utils.py do?
test_uuid_utils.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_uuid_utils.py?
test_uuid_utils.py defines 3 function(s): _uuid_v7_ms, test_monotonicity, test_uuid7.
What does test_uuid_utils.py depend on?
test_uuid_utils.py imports 3 module(s): langchain_core.utils.uuid, time, uuid.
Where is test_uuid_utils.py in the architecture?
test_uuid_utils.py is located at libs/core/tests/unit_tests/utils/test_uuid_utils.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/tests/unit_tests/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free