changeset 306:de1afab6a4e5

Forbid the use of max_read and mr with AudioRegion.split
author Amine Sehili <amine.sehili@gmail.com>
date Fri, 11 Oct 2019 20:43:07 +0100
parents a7bdc583e622
children 334c8760e80f
files auditok/core.py tests/test_core.py
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/core.py	Thu Oct 10 20:43:07 2019 +0200
+++ b/auditok/core.py	Fri Oct 11 20:43:07 2019 +0100
@@ -549,6 +549,11 @@
     ):
         """Split region. See :auditok.split() for split parameters description.
         """
+        if kwargs.get("max_read", kwargs.get("mr")) is not None:
+            warn_msg = "'max_read' (or 'mr') should not be used with "
+            warn_msg += "AudioRegion.split_and_plot(). You should rather "
+            warn_msg += "slice audio region before calling this method"
+            raise RuntimeWarning(warn_msg)
         return split(
             self,
             min_dur=min_dur,
@@ -604,8 +609,7 @@
         try:
             from auditok.plotting import plot
 
-            regions = split(
-                self,
+            regions = self.split(
                 min_dur=min_dur,
                 max_dur=max_dur,
                 max_silence=max_silence,
--- a/tests/test_core.py	Thu Oct 10 20:43:07 2019 +0200
+++ b/tests/test_core.py	Fri Oct 11 20:43:07 2019 +0100
@@ -268,6 +268,12 @@
         )
 
         region = AudioRegion(data, 10, 2, channels)
+        max_read = kwargs.get("max_read", kwargs.get("mr"))
+        if max_read is not None:
+            region = region.sec[:max_read]
+            kwargs.pop("max_read", None)
+            kwargs.pop("mr", None)
+
         regions_ar = region.split(
             min_dur=0.2,
             max_dur=5,
@@ -879,6 +885,15 @@
             expected_regions.append(AudioRegion(data[onset:offset], 10, 2, 1))
         self.assertEqual(regions, expected_regions)
 
+    def test_split_exception(self):
+        with open("tests/data/test_split_10HZ_mono.raw", "rb") as fp:
+            data = fp.read()
+            region = AudioRegion(data, 10, 2, 1)
+
+        with self.assertRaises(RuntimeWarning):
+            # max_read is not accepted when calling AudioRegion.split
+            region.split(max_read=2)
+
 
 @genty
 class TestAudioRegion(TestCase):