From 7f5e9708dc55b192744f5eca6449fedd799dd58c Mon Sep 17 00:00:00 2001 From: Matt Snider Date: Sun, 30 Jun 2019 11:38:37 +0200 Subject: [PATCH] Change base Exception to UnsupportedRecurrence --- tests/test_recur.py | 5 +++-- todoist_taskwarrior/errors.py | 9 +++++++++ todoist_taskwarrior/utils.py | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 todoist_taskwarrior/errors.py diff --git a/tests/test_recur.py b/tests/test_recur.py index 9c29d55..66addb3 100644 --- a/tests/test_recur.py +++ b/tests/test_recur.py @@ -4,6 +4,7 @@ Tests parsing `recur` strings from Todoist `date_string`s """ import pytest from todoist_taskwarrior import utils +from todoist_taskwarrior import errors def test_hourly(): @@ -169,9 +170,9 @@ def test_annually(): def test_unsupported(): - with pytest.raises(Exception): + with pytest.raises(errors.UnsupportedRecurrence): utils.parse_recur('every mon,tues,weds') - with pytest.raises(Exception): + with pytest.raises(errors.UnsupportedRecurrence): utils.parse_recur('every monday,tuesday,wednesday') diff --git a/todoist_taskwarrior/errors.py b/todoist_taskwarrior/errors.py new file mode 100644 index 0000000..7238973 --- /dev/null +++ b/todoist_taskwarrior/errors.py @@ -0,0 +1,9 @@ +""" Custom Errors """ + + +class UnsupportedRecurrence(Exception): + + def __init__(self, date_string): + super().__init__('Unsupported recurrence: %s' % date_string) + self.date_string = date_string + diff --git a/todoist_taskwarrior/utils.py b/todoist_taskwarrior/utils.py index 059bc63..0635cca 100644 --- a/todoist_taskwarrior/utils.py +++ b/todoist_taskwarrior/utils.py @@ -1,6 +1,7 @@ import click import re from datetime import datetime +from .errors import UnsupportedRecurrence """ Validation """ @@ -94,7 +95,7 @@ def parse_recur(date_string): _recur_special(date_string) ) if not result: - raise Exception("Recurrence not supported: %s" % date_string) + raise UnsupportedRecurrence(date_string) return result