Skip to content

Instantly share code, notes, and snippets.

@zrzka
Created October 23, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zrzka/2f8e2f4bcfb81964cd472dab6039a00a to your computer and use it in GitHub Desktop.
Save zrzka/2f8e2f4bcfb81964cd472dab6039a00a to your computer and use it in GitHub Desktop.
Sample test
#!python3
import unittest
import notification
# https://github.com/omz/Pythonista-Issues/issues/21
class TestScheduledNotifications(unittest.TestCase):
delay = 300 # Keep it in the distant future, so, it won't fire during tests
count = 10
def setUp(self):
notification.cancel_all()
def test_notifications_are_scheduled(self):
for i in range(self.count):
notification.schedule(f'{i}', delay=self.delay + i)
notes = sorted(notification.get_scheduled(), key=lambda x: x['fire_date'])
for i, note in enumerate(notes):
assert(note['message'] == f'{i}')
notification.cancel_all()
def test_notification_is_cancelable(self):
for i in range(self.count):
notification.schedule(f'{i}', delay=self.delay)
notes = notification.get_scheduled()
for i, note in enumerate(notes):
assert(len(notification.get_scheduled()) == self.count - i)
notification.cancel(note)
assert(not notification.get_scheduled())
def tearDown(self):
notification.cancel_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment