Changeset 78472 in vbox
- Timestamp:
- May 12, 2019 6:28:36 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r78464 r78472 2083 2083 # If both have the same type, use the compare operator of the class: 2084 2084 if type(oLeft) is type(oRight): 2085 #print('same type: %s' % (oLeft == oRight,)); 2085 2086 return oLeft == oRight; 2086 2087 2087 2088 # On the offchance that they're both strings, but of different types. 2088 2089 if isString(oLeft) and isString(oRight): 2090 #print('string compare: %s' % (oLeft == oRight,)); 2089 2091 return oLeft == oRight; 2090 2092 … … 2107 2109 # Check if we now have the same type for both: 2108 2110 if type(oLeft) is type(oRight): 2111 #print('same type now: %s' % (oLeft == oRight,)); 2109 2112 return oLeft == oRight; 2110 2113 2111 2114 # Do item by item comparison: 2112 2115 if len(oLeft) != len(oRight): 2116 #print('different length: %s vs %s' % (len(oLeft), len(oRight))); 2113 2117 return False; 2114 2118 i = len(oLeft); 2115 2119 while i > 0: 2116 2120 i = i - 1; 2117 if oLeft[i] != oRight[i]: 2121 2122 iElmLeft = oLeft[i]; 2123 if not isinstance(iElmLeft, int) and not isinstance(iElmLeft, long): 2124 iElmLeft = ord(iElmLeft); 2125 2126 iElmRight = oRight[i]; 2127 if not isinstance(iElmRight, int) and not isinstance(iElmRight, long): 2128 iElmRight = ord(iElmRight); 2129 2130 if iElmLeft != iElmRight: 2131 #print('element %d differs: %x %x' % (i, iElmLeft, iElmRight,)); 2118 2132 return False; 2119 2133 return True; … … 2125 2139 2126 2140 # pylint: disable=C0111 2141 # pylint: disable=undefined-variable 2127 2142 class BuildCategoryDataTestCase(unittest.TestCase): 2128 2143 def testIntervalSeconds(self): … … 2163 2178 self.assertEqual(areBytesEqual(b'1234', bytearray([0x31,0x32,0x33,0x34])), True); 2164 2179 self.assertEqual(areBytesEqual('1234', bytearray([0x31,0x32,0x33,0x34])), True); 2180 self.assertEqual(areBytesEqual(u'1234', bytearray([0x31,0x32,0x33,0x34])), True); 2165 2181 self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), bytearray([0x31,0x32,0x33,0x34])), True); 2166 2182 self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), '1224'), False); 2167 2183 self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), bytearray([0x31,0x32,0x32,0x34])), False); 2184 if sys.version_info[0] >= 3: 2185 pass; 2186 else: 2187 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2188 bytearray([0x31,0x32,0x32,0x34])), False); 2189 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2190 buffer(bytearray([0x31,0x32,0x33,0x34,0x34]), 0, 4)), True); 2191 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), b'1234'), True); 2192 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), '1234'), True); 2193 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), u'1234'), True); 2168 2194 2169 2195 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.