From 26dc29331399b629f23ea7d06fa1644f8f8dc980 Mon Sep 17 00:00:00 2001 From: Matthew McDermott Date: Mon, 14 Oct 2024 13:45:08 -0400 Subject: [PATCH] Added timeable tests to get coverage up. --- tests/test_timeable_mixin.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_timeable_mixin.py b/tests/test_timeable_mixin.py index 7b6aeb4..286459e 100644 --- a/tests/test_timeable_mixin.py +++ b/tests/test_timeable_mixin.py @@ -57,6 +57,14 @@ class Derived(TimeableMixin): assert (3, "foo") == Derived._get_pprint_num_unit(3 / 20, "biz") assert (1.2, "biz") == Derived._get_pprint_num_unit(2.4 * 10, "foo") + try: + Derived._get_pprint_num_unit(1, "WRONG") + raise AssertionError("Should have raised an exception") + except LookupError: + pass + except Exception as e: + raise AssertionError(f"Raised the wrong exception: {e}") + def test_context_manager(): T = TimeableDerived() @@ -90,5 +98,9 @@ def test_times_and_profiling(): assert 0 == stats["decorated_takes_time_auto_key"][2] got_str = T._profile_durations() - want_str = "decorated_takes_time_auto_key: 2.0 sec\n" "decorated: 1.5 ± 0.5 sec (x2)" + want_str = "decorated_takes_time_auto_key: 2.0 sec\ndecorated: 1.5 ± 0.5 sec (x2)" + assert want_str == got_str, f"Want:\n{want_str}\nGot:\n{got_str}" + + got_str = T._profile_durations(only_keys=["decorated_takes_time_auto_key"]) + want_str = "decorated_takes_time_auto_key: 2.0 sec" assert want_str == got_str, f"Want:\n{want_str}\nGot:\n{got_str}"