Commits

Andrew Wooster committed 9ae27d1

Removing duplicate code. Adding test for 4 byte real values.

Comments (0)

Files changed (4)

biplist/__init__.py

         result = 0
         original_offset = self.currentOffset
         data = self.contents[self.currentOffset:self.currentOffset+bytes]
-        # 1, 2, and 4 byte integers are unsigned
-        if bytes == 1:
-            result = unpack('>B', data)[0]
-        elif bytes == 2:
-            result = unpack('>H', data)[0]
-        elif bytes == 4:
-            result = unpack('>L', data)[0]
-        elif bytes == 8:
-            result = unpack('>q', data)[0]
-        else:
-            raise InvalidPlistException("Encountered integer longer than 8 bytes.")
+        result = self.getSizedInteger(data, bytes)
         self.currentOffset = original_offset + bytes
         return result
     

tests/data/small_real.plist

Binary file added.

tests/test_valid.py

         self.assertEquals(root['boolItem'], True)
         self.assertEquals(root['arrayItem'], ['item0'])
         
-    def test_file_read(self):
+    def testFileRead(self):
         try:
             result = readPlist(data_path('simple_binary.plist'))
             self.validateSimpleBinaryRoot(result)
         result = readPlist(data_path('unicode_empty.plist'))
         self.assertEquals(result, u"")
     
+    def testSmallReal(self):
+        result = readPlist(data_path('small_real.plist'))
+        self.assertEquals(result, {'4 byte real':0.5})
+    
     def testKeyedArchiverPlist(self):
         """
         Archive is created with class like this:

tests/test_write.py

                 got = writer.intSize(test)
                 self.assertEquals(bytelen, got, "Byte size is wrong. Expected %d, got %d" % (bytelen, got))
         
+        bytes_lists = [list(x) for x in bytes]
+        self.roundTrip(bytes_lists)
+        
         try:
             self.roundTrip([0x8000000000000000, pow(2, 63)])
             self.fail("2^63 should be too large for Core Foundation to handle.")