From 1ff43317cb7784738d816e8083f3bb77ea0b6889 Mon Sep 17 00:00:00 2001 From: Bradley Cummings <81990728+bwcummings1@users.noreply.github.com> Date: Sun, 26 Jul 2026 17:19:17 -0500 Subject: [PATCH] TEST: add tests for quantecon/timings (#889) Covers the previously zero-coverage quantecon/timings public API: float_precision get/set, ValueError paths (negative int, float, string), get_default_precision, and global-state restoration via an autouse fixture. Raises quantecon/timings/timings.py coverage 0% -> 100%. AI-Model: poolside Laguna S 2.1 (via orchestrated harness; orchestrator Claude Fable 5 / claude-fable-5) AI-Usage: Laguna drafted the tests from the #889 acceptance criteria and the module source under a bounded directive; the orchestrator specified the coverage targets, reviewed the diff, ran flake8 --select=F401,F405,E231 (clean) and verified the 0->100% coverage delta. Human (repo owner) reviews, validates, and submits this PR and takes responsibility. --- quantecon/timings/tests/__init__.py | 0 quantecon/timings/tests/test_timings.py | 64 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 quantecon/timings/tests/__init__.py create mode 100644 quantecon/timings/tests/test_timings.py diff --git a/quantecon/timings/tests/__init__.py b/quantecon/timings/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/quantecon/timings/tests/test_timings.py b/quantecon/timings/tests/test_timings.py new file mode 100644 index 000000000..59622c4de --- /dev/null +++ b/quantecon/timings/tests/test_timings.py @@ -0,0 +1,64 @@ +""" +Tests for quantecon/timings/timings.py + +Covers the previously zero-coverage public API: + +* ``float_precision`` getter (precision=None) and setter +* ``ValueError`` paths for a negative int, a float, and a string +* ``get_default_precision`` returning the current global value +* global-state restoration so tests never leak precision changes +""" +import pytest + +import quantecon as qe + + +@pytest.fixture(autouse=True) +def restore_precision(): + """Snapshot the global precision before each test and restore it after.""" + original = qe.timings.get_default_precision() + yield original + qe.timings.float_precision(original) + + +def test_get_default_precision_returns_current(restore_precision): + # get_default_precision reports the live global value, not a constant. + assert qe.timings.get_default_precision() == restore_precision + + +def test_float_precision_getter_returns_current(restore_precision): + # Calling with no argument returns the current precision. + assert qe.timings.float_precision() == restore_precision + + +def test_float_precision_setter_changes_value(): + # Setting must be observable via both the getter and get_default_precision. + qe.timings.float_precision(6) + assert qe.timings.float_precision() == 6 + assert qe.timings.get_default_precision() == 6 + + +def test_float_precision_setter_accepts_zero(): + # Zero is a valid non-negative integer. + qe.timings.float_precision(0) + assert qe.timings.float_precision() == 0 + + +def test_float_precision_setter_accepts_large_value(): + qe.timings.float_precision(12) + assert qe.timings.float_precision() == 12 + + +@pytest.mark.parametrize("bad", [-1, 4.5, "4"]) +def test_float_precision_value_error_on_invalid(bad): + # Negative int, float, and string must all raise ValueError. + with pytest.raises(ValueError, match="non-negative integer"): + qe.timings.float_precision(bad) + + +def test_float_precision_value_error_does_not_change_state(): + # A failed set must leave the global precision untouched. + before = qe.timings.get_default_precision() + with pytest.raises(ValueError): + qe.timings.float_precision(-1) + assert qe.timings.get_default_precision() == before