Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions ci/tools/tests/test_rebase_sphinx_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@

from cuda_python.docs.copy_rebased_sphinx_inventory_one_level_up import copy_rebased_inventory_one_level_up

_INVENTORY_HEADER = (
b"# Sphinx inventory version 2\n"
b"# Project: cuda.bindings\n"
b"# Version: 13.5.0\n"
b"# The remainder of this file is compressed using zlib.\n"
)


@pytest.mark.agent_authored(model="gpt-6")
def test_copy_rebases_relative_inventory_targets(tmp_path, monkeypatch):
header = (
b"# Sphinx inventory version 2\n"
b"# Project: cuda.bindings\n"
b"# Version: 13.5.0\n"
b"# The remainder of this file is compressed using zlib.\n"
)
entries = (
b"cuda.bindings.driver.cuInit py:function 1 module/driver.html#$ -\n"
b"figure 1 std:label -1 overview.html#figure-1 Example with spaces\n"
b"external std:label -1 https://example.org/overview.html#target -\n"
)
original = header + zlib.compress(entries)
original = _INVENTORY_HEADER + zlib.compress(entries)
source = tmp_path / "latest" / "objects.inv"
source.parent.mkdir()
source.write_bytes(original)
Expand All @@ -32,10 +33,23 @@ def test_copy_rebases_relative_inventory_targets(tmp_path, monkeypatch):
copy_rebased_inventory_one_level_up(Path("objects.inv"))

rebased = destination.read_bytes()
assert rebased.startswith(header)
assert zlib.decompress(rebased[len(header) :]) == (
assert rebased.startswith(_INVENTORY_HEADER)
assert zlib.decompress(rebased[len(_INVENTORY_HEADER) :]) == (
b"cuda.bindings.driver.cuInit py:function 1 latest/module/driver.html#$ -\n"
b"figure 1 std:label -1 latest/overview.html#figure-1 Example with spaces\n"
b"external std:label -1 https://example.org/overview.html#target -\n"
)
assert source.read_bytes() == original


@pytest.mark.agent_authored(model="gpt-6")
def test_copy_rejects_malformed_inventory_entries(tmp_path):
entries = b"cuda.bindings.driver.cuInit py:function 1 module/driver.html#$ -\nunexpected entry\n"
source = tmp_path / "latest" / "objects.inv"
source.parent.mkdir()
source.write_bytes(_INVENTORY_HEADER + zlib.compress(entries))

with pytest.raises(ValueError, match="1 of 2 inventory entries did not match the expected format"):
copy_rebased_inventory_one_level_up(source)

assert not (tmp_path / "objects.inv").exists()
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def rebase_entry(match: re.Match[str]) -> str:

header = b"\n".join(parts[:4]) + b"\n"
entries = zlib.decompress(parts[4]).decode()
rebased = _ENTRY.sub(rebase_entry, entries)
rebased, matched = _ENTRY.subn(rebase_entry, entries)
expected = sum(1 for line in entries.split("\n") if line.strip())
if matched != expected:
raise ValueError(
f"{source}: {expected - matched} of {expected} inventory entries did not match the expected format"
)
destination.write_bytes(header + zlib.compress(rebased.encode()))


Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[pytest]
addopts = --showlocals --durations=20
pythonpath = .
norecursedirs =
samples

Expand Down
Loading