Skip to content

Commit

Permalink
tests(remove): remove the toasts unconditionally
Browse files Browse the repository at this point in the history
Don't wait for on_activated or on_dismissed, otherwise the coverage doesn't run
  • Loading branch information
DatGuy1 committed May 20, 2024
1 parent b7796c2 commit 6477535
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def real_run_fixture(pytestconfig) -> Iterator[None]:
else:
with patch("winrt.windows.ui.notifications.ToastNotificationManager.create_toast_notifier"), patch(
"winrt.windows.ui.notifications.ToastNotifier.show"
), patch("winrt.windows.ui.notifications.ToastNotificationHistory.clear"):
), patch("winrt.windows.ui.notifications.ToastNotificationHistory.clear"), patch("time.sleep"):
yield


Expand Down
18 changes: 16 additions & 2 deletions tests/test_toasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,24 @@ def test_system_toast():

InteractableWindowsToaster("Python").show_toast(newToast)


def test_remove_toast():
toaster = WindowsToaster("Python")

newToast = Toast(["Disappearing act"])
newToast.on_dismissed = lambda _: toaster.remove_toast(newToast)

toaster.show_toast(newToast)

import time

time.sleep(0.5)

toaster.remove_toast(newToast)


def test_remove_toast_group():
import time
from src.windows_toasts import ToastActivatedEventArgs

toaster = WindowsToaster("Python")

toast1 = Toast(["A bigger disappearing act"], group="begone")
Expand All @@ -315,3 +324,8 @@ def test_remove_toast_group():

toaster.show_toast(toast1)
toaster.show_toast(toast2)

# If it hasn't been activated, remove it ourselves
time.sleep(1)

toast2.on_activated(ToastActivatedEventArgs())

0 comments on commit 6477535

Please sign in to comment.