Files
cs249r_book/mlsysim/tests/test_provenance.py
Vijay Janapa Reddi d6d90aa2be fix(security): resolve all 28 GitHub code scanning alerts
Add least-privilege permissions blocks to 8 workflow files (16 alerts),
fix ReDoS regex, HTTP response splitting, XSS/open redirect, insecure
randomness, incomplete URL sanitization, and add SRI hashes to CDN scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 11:54:06 -04:00

60 lines
1.7 KiB
Python

import pytest
import pint
from mlsysim.core.provenance import TraceableConstant
from mlsysim.core.constants import ureg
def test_system_assumption_behaves_like_float():
"""Ensure the pedagogical wrapper doesn't break basic math operations."""
assump = TraceableConstant(
0.85,
name="Test MFU",
description="A test assumption.",
citation="Test Citation"
)
assert isinstance(assump, float)
assert assump == 0.85
assert assump * 2 == 1.7
assert 1.0 - assump == pytest.approx(0.15)
assert assump / 2 == 0.425
assert assump > 0.80
def test_system_assumption_preserves_metadata():
"""Ensure the metadata is accessible for textbook rendering."""
assump = TraceableConstant(
0.50,
name="Test MFU",
description="A test assumption.",
citation="Test Citation",
url="https://example.com"
)
assert assump.name == "Test MFU"
assert assump.description == "A test assumption."
assert assump.citation == "Test Citation"
md = assump.render_markdown()
assert "Test MFU" in md
expected_url = "https://example.com"
assert expected_url in md
assert "0.5" in md
def test_system_assumption_with_pint():
"""Ensure pint unit operations work correctly on the wrapper."""
assump = TraceableConstant(
15.0,
name="Test Overhead",
description="Overhead in ms.",
citation="Test Citation"
)
# Multiplying by a pint unit
quant = assump * ureg.ms
assert isinstance(quant, pint.Quantity)
assert quant.magnitude == 15.0
assert quant.units == ureg.ms
# Division
rate = 1.0 / quant
assert rate.magnitude == pytest.approx(1/15.0)