[SCM] morituri/master: * morituri/common/accurip.py: * morituri/image/image.py: * morituri/test/Makefile.am: * morituri/test/test_image_image.py: * morituri/test/test_common_accurip.py (added): Move accuraterip stuff to the accurip module. Move/create new test file.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:03 UTC 2014


The following commit has been merged in the master branch:
commit 7dfc1fbc6c19435fe6fbc61df791ebc862bf43f6
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sat May 23 18:14:11 2009 +0000

    	* morituri/common/accurip.py:
    	* morituri/image/image.py:
    	* morituri/test/Makefile.am:
    	* morituri/test/test_image_image.py:
    	* morituri/test/test_common_accurip.py (added):
    	  Move accuraterip stuff to the accurip module.
    	  Move/create new test file.

diff --git a/ChangeLog b/ChangeLog
index 0559922..db2878e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-05-23  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/common/accurip.py:
+	* morituri/image/image.py:
+	* morituri/test/Makefile.am:
+	* morituri/test/test_image_image.py:
+	* morituri/test/test_common_accurip.py (added):
+	  Move accuraterip stuff to the accurip module.
+	  Move/create new test file.
+
+2009-05-23  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/rip/Makefile.am:
 	* morituri/rip/main.py:
 	* morituri/rip/drive.py (added):
diff --git a/morituri/common/accurip.py b/morituri/common/accurip.py
index 7b9c16b..9f94baf 100644
--- a/morituri/common/accurip.py
+++ b/morituri/common/accurip.py
@@ -1,4 +1,4 @@
-# -*- Mode: Python -*-
+# -*- Mode: Python; test-case-name: morituri.test.test_common_accurip -*-
 # vi:si:et:sw=4:sts=4:ts=4
 
 # Morituri - for those about to RIP
@@ -21,11 +21,11 @@
 # along with morituri.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
+import strct
 import urlparse
 import urllib2
 
 from morituri.common import log
-from morituri.image import image
 
 _CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
 
@@ -56,7 +56,7 @@ class AccuCache(log.Loggable):
 
         data = self._read(url)
 
-        return image.getAccurateRipResponses(data)
+        return getAccurateRipResponses(data)
 
     def download(self, url):
         # FIXME: download url as a task too
@@ -89,4 +89,44 @@ class AccuCache(log.Loggable):
         data = handle.read()
         handle.close()
         return data
-        
+
+def getAccurateRipResponses(data):
+    ret = []
+
+    while data:
+        trackCount = struct.unpack("B", data[0])[0]
+        bytes = 1 + 12 + trackCount * (1 + 8)
+
+        ret.append(AccurateRipResponse(data[:bytes]))
+        data = data[bytes:]
+
+    return ret
+
+class AccurateRipResponse(object):
+    """
+    I represent the response of the AccurateRip online database.
+    """
+
+    trackCount = None
+    discId1 = ""
+    discId2 = ""
+    cddbDiscId = ""
+    confidences = None
+    checksums = None
+
+    def __init__(self, data):
+        self.trackCount = struct.unpack("B", data[0])[0]
+        self.discId1 = "%08x" % struct.unpack("<L", data[1:5])[0]
+        self.discId2 = "%08x" % struct.unpack("<L", data[5:9])[0]
+        self.cddbDiscId = "%08x" % struct.unpack("<L", data[9:13])[0]
+
+        self.confidences = []
+        self.checksums = []
+
+        pos = 13
+        for _ in range(self.trackCount):
+            confidence = struct.unpack("B", data[pos])[0]
+            checksum = "%08x" % struct.unpack("<L", data[pos + 1:pos + 5])[0]
+            pos += 9
+            self.confidences.append(confidence)
+            self.checksums.append(checksum) 
diff --git a/morituri/image/image.py b/morituri/image/image.py
index 7fbdf84..28e7ec7 100644
--- a/morituri/image/image.py
+++ b/morituri/image/image.py
@@ -197,45 +197,3 @@ class ImageVerifyTask(task.MultiSeparateTask):
             self.lengths[trackIndex] = end - index.relative
 
         task.MultiSeparateTask.stop(self)
-
-# FIXME: move this method to a different module ?
-def getAccurateRipResponses(data):
-    ret = []
-
-    while data:
-        trackCount = struct.unpack("B", data[0])[0]
-        bytes = 1 + 12 + trackCount * (1 + 8)
-
-        ret.append(AccurateRipResponse(data[:bytes]))
-        data = data[bytes:]
-
-    return ret
-
-class AccurateRipResponse(object):
-    """
-    I represent the response of the AccurateRip online database.
-    """
-
-    trackCount = None
-    discId1 = ""
-    discId2 = ""
-    cddbDiscId = ""
-    confidences = None
-    checksums = None
-
-    def __init__(self, data):
-        self.trackCount = struct.unpack("B", data[0])[0]
-        self.discId1 = "%08x" % struct.unpack("<L", data[1:5])[0]
-        self.discId2 = "%08x" % struct.unpack("<L", data[5:9])[0]
-        self.cddbDiscId = "%08x" % struct.unpack("<L", data[9:13])[0]
-
-        self.confidences = []
-        self.checksums = []
-
-        pos = 13
-        for _ in range(self.trackCount):
-            confidence = struct.unpack("B", data[pos])[0]
-            checksum = "%08x" % struct.unpack("<L", data[pos + 1:pos + 5])[0]
-            pos += 9
-            self.confidences.append(confidence)
-            self.checksums.append(checksum)
diff --git a/morituri/test/Makefile.am b/morituri/test/Makefile.am
index 6e91dfb..38d6634 100644
--- a/morituri/test/Makefile.am
+++ b/morituri/test/Makefile.am
@@ -3,6 +3,7 @@ CLEANFILES = *.py{c,o}
 EXTRA_DIST = \
 	__init__.py \
 	common.py \
+	test_common_accurip.py \
 	test_common_renamer.py \
 	test_image_cue.py \
 	test_image_image.py \
diff --git a/morituri/test/test_common_accurip.py b/morituri/test/test_common_accurip.py
new file mode 100644
index 0000000..484642a
--- /dev/null
+++ b/morituri/test/test_common_accurip.py
@@ -0,0 +1,29 @@
+# -*- Mode: Python; test-case-name: morituri.test.test_common_accurip -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+import os
+import unittest
+
+from morituri.common import accurip, common
+
+class AccurateRipResponseTestCase(unittest.TestCase):
+    def testResponse(self):
+        path = os.path.join(os.path.dirname(__file__),
+            'dBAR-011-0010e284-009228a3-9809ff0b.bin')
+        data = open(path, "rb").read()
+
+        responses = accurip.getAccurateRipResponses(data)
+        self.assertEquals(len(responses), 3)
+
+
+        response = responses[0]
+
+        self.assertEquals(response.trackCount, 11)
+        self.assertEquals(response.discId1, "0010e284")
+        self.assertEquals(response.discId2, "009228a3")
+        self.assertEquals(response.cddbDiscId, "9809ff0b")
+
+        for i in range(11):
+            self.assertEquals(response.confidences[i], 35)
+        self.assertEquals(response.checksums[0], "beea32c8")
+        self.assertEquals(response.checksums[10], "acee98ca")
diff --git a/morituri/test/test_image_image.py b/morituri/test/test_image_image.py
index 7468235..7dd7340 100644
--- a/morituri/test/test_image_image.py
+++ b/morituri/test/test_image_image.py
@@ -1,4 +1,4 @@
-# -*- Mode: Python; test-case-name: morituri.test.test_image_cue -*-
+# -*- Mode: Python; test-case-name: morituri.test.test_image_image -*-
 # vi:si:et:sw=4:sts=4:ts=4
 
 import os
@@ -80,25 +80,3 @@ class AudioLengthTestCase(unittest.TestCase):
         runner = task.SyncRunner()
         runner.run(t, verbose=False)
         self.assertEquals(t.length, 10 * common.SAMPLES_PER_FRAME)
-
-class AccurateRipResponseTestCase(unittest.TestCase):
-    def testResponse(self):
-        path = os.path.join(os.path.dirname(__file__),
-            'dBAR-011-0010e284-009228a3-9809ff0b.bin')
-        data = open(path, "rb").read()
-
-        responses = image.getAccurateRipResponses(data)
-        self.assertEquals(len(responses), 3)
-
-
-        response = responses[0]
-
-        self.assertEquals(response.trackCount, 11)
-        self.assertEquals(response.discId1, "0010e284")
-        self.assertEquals(response.discId2, "009228a3")
-        self.assertEquals(response.cddbDiscId, "9809ff0b")
-
-        for i in range(11):
-            self.assertEquals(response.confidences[i], 35)
-        self.assertEquals(response.checksums[0], "beea32c8")
-        self.assertEquals(response.checksums[10], "acee98ca")

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list