forked from third-party-mirrors/zfs_autobackup
tests, nicer error message for invalid schedule str
This commit is contained in:
parent
f9719ba87e
commit
bef3be4955
@ -3,7 +3,7 @@ import pprint
|
||||
|
||||
from zfs_autobackup.Thinner import Thinner
|
||||
|
||||
#randint is different in python 2 vs 3
|
||||
# randint is different in python 2 vs 3
|
||||
randint_compat = lambda lo, hi: lo + int(random.random() * (hi + 1 - lo))
|
||||
|
||||
|
||||
@ -23,6 +23,20 @@ class TestThinner(unittest2.TestCase):
|
||||
|
||||
# return super().setUp()
|
||||
|
||||
def test_exceptions(self):
|
||||
with self.assertRaisesRegexp(Exception, "^Invalid period"):
|
||||
ThinnerRule("12X12m")
|
||||
|
||||
with self.assertRaisesRegexp(Exception, "^Invalid ttl"):
|
||||
ThinnerRule("12d12X")
|
||||
|
||||
with self.assertRaisesRegexp(Exception, "^Period cant be"):
|
||||
ThinnerRule("12d1d")
|
||||
|
||||
with self.assertRaisesRegexp(Exception, "^Invalid schedule"):
|
||||
ThinnerRule("XXX")
|
||||
|
||||
|
||||
def test_incremental(self):
|
||||
ok=['2023-01-03 10:53:16',
|
||||
'2024-01-02 15:43:29',
|
||||
|
@ -39,6 +39,10 @@ class ThinnerRule:
|
||||
rule_str = rule_str.lower()
|
||||
matches = re.findall("([0-9]*)([a-z]*)([0-9]*)([a-z]*)", rule_str)[0]
|
||||
|
||||
if '' in matches:
|
||||
raise (Exception("Invalid schedule string: '{}'".format(rule_str)))
|
||||
|
||||
print(matches)
|
||||
period_amount = int(matches[0])
|
||||
period_unit = matches[1]
|
||||
ttl_amount = int(matches[2])
|
||||
|
Loading…
x
Reference in New Issue
Block a user