summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Le Marec - Pasquet <kiorky@cryptelium.net>2016-08-15 22:19:22 +0200
committerGitHub <noreply@github.com>2016-08-15 22:19:22 +0200
commit500282ea572423c08e70c823979d2fd2562ac5a7 (patch)
tree2c3a2b6a6f120874c8ab99d78ccd9119dfe8acb0
parent65ebe6d0f43d68fe9dd93cb3c26495801fed321c (diff)
parent0e08b40d959734e48eac592b23d86fa615ca37be (diff)
downloadcroniter-500282ea572423c08e70c823979d2fd2562ac5a7.tar.gz
Merge pull request #13 from taichino/master
merge from taichino
-rw-r--r--src/croniter/croniter.py13
-rwxr-xr-xsrc/croniter/tests/test_croniter.py6
2 files changed, 14 insertions, 5 deletions
diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py
index 5cc2f41..25bb42d 100644
--- a/src/croniter/croniter.py
+++ b/src/croniter/croniter.py
@@ -86,10 +86,10 @@ class croniter(object):
(low, high, step) = m.group(1), m.group(2), m.group(4) or 1
if not any_int_re.search(low):
- low = "{0}".format(self.ALPHACONV[i][low.lower()])
+ low = "{0}".format(self._alphaconv(i, low))
if not any_int_re.search(high):
- high = "{0}".format(self.ALPHACONV[i][high.lower()])
+ high = "{0}".format(self._alphaconv(i, high))
if (
not low or not high or int(low) > int(high)
@@ -111,7 +111,7 @@ class croniter(object):
# e_list.append(j)
else:
if not star_or_int_re.search(t):
- t = self.ALPHACONV[i][t.lower()]
+ t = self._alphaconv(i, t)
try:
t = int(t)
@@ -138,6 +138,13 @@ class croniter(object):
else res)
self.expanded = expanded
+ def _alphaconv(self, index, key):
+ try:
+ return self.ALPHACONV[index][key.lower()]
+ except KeyError:
+ raise ValueError(
+ "[{0}] is not acceptable".format(" ".join(self.exprs)))
+
def get_next(self, ret_type=None):
return self._get_next(ret_type or self._ret_type, is_prev=False)
diff --git a/src/croniter/tests/test_croniter.py b/src/croniter/tests/test_croniter.py
index 55b81a2..0601a7f 100755
--- a/src/croniter/tests/test_croniter.py
+++ b/src/croniter/tests/test_croniter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
@@ -228,7 +228,9 @@ class CroniterTest(base.TestCase):
self.assertRaises(TypeError, itr.get_next, str)
self.assertRaises(ValueError, croniter, '* * * *')
self.assertRaises(ValueError, croniter, '* * 5-1 * *')
- self.assertRaises(KeyError, croniter, '* * * janu-jun *')
+ self.assertRaises(ValueError, croniter, '-90 * * * *')
+ self.assertRaises(ValueError, croniter, 'a * * * *')
+ self.assertRaises(ValueError, croniter, '* * * janu-jun *')
def testSundayToThursdayWithAlphaConversion(self):
base = datetime(2010, 8, 25, 15, 56) #wednesday