Skip to content

Commit c17b374

Browse files
Merge pull request #438 from jakob-bagterp/feature/increase-codecov-test-coverage
Feature: Increase Codecov test coverage (part 7)
2 parents 22f0b90 + ac1b245 commit c17b374

10 files changed

+73
-25
lines changed

test/_constant/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ULTRA_SHORT_INTERVAL: float = 0.001 # 1 millisecond.
1+
ONE_MILLISECOND_AS_SECOND: float = 0.001

test/timer/exception_handling/__init__.py

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from collections.abc import Callable
2+
from contextlib import nullcontext as does_not_raise_exception
3+
4+
import pytest
5+
6+
from .soft_error.decimals_1_test import (
7+
test_timer_decimals_above_accepted_value,
8+
test_timer_decimals_below_accepted_value)
9+
from .soft_error.invalid_thread_type_start_test import (
10+
test_timer_start_invalid_thread_type_soft_error_with_context_manager,
11+
test_timer_start_invalid_thread_type_soft_error_without_context_manager)
12+
from .soft_error.invalid_thread_type_stop_test import (
13+
test_timer_stop_invalid_thread_type_soft_error_with_context_manager,
14+
test_timer_stop_invalid_thread_type_soft_error_without_context_manager)
15+
from .soft_error.start_test import (
16+
test_timer_start_default_thread_twice_soft_error_without_context_manager,
17+
test_timer_start_thread_name_collision_soft_error_with_context_manager,
18+
test_timer_start_thread_name_collision_soft_error_without_context_manager)
19+
from .soft_error.stop_test import (
20+
test_timer_stop_default_thread_while_custom_thread_is_running_soft_error,
21+
test_timer_stop_not_started_thread_soft_error_without_start,
22+
test_timer_stop_not_started_thread_soft_error_without_start_and_with_custom_thread,
23+
test_timer_stop_unknown_thread_soft_error_with_default_and_custom_thread,
24+
test_timer_stop_unknown_thread_soft_error_with_multiple_custom_threads)
25+
26+
27+
@pytest.mark.parametrize("test_function", [
28+
test_timer_decimals_below_accepted_value,
29+
test_timer_decimals_above_accepted_value,
30+
test_timer_start_invalid_thread_type_soft_error_without_context_manager,
31+
test_timer_start_invalid_thread_type_soft_error_with_context_manager,
32+
test_timer_stop_invalid_thread_type_soft_error_without_context_manager,
33+
test_timer_stop_invalid_thread_type_soft_error_with_context_manager,
34+
test_timer_start_default_thread_twice_soft_error_without_context_manager,
35+
test_timer_start_thread_name_collision_soft_error_with_context_manager,
36+
test_timer_start_thread_name_collision_soft_error_without_context_manager,
37+
test_timer_stop_default_thread_while_custom_thread_is_running_soft_error,
38+
test_timer_stop_not_started_thread_soft_error_without_start,
39+
test_timer_stop_not_started_thread_soft_error_without_start_and_with_custom_thread,
40+
test_timer_stop_unknown_thread_soft_error_with_default_and_custom_thread,
41+
test_timer_stop_unknown_thread_soft_error_with_multiple_custom_threads,
42+
])
43+
def test_timer_does_not_raise_exceptions(test_function: Callable[..., None], capfd: object) -> None:
44+
with does_not_raise_exception():
45+
test_function(capfd)

test/timer/exception_handling/soft_error/__init__.py

Whitespace-only changes.

test/timer/exception_handling/soft_error/stop_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os import linesep
33

44
import pytest
5+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
56
from _helper import operating_system
67
from _helper.random import random_thread_name, random_thread_name_but_not
78
from _helper.timer import ensure_all_timer_threads_are_stopped
@@ -17,7 +18,7 @@ def test_timer_stop_unknown_thread_soft_error_with_default_and_custom_thread(cap
1718
custom_thread = random_thread_name()
1819
timer = ensure_all_timer_threads_are_stopped()
1920
timer.start()
20-
time.sleep(0.001)
21+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2122
timer.stop(thread=custom_thread)
2223
terminal_output, _ = capfd.readouterr()
2324
assert terminal_output == \
@@ -35,7 +36,7 @@ def test_timer_stop_unknown_thread_soft_error_with_multiple_custom_threads(capfd
3536
custom_thread_2 = random_thread_name_but_not(custom_thread_1)
3637
timer = ensure_all_timer_threads_are_stopped()
3738
timer.start(thread=custom_thread_1)
38-
time.sleep(0.001)
39+
time.sleep(ONE_MILLISECOND_AS_SECOND)
3940
timer.stop(thread=custom_thread_2)
4041
terminal_output, _ = capfd.readouterr()
4142
assert terminal_output == \

test/timer/successful_output/decimals_2_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import time
33

4+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
45
from _helper.terminal_output import successful_output_regex
56
from _helper.timer import ensure_all_timer_threads_are_stopped
67

@@ -12,7 +13,7 @@ def test_timer_decimals_output(capfd: object) -> None:
1213
ensure_all_timer_threads_are_stopped()
1314
for decimals in range(MINIMUM, MAXIMUM + 1):
1415
with Timer(decimals=decimals):
15-
time.sleep(0.001)
16+
time.sleep(ONE_MILLISECOND_AS_SECOND)
1617
terminal_output, _ = capfd.readouterr()
1718
expected_output_regex = successful_output_regex(decimals=decimals)
1819
assert re.fullmatch(expected_output_regex, terminal_output)

test/timer/successful_output/decorator/function_with_arguments_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any
55

66
import pytest
7-
from _constant.interval import ULTRA_SHORT_INTERVAL
7+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
88
from _helper.terminal_output import successful_output_regex
99
from _helper.timer import ensure_all_timer_threads_are_stopped
1010

@@ -17,32 +17,32 @@
1717

1818
@function_timer()
1919
def function_with_args(a: int, b: int) -> None:
20-
time.sleep(ULTRA_SHORT_INTERVAL)
20+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2121

2222

2323
@function_timer()
2424
def function_with_kwargs(x: int = 1, y: int = 2) -> None:
25-
time.sleep(ULTRA_SHORT_INTERVAL)
25+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2626

2727

2828
@function_timer()
2929
def function_with_args_and_kwargs(a: int, b: int, x: int = 3, y: int = 4) -> None:
30-
time.sleep(ULTRA_SHORT_INTERVAL)
30+
time.sleep(ONE_MILLISECOND_AS_SECOND)
3131

3232

3333
@function_timer()
3434
def function_with_args_and_kwargs_number_and_strings(a: int, b: str, x: int = 3, y: str = "4") -> None:
35-
time.sleep(ULTRA_SHORT_INTERVAL)
35+
time.sleep(ONE_MILLISECOND_AS_SECOND)
3636

3737

3838
@function_timer(thread=CUSTOM_THREAD)
3939
def function_with_args_kwargs_and_custom_thread(a: int, b: int, x: int = 3, y: int = 4) -> None:
40-
time.sleep(ULTRA_SHORT_INTERVAL)
40+
time.sleep(ONE_MILLISECOND_AS_SECOND)
4141

4242

4343
@function_timer(thread=CUSTOM_THREAD, decimals=CUSTOM_DECIMALS)
4444
def function_with_args_kwargs_custom_thread_and_custom_decimals(a: int, b: int, x: int = 3, y: int = 4) -> None:
45-
time.sleep(ULTRA_SHORT_INTERVAL)
45+
time.sleep(ONE_MILLISECOND_AS_SECOND)
4646

4747

4848
@pytest.mark.parametrize("function, args, kwargs, expected_thread_name, decimals", [

test/timer/successful_output/decorator/function_without_arguments_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections.abc import Callable
44

55
import pytest
6-
from _constant.interval import ULTRA_SHORT_INTERVAL
6+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
77
from _helper.terminal_output import successful_output_regex
88
from _helper.timer import ensure_all_timer_threads_are_stopped
99

@@ -15,22 +15,22 @@
1515

1616
@function_timer()
1717
def function_to_be_timed() -> None:
18-
time.sleep(ULTRA_SHORT_INTERVAL)
18+
time.sleep(ONE_MILLISECOND_AS_SECOND)
1919

2020

2121
@function_timer(thread=CUSTOM_THREAD)
2222
def function_to_be_timed_with_custom_thread() -> None:
23-
time.sleep(ULTRA_SHORT_INTERVAL)
23+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2424

2525

2626
@function_timer(decimals=CUSTOM_DECIMALS)
2727
def function_to_be_timed_with_custom_decimals() -> None:
28-
time.sleep(ULTRA_SHORT_INTERVAL)
28+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2929

3030

3131
@function_timer(thread=CUSTOM_THREAD, decimals=CUSTOM_DECIMALS)
3232
def function_to_be_timed_with_custom_thread_and_decimals() -> None:
33-
time.sleep(ULTRA_SHORT_INTERVAL)
33+
time.sleep(ONE_MILLISECOND_AS_SECOND)
3434

3535

3636
@pytest.mark.parametrize("function, thread, decimals", [

test/timer/successful_output/thread_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import time
33

4+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
45
from _helper.random import random_thread_name
56
from _helper.terminal_output import successful_output_regex
67
from _helper.timer import ensure_all_timer_threads_are_stopped
@@ -12,7 +13,7 @@ def test_timer_thread_output(capfd: object) -> None:
1213
ensure_all_timer_threads_are_stopped()
1314
custom_thread = random_thread_name()
1415
with Timer(thread=custom_thread):
15-
time.sleep(0.001)
16+
time.sleep(ONE_MILLISECOND_AS_SECOND)
1617
terminal_output, _ = capfd.readouterr()
1718
expected_output_regex = successful_output_regex(thread=custom_thread)
1819
assert re.fullmatch(expected_output_regex, terminal_output)

test/various/with_statement_context_manager_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from _constant.interval import ULTRA_SHORT_INTERVAL
3+
from _constant.interval import ONE_MILLISECOND_AS_SECOND
44
from _helper.random import random_thread_name
55
from _helper.terminal_output import (verify_decimals_in_terminal_output,
66
verify_prefix_in_terminal_output)
@@ -12,15 +12,15 @@
1212

1313
def test_with_statement_context_manager(capfd: object) -> None:
1414
with Timer():
15-
time.sleep(ULTRA_SHORT_INTERVAL)
15+
time.sleep(ONE_MILLISECOND_AS_SECOND)
1616
terminal_output, _ = capfd.readouterr()
1717
assert verify_prefix_in_terminal_output(terminal_output)
1818

1919

2020
def test_with_statement_context_manager_with_thread(capfd: object) -> None:
2121
thread = random_thread_name(4)
2222
with Timer(thread=thread):
23-
time.sleep(ULTRA_SHORT_INTERVAL)
23+
time.sleep(ONE_MILLISECOND_AS_SECOND)
2424
terminal_output, _ = capfd.readouterr()
2525
assert verify_prefix_in_terminal_output(terminal_output)
2626
assert thread in terminal_output
@@ -29,7 +29,7 @@ def test_with_statement_context_manager_with_thread(capfd: object) -> None:
2929
def test_with_statement_context_manager_with_decimals(capfd: object) -> None:
3030
for decimals in DECIMALS_RANGE:
3131
with Timer(decimals=decimals):
32-
time.sleep(ULTRA_SHORT_INTERVAL)
32+
time.sleep(ONE_MILLISECOND_AS_SECOND)
3333
terminal_output, _ = capfd.readouterr()
3434
assert verify_prefix_in_terminal_output(terminal_output)
3535
assert verify_decimals_in_terminal_output(decimals, terminal_output)
@@ -39,7 +39,7 @@ def test_with_statement_context_manager_with_thread_1nd_decimals(capfd: object)
3939
thread = random_thread_name(4)
4040
for decimals in DECIMALS_RANGE:
4141
with Timer(thread=thread, decimals=decimals):
42-
time.sleep(ULTRA_SHORT_INTERVAL)
42+
time.sleep(ONE_MILLISECOND_AS_SECOND)
4343
terminal_output, _ = capfd.readouterr()
4444
assert verify_prefix_in_terminal_output(terminal_output)
4545
assert thread in terminal_output
@@ -52,9 +52,9 @@ def test_with_statement_context_manager_with_multiple_nested_threads_and_decimal
5252
for decimals in DECIMALS_RANGE:
5353
with Timer():
5454
with Timer(thread=thread_1, decimals=decimals):
55-
time.sleep(ULTRA_SHORT_INTERVAL)
55+
time.sleep(ONE_MILLISECOND_AS_SECOND)
5656
with Timer(thread=thread_2):
57-
time.sleep(ULTRA_SHORT_INTERVAL)
57+
time.sleep(ONE_MILLISECOND_AS_SECOND)
5858
terminal_output_1, _ = capfd.readouterr()
5959
assert verify_prefix_in_terminal_output(terminal_output_1)
6060
assert thread_2 in terminal_output_1
@@ -72,7 +72,7 @@ def test_mix_of_context_manager_standard(capfd: object) -> None:
7272
timer = Timer()
7373
timer.start(thread=thread)
7474
with Timer():
75-
time.sleep(ULTRA_SHORT_INTERVAL)
75+
time.sleep(ONE_MILLISECOND_AS_SECOND)
7676
terminal_output_1, _ = capfd.readouterr()
7777
assert verify_prefix_in_terminal_output(terminal_output_1)
7878
timer.stop(thread)

0 commit comments

Comments
 (0)