Change base Exception to UnsupportedRecurrence

This commit is contained in:
Matt Snider 2019-06-30 11:38:37 +02:00
parent c4815955ef
commit 7f5e9708dc
3 changed files with 14 additions and 3 deletions

View File

@ -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')

View File

@ -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

View File

@ -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