diff --git a/test/_constant/terminal.py b/test/_constant/terminal.py new file mode 100644 index 00000000..6c31c26b --- /dev/null +++ b/test/_constant/terminal.py @@ -0,0 +1,5 @@ +from os import linesep + +from _helper import operating_system + +LINESEP = "\n" if operating_system.is_windows() else linesep diff --git a/test/timer/exception_handling/soft_error/invalid_thread_type_start_test.py b/test/timer/exception_handling/soft_error/invalid_thread_type_start_test.py index fac68a68..e0bcf2a4 100644 --- a/test/timer/exception_handling/soft_error/invalid_thread_type_start_test.py +++ b/test/timer/exception_handling/soft_error/invalid_thread_type_start_test.py @@ -1,7 +1,4 @@ -from os import linesep - -import pytest -from _helper import operating_system +from _constant.terminal import LINESEP from _helper.random import random_thread_name from _helper.timer import get_timer_with_invalid_thread_type from colorist import Color @@ -18,18 +15,13 @@ def test_timer_start_invalid_thread_type_soft_error_without_context_manager(capf def test_timer_start_invalid_thread_type_soft_error_with_context_manager(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() get_timer_with_invalid_thread_type(custom_thread) with Timer(thread=custom_thread): pass terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{linesep}" + f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" diff --git a/test/timer/exception_handling/soft_error/invalid_thread_type_stop_test.py b/test/timer/exception_handling/soft_error/invalid_thread_type_stop_test.py index b4e45f47..7df989fe 100644 --- a/test/timer/exception_handling/soft_error/invalid_thread_type_stop_test.py +++ b/test/timer/exception_handling/soft_error/invalid_thread_type_stop_test.py @@ -1,7 +1,4 @@ -from os import linesep - -import pytest -from _helper import operating_system +from _constant.terminal import LINESEP from _helper.random import random_thread_name from _helper.timer import get_timer_with_invalid_thread_type from colorist import Color @@ -10,34 +7,24 @@ def test_timer_stop_invalid_thread_type_soft_error_without_context_manager(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() timer = get_timer_with_invalid_thread_type(custom_thread) timer.stop(thread=custom_thread) terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{linesep}" + f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" def test_timer_stop_invalid_thread_type_soft_error_with_context_manager(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() get_timer_with_invalid_thread_type(custom_thread) with Timer(thread=custom_thread): pass terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{linesep}" +\ - f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{linesep}" + f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer: Something went wrong in the Timer's lookup module for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{LINESEP}" +\ + f"{Color.YELLOW}Timer: Something went wrong in the Timer's stop thread controller for thread {custom_thread.upper()}.{Color.OFF}{LINESEP}" diff --git a/test/timer/exception_handling/soft_error/start_test.py b/test/timer/exception_handling/soft_error/start_test.py index a6834f4f..03e44ac2 100644 --- a/test/timer/exception_handling/soft_error/start_test.py +++ b/test/timer/exception_handling/soft_error/start_test.py @@ -1,7 +1,4 @@ -from os import linesep - -import pytest -from _helper import operating_system +from _constant.terminal import LINESEP from _helper.random import random_thread_name from _helper.timer import ensure_all_timer_threads_are_stopped from colorist import Color @@ -19,11 +16,6 @@ def test_timer_start_thread_name_collision_soft_error_without_context_manager(ca def test_timer_start_thread_name_collision_soft_error_with_context_manager(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() timer = ensure_all_timer_threads_are_stopped() timer.start(thread=custom_thread) @@ -31,7 +23,7 @@ def test_timer_start_thread_name_collision_soft_error_with_context_manager(capfd pass terminal_output, _ = capfd.readouterr() assert str(terminal_output).startswith( - f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is running. Use .stop(thread='{custom_thread.upper()}') to stop it.{Color.OFF}{linesep}" + "Elapsed time:") + f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is running. Use .stop(thread='{custom_thread.upper()}') to stop it.{Color.OFF}{LINESEP}" + "Elapsed time:") assert str(terminal_output).endswith(f" for thread {Color.GREEN}{custom_thread.upper()}{Color.OFF}\n") diff --git a/test/timer/exception_handling/soft_error/stop_test.py b/test/timer/exception_handling/soft_error/stop_test.py index 2475b642..8b0aa5ed 100644 --- a/test/timer/exception_handling/soft_error/stop_test.py +++ b/test/timer/exception_handling/soft_error/stop_test.py @@ -1,20 +1,13 @@ import time -from os import linesep -import pytest from _constant.interval import ONE_MILLISECOND_AS_SECOND -from _helper import operating_system +from _constant.terminal import LINESEP from _helper.random import random_thread_name, random_thread_name_but_not from _helper.timer import ensure_all_timer_threads_are_stopped from colorist import Color def test_timer_stop_unknown_thread_soft_error_with_default_and_custom_thread(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() timer = ensure_all_timer_threads_are_stopped() timer.start() @@ -22,16 +15,11 @@ def test_timer_stop_unknown_thread_soft_error_with_default_and_custom_thread(cap timer.stop(thread=custom_thread) terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{linesep}" +\ - f"Or maybe you aren't stopping the right thread? Currently open threads: NONE{linesep}" + f"{Color.YELLOW}Timer for thread {custom_thread.upper()} is not running. Use .start(thread='{custom_thread.upper()}') to start it.{Color.OFF}{LINESEP}" +\ + f"Or maybe you aren't stopping the right thread? Currently open threads: NONE{LINESEP}" def test_timer_stop_unknown_thread_soft_error_with_multiple_custom_threads(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread_1 = random_thread_name() custom_thread_2 = random_thread_name_but_not(custom_thread_1) timer = ensure_all_timer_threads_are_stopped() @@ -40,8 +28,8 @@ def test_timer_stop_unknown_thread_soft_error_with_multiple_custom_threads(capfd timer.stop(thread=custom_thread_2) terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer for thread {custom_thread_2.upper()} is not running. Use .start(thread='{custom_thread_2.upper()}') to start it.{Color.OFF}{linesep}" +\ - f"Or maybe you aren't stopping the right thread? Currently open threads: {custom_thread_1.upper()}{linesep}" + f"{Color.YELLOW}Timer for thread {custom_thread_2.upper()} is not running. Use .start(thread='{custom_thread_2.upper()}') to start it.{Color.OFF}{LINESEP}" +\ + f"Or maybe you aren't stopping the right thread? Currently open threads: {custom_thread_1.upper()}{LINESEP}" def test_timer_stop_not_started_thread_soft_error_without_start(capfd: object) -> None: @@ -60,16 +48,11 @@ def test_timer_stop_not_started_thread_soft_error_without_start_and_with_custom_ def test_timer_stop_default_thread_while_custom_thread_is_running_soft_error(capfd: object) -> None: - if operating_system.is_windows(): - pytest.skip("Skipping test for Windows due to line separator issue.") # pragma: no cover - # TODO: Fix line separator issue on Windows. - return # pragma: no cover - custom_thread = random_thread_name() timer = ensure_all_timer_threads_are_stopped() timer.start(thread=custom_thread) timer.stop() terminal_output, _ = capfd.readouterr() assert terminal_output == \ - f"{Color.YELLOW}Timer is not running. Use .start() to start it.{Color.OFF}{linesep}" +\ - f"Or maybe you aren't stopping the right thread? Currently open threads: {custom_thread.upper()}{linesep}" + f"{Color.YELLOW}Timer is not running. Use .start() to start it.{Color.OFF}{LINESEP}" +\ + f"Or maybe you aren't stopping the right thread? Currently open threads: {custom_thread.upper()}{LINESEP}"