Changeset 79279 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Jun 21, 2019 2:24:11 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r79092 r79279 2091 2091 return oLeft == oRight; 2092 2092 2093 # Convert strings to byte arrays: 2093 # 2094 # See if byte/buffer stuff that can be compared directory. If not convert 2095 # strings to bytes. 2096 # 2097 # Note! For 2.x, we must convert both sides to the buffer type or the 2098 # comparison may fail despite it working okay in test cases. 2099 # 2094 2100 if sys.version_info[0] >= 3: 2101 if isinstance(oLeft, (bytearray, memoryview, bytes)) and isinstance(oRight, (bytearray, memoryview, bytes)): # pylint: disable=undefined-variable 2102 return oLeft == oRight; 2103 2095 2104 if isString(oLeft): 2096 2105 try: oLeft = bytes(oLeft, 'utf-8'); … … 2100 2109 except: pass; 2101 2110 else: 2111 if isinstance(oLeft, (bytearray, buffer)) and isinstance(oRight, (bytearray, buffer)): # pylint: disable=undefined-variable 2112 if isinstance(oLeft, bytearray): 2113 oLeft = buffer(oLeft); # pylint: disable=redefined-variable-type,undefined-variable 2114 else: 2115 oRight = buffer(oRight); # pylint: disable=redefined-variable-type,undefined-variable 2116 #print('buf/byte #1 compare: %s (%s vs %s)' % (oLeft == oRight, type(oLeft), type(oRight),)); 2117 return oLeft == oRight; 2118 2102 2119 if isString(oLeft): 2103 2120 try: oLeft = bytearray(oLeft, 'utf-8'); # pylint: disable=redefined-variable-type … … 2111 2128 #print('same type now: %s' % (oLeft == oRight,)); 2112 2129 return oLeft == oRight; 2130 2131 # Check if we now have buffer/memoryview vs bytes/bytesarray again. 2132 if sys.version_info[0] >= 3: 2133 if isinstance(oLeft, (bytearray, memoryview, bytes)) and isinstance(oRight, (bytearray, memoryview, bytes)): # pylint: disable=undefined-variable 2134 return oLeft == oRight; 2135 else: 2136 if isinstance(oLeft, (bytearray, buffer)) and isinstance(oRight, (bytearray, buffer)): # pylint: disable=undefined-variable 2137 if isinstance(oLeft, bytearray): 2138 oLeft = buffer(oLeft); # pylint: disable=redefined-variable-type,undefined-variable 2139 else: 2140 oRight = buffer(oRight); # pylint: disable=redefined-variable-type,undefined-variable 2141 #print('buf/byte #2 compare: %s (%s vs %s)' % (oLeft == oRight, type(oLeft), type(oRight),)); 2142 return oLeft == oRight; 2113 2143 2114 2144 # Do item by item comparison: … … 2186 2216 else: 2187 2217 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2188 bytearray([0x31,0x32,0x32,0x34])), False);2218 bytearray([0x31,0x32,0x33,0x34])), True); 2189 2219 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2190 buffer(bytearray([0x31,0x32,0x33,0x34,0x34]), 0, 4)), True); 2220 bytearray([0x99,0x32,0x32,0x34])), False); 2221 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2222 buffer(bytearray([0x31,0x32,0x33,0x34,0x34]), 0, 4)), True); 2223 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), 2224 buffer(bytearray([0x99,0x32,0x33,0x34,0x34]), 0, 4)), False); 2191 2225 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), b'1234'), True); 2192 2226 self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), '1234'), True);
Note:
See TracChangeset
for help on using the changeset viewer.