diff options
author | Mathieu Le Marec - Pasquet <kiorky@cryptelium.net> | 2016-08-15 22:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-15 22:21:14 +0200 |
commit | afa938fff4cca9cab5f3f65127e4784b80219bee (patch) | |
tree | ed2f497b402856928c5d7e0a3e6f6124cfbfb7ef | |
parent | 3827e2ab306a59104dd24aba45d169592d81f9be (diff) | |
parent | 3284e2146aae69e0bbf53e570133d65db470b1a7 (diff) | |
download | croniter-afa938fff4cca9cab5f3f65127e4784b80219bee.tar.gz |
Merge pull request #15 from kiorky/revert-14-revert-13-master
Revert "Revert "merge from taichino""
-rw-r--r-- | src/croniter/croniter.py | 13 | ||||
-rwxr-xr-x | src/croniter/tests/test_croniter.py | 6 |
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 |