# HG changeset patch # User Amine Sehili # Date 1570822987 -3600 # Node ID de1afab6a4e51815981d444dacfb1d3febc998cb # Parent a7bdc583e62261acff030cfe32fca4f5ca23a808 Forbid the use of max_read and mr with AudioRegion.split diff -r a7bdc583e622 -r de1afab6a4e5 auditok/core.py --- 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, diff -r a7bdc583e622 -r de1afab6a4e5 tests/test_core.py --- 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):