35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import pytest
|
|
|
|
# Ensure the src layout is on PYTHONPATH for tests without installing the package
|
|
import os
|
|
import sys
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
SRC = os.path.join(ROOT, "src")
|
|
if SRC not in sys.path:
|
|
sys.path.insert(0, SRC)
|
|
|
|
from idea34_openpassmarket_privacy_preserving.core import LocalProblem, PassSpec, PrivacyBudget, to_contract_message
|
|
|
|
|
|
def test_to_contract_message_deterministic():
|
|
lp = LocalProblem(
|
|
problem_id="p1",
|
|
code_region="def f(): pass",
|
|
inlining_decisions={},
|
|
loop_tiling_params={},
|
|
vectorization_hints={},
|
|
constraints={},
|
|
)
|
|
spec = PassSpec(pass_id="pass_01", language="Python", target_IR="IR1", transform_type="mutate")
|
|
budget = PrivacyBudget(budget=5.0, leakage_model="Laplace")
|
|
|
|
msg1 = to_contract_message(lp, spec, budget)
|
|
msg2 = to_contract_message(lp, spec, budget)
|
|
|
|
# Deterministic content (timestamp can differ between invocations)
|
|
assert msg1["local_problem"] == msg2["local_problem"]
|
|
assert msg1["pass_spec"] == msg2["pass_spec"]
|
|
assert msg1["privacy_budget"] == msg2["privacy_budget"]
|
|
assert "timestamp" in msg1
|