aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_util.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-12-30 01:56:41 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-12-30 01:56:41 -0500
commit7bc30b43b70556630b4a93c03fefc0d888e3d19f (patch)
treefb0e96762ab8137d23f248ef303538d8d6ff4368 /test/test_util.py
parenta5aecc343fd2886e7ae09bb3e2afeec38f175755 (diff)
New upstream version 1.20.0.upstream/1.20.0
Diffstat (limited to 'test/test_util.py')
-rw-r--r--test/test_util.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test_util.py b/test/test_util.py
index 32e9784..ce403a8 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -357,6 +357,31 @@ class TestOther(unittest.TestCase):
with self.assertRaises(exception.StopExtraction):
expr()
+ def test_build_duration_func(self, f=util.build_duration_func):
+ for v in (0, 0.0, "", None, (), []):
+ self.assertIsNone(f(v))
+
+ def test_single(df, v):
+ for _ in range(10):
+ self.assertEqual(df(), v)
+
+ def test_range(df, lower, upper):
+ for __ in range(10):
+ v = df()
+ self.assertGreaterEqual(v, lower)
+ self.assertLessEqual(v, upper)
+
+ test_single(f(3), 3)
+ test_single(f(3.0), 3.0)
+ test_single(f("3"), 3)
+ test_single(f("3.0-"), 3)
+ test_single(f(" 3 -"), 3)
+
+ test_range(f((2, 4)), 2, 4)
+ test_range(f([2, 4]), 2, 4)
+ test_range(f("2-4"), 2, 4)
+ test_range(f(" 2.0 - 4 "), 2, 4)
+
def test_extractor_filter(self):
# empty
func = util.build_extractor_filter("")