Skip to content

Fix: Line separator issue in skipped tests for Windows #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/_constant/terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from os import linesep

from _helper import operating_system

LINESEP = "\n" if operating_system.is_windows() else linesep
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}"
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}"
12 changes: 2 additions & 10 deletions test/timer/exception_handling/soft_error/start_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,19 +16,14 @@ 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)
with Timer(thread=custom_thread):
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")


Expand Down
31 changes: 7 additions & 24 deletions test/timer/exception_handling/soft_error/stop_test.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
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()
time.sleep(ONE_MILLISECOND_AS_SECOND)
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()
Expand All @@ -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:
Expand All @@ -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}"
Loading