Skip to content

Commit

Permalink
Added timeable tests to get coverage up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcdermott committed Oct 14, 2024
1 parent 40a993e commit 26dc293
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/test_timeable_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}"

0 comments on commit 26dc293

Please sign in to comment.