Mercurial > hg > auditok
changeset 198:6e574fa1b573
Implement __eq__ in AudioRegion
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Mon, 06 May 2019 18:43:34 +0100 |
parents | 3cb0bbcc262d |
children | f6ac8dbea102 |
files | auditok/core.py tests/test_core.py |
diffstat | 2 files changed, 14 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/auditok/core.py Sat May 04 17:21:07 2019 +0100 +++ b/auditok/core.py Mon May 06 18:43:34 2019 +0100 @@ -410,6 +410,18 @@ def __rmul__(self, n): return self * n + def __eq__(self, other): + if other is self: + return True + if not isinstance(other, AudioRegion): + return False + return ( + (self._data == other._data) + and (self.sr == other.sr) + and (self.sw == other.sw) + and (self.ch == other.ch) + ) + def __getitem__(self, index): err_message = "AudioRegion index must a slice object without a step" if not isinstance(index, slice):
--- a/tests/test_core.py Sat May 04 17:21:07 2019 +0100 +++ b/tests/test_core.py Mon May 06 18:43:34 2019 +0100 @@ -475,12 +475,9 @@ self.assertEqual(m_region.duration, expected_duration) self.assertEqual(len(m_region), expected_length) - @genty_dataset( - _str=("x", "str"), - _float=(1.4, "float"), - ) + @genty_dataset(_str=("x", "str"), _float=(1.4, "float")) def test_multiplication_non_int(self, factor, _type): with self.assertRaises(TypeError) as type_err: - AudioRegion(b'0' * 80, 0, 8000, 1, 1) * factor + AudioRegion(b"0" * 80, 0, 8000, 1, 1) * factor err_msg = "Can't multiply AudioRegion by a non-int of type '{}'" self.assertEqual(err_msg.format(_type), str(type_err.exception))