Repository: rabitt/pysox

Issue:
Trim allows start time without an end
Trim can trim a file from the beginning with only the start time (e.g. `sox input output trim 10`) but pysox's trim requires both start and end. Added #81 as a fix.

Discussion:

Patch:
diff --git a/sox/transform.py b/sox/transform.py
index de13675..75de069 100644
--- a/sox/transform.py
+++ b/sox/transform.py
@@ -2964,30 +2964,33 @@ class Transformer(object):
 
         return self
 
-    def trim(self, start_time, end_time):
-        '''Excerpt a clip from an audio file, given a start and end time.
+    def trim(self, start_time, end_time=None):
+        '''Excerpt a clip from an audio file, given the start timestamp and end timestamp of the clip within the file, expressed in seconds. If the end timestamp is set to `None` or left unspecified, it defaults to the duration of the audio file.
 
         Parameters
         ----------
         start_time : float
             Start time of the clip (seconds)
-        end_time : float
+        end_time : float or None, default=None
             End time of the clip (seconds)
 
         '''
         if not is_number(start_time) or start_time < 0:
             raise ValueError("start_time must be a positive number.")
-        if not is_number(end_time) or end_time < 0:
-            raise ValueError("end_time must be a positive number.")
-        if start_time >= end_time:
-            raise ValueError("start_time must be smaller than end_time.")
 
         effect_args = [
             'trim',
-            '{:f}'.format(start_time),
-            '{:f}'.format(end_time - start_time)
+            '{:f}'.format(start_time)
         ]
 
+        if end_time is not None:
+            if not is_number(end_time) or end_time < 0:
+                raise ValueError("end_time must be a positive number.")
+            if start_time >= end_time:
+                raise ValueError("start_time must be smaller than end_time.")
+
+            effect_args.append('{:f}'.format(end_time - start_time))
+
         self.effects.extend(effect_args)
         self.effects_log.append('trim')
 


Test patch:
diff --git a/tests/test_transform.py b/tests/test_transform.py
index f611ee4..8930637 100644
--- a/tests/test_transform.py
+++ b/tests/test_transform.py
@@ -4361,6 +4361,22 @@ class TestTransformerTremolo(unittest.TestCase):
 class TestTransformerTrim(unittest.TestCase):
 
     def test_default(self):
+        tfm = new_transformer()
+        tfm.trim(5.0)
+
+        actual_args = tfm.effects
+        expected_args = ['trim', '5.000000']
+        self.assertEqual(expected_args, actual_args)
+
+        actual_log = tfm.effects_log
+        expected_log = ['trim']
+        self.assertEqual(expected_log, actual_log)
+
+        actual_res = tfm.build(INPUT_FILE, OUTPUT_FILE)
+        expected_res = True
+        self.assertEqual(expected_res, actual_res)
+
+    def test_end_time(self):
         tfm = new_transformer()
         tfm.trim(0, 8.5)