Files
wehub-resource-sync bcbd1bdb22
Test (Python) / test-python-gate (push) Blocked by required conditions
Test (TypeScript) / test-typescript-gate (push) Blocked by required conditions
CLI exit codes / cli-gate (push) Blocked by required conditions
Test (Install) / test-install-gate (push) Blocked by required conditions
Integ / integ-gate (push) Blocked by required conditions
CLI exit codes / Python CLI (push) Waiting to run
Integ / changes (push) Has been skipped
Test (Install) / python-minimal (3.11) (push) Waiting to run
Test (Install) / python-minimal (3.12) (push) Waiting to run
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Waiting to run
Integ / integ-ts (push) Waiting to run
Integ / integ (push) Waiting to run
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Waiting to run
Integ / integ-database (push) Waiting to run
Test (Install) / python-extra (email, mirage.resource.email) (push) Waiting to run
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Waiting to run
Integ / integ-ssh (push) Waiting to run
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
CLI exit codes / TypeScript CLI (push) Waiting to run
CLI exit codes / Cross-language snapshot interop (push) Waiting to run
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Waiting to run
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Waiting to run
Test (Python) / changes (push) Has been skipped
Integ / integ-database-ts (push) Waiting to run
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Waiting to run
Integ / integ-data (push) Waiting to run
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Waiting to run
Test (Python) / test (push) Waiting to run
Integ / integ-fuse (push) Waiting to run
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Waiting to run
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Waiting to run
Test (Python) / audit (push) Waiting to run
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Waiting to run
Integ / integ-ssh-ts (push) Waiting to run
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Waiting to run
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Waiting to run
Test (TypeScript) / changes (push) Has been skipped
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Waiting to run
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Waiting to run
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Waiting to run
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Waiting to run
Test (TypeScript) / test (push) Waiting to run
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Waiting to run
Test (TypeScript) / python-fs-shim (push) Waiting to run
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Waiting to run
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Waiting to run
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Waiting to run
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Waiting to run
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Waiting to run
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Waiting to run
Test (Install) / ts-minimal (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:30:44 +08:00

98 lines
3.0 KiB
Python

import pytest
from mirage.shell.arith import evaluate_arith
from mirage.shell.errors import ArithError
def test_basic_precedence():
assert evaluate_arith("1 + 2 * 3", {})[0] == 7
assert evaluate_arith("(1 + 2) * 3", {})[0] == 9
assert evaluate_arith("2 ** 3 ** 2", {})[0] == 512
def test_trunc_division_and_mod_match_c():
assert evaluate_arith("-7 / 2", {})[0] == -3
assert evaluate_arith("7 / -2", {})[0] == -3
assert evaluate_arith("-7 % 2", {})[0] == -1
assert evaluate_arith("7 % -2", {})[0] == 1
def test_literals():
assert evaluate_arith("0x10", {})[0] == 16
assert evaluate_arith("010", {})[0] == 8
with pytest.raises(ArithError):
evaluate_arith("08", {})
def test_assignment_and_updates():
value, updates = evaluate_arith("y = 3, y + 2", {})
assert value == 5
assert updates == {"y": "3"}
value, updates = evaluate_arith("v += 9", {"v": "1"})
assert (value, updates) == (10, {"v": "10"})
def test_increment_decrement():
value, updates = evaluate_arith("i++", {})
assert (value, updates) == (0, {"i": "1"})
value, updates = evaluate_arith("++i", {"i": "1"})
assert (value, updates) == (2, {"i": "2"})
value, updates = evaluate_arith("i--", {"i": "5"})
assert (value, updates) == (5, {"i": "4"})
def test_short_circuit_skips_side_effects():
value, updates = evaluate_arith("0 && (q = 7)", {})
assert (value, updates) == (0, {})
value, updates = evaluate_arith("1 || (q = 7)", {})
assert (value, updates) == (1, {})
def test_ternary_evaluates_taken_arm_only():
value, updates = evaluate_arith("1 ? (w = 4) : (w = 9)", {})
assert (value, updates) == (4, {"w": "4"})
assert evaluate_arith("5 > 3 ? 10 : 20", {})[0] == 10
def test_variables_resolve_recursively():
assert evaluate_arith("x + 1", {})[0] == 1
assert evaluate_arith("s * 2", {"s": "1+2"})[0] == 6
assert evaluate_arith("z + 1", {"z": ""})[0] == 1
def test_logical_and_comparison_results_are_zero_or_one():
assert evaluate_arith("3 && 4", {})[0] == 1
assert evaluate_arith("!5", {})[0] == 0
assert evaluate_arith("2 == 2", {})[0] == 1
assert evaluate_arith("2 != 2", {})[0] == 0
def test_bitwise_and_shifts():
assert evaluate_arith("6 & 3", {})[0] == 2
assert evaluate_arith("6 | 3", {})[0] == 7
assert evaluate_arith("6 ^ 3", {})[0] == 5
assert evaluate_arith("~0", {})[0] == -1
assert evaluate_arith("1 << 4", {})[0] == 16
assert evaluate_arith("-16 >> 2", {})[0] == -4
def test_sixty_four_bit_wrap():
assert evaluate_arith("(1 << 63) - 1 + 1", {})[0] == -(1 << 63)
def test_errors():
with pytest.raises(ArithError):
evaluate_arith("1 / 0", {})
with pytest.raises(ArithError):
evaluate_arith("2 ** -1", {})
with pytest.raises(ArithError):
evaluate_arith("1 +", {})
with pytest.raises(ArithError):
evaluate_arith("@", {})
with pytest.raises(ArithError):
evaluate_arith("r + 1", {"r": "r + 1"})
def test_empty_expression_is_zero():
assert evaluate_arith("", {}) == (0, {})