changeset 268:deb05a16eef5

Add tests for make_duration_fromatter
author Amine Sehili <amine.sehili@gmail.com>
date Sat, 14 Sep 2019 15:40:08 +0200
parents d4995db23881
children 549a2b63de9f
files auditok/exceptions.py tests/test_cmdline_util.py
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/exceptions.py	Fri Sep 13 21:32:46 2019 +0100
+++ b/auditok/exceptions.py	Sat Sep 14 15:40:08 2019 +0200
@@ -9,3 +9,7 @@
         self.block_dur = block_dur
         self.sampling_rate = sampling_rate
         super(TooSamllBlockDuration, self).__init__(message)
+
+
+class TimeFormatError(Exception):
+    pass
\ No newline at end of file
--- a/tests/test_cmdline_util.py	Fri Sep 13 21:32:46 2019 +0100
+++ b/tests/test_cmdline_util.py	Sat Sep 14 15:40:08 2019 +0200
@@ -48,7 +48,7 @@
 
 
 @genty
-class TestCmdLineUtil(TestCase):
+class _TestCmdLineUtil(TestCase):
     @genty_dataset(
         no_record=("stream.ogg", False, None, "mix", "mix", False),
         no_record_plot=("stream.ogg", True, None, None, None, False),
@@ -139,3 +139,35 @@
         expected = KeywordArguments(io_kwargs, split_kwargs, miscellaneous)
         kwargs = make_kwargs(args_ns)
         self.assertEqual(kwargs, expected)
+
+    @genty_dataset(
+        only_seconds=("%S", 5400, "5400.000"),
+        only_millis=("%I", 5400, "5400000"),
+        full=("%h:%m:%s.%i", 3725.365, "01:02:05.365"),
+        full_zero_hours=("%h:%m:%s.%i", 1925.075, "00:32:05.075"),
+        full_zero_minutes=("%h:%m:%s.%i", 3659.075, "01:00:59.075"),
+        full_zero_seconds=("%h:%m:%s.%i", 3720.075, "01:02:00.075"),
+        full_zero_millis=("%h:%m:%s.%i", 3725, "01:02:05.000"),
+        duplicate_directive=(
+            "%h %h:%m:%s.%i %s",
+            3725.365,
+            "01 01:02:05.365 05",
+        ),
+        no_millis=("%h:%m:%s", 3725, "01:02:05"),
+        no_seconds=("%h:%m", 3725, "01:02"),
+        no_minutes=("%h", 3725, "01"),
+        no_hours=("%m:%s.%i", 3725, "02:05.000"),
+    )
+    def test_make_duration_fromatter(self, fmt, duration, expected):
+        formatter = make_duration_fromatter(fmt)
+        result = formatter(duration)
+        self.assertEqual(result, expected)
+
+    @genty_dataset(
+        duplicate_only_seconds=("%S %S",),
+        duplicate_only_millis=("%I %I",),
+        unknown_directive=("%x",),
+    )
+    def test_make_duration_fromatter_error(self, fmt):
+        with self.assertRaises(TimeFormatError):
+            make_duration_fromatter(fmt)