How to use unpack method in webdriver_manager

Best Python code snippet using webdriver_manager

test_lib_pack.py

Source:test_lib_pack.py Github

copy

Full Screen

...193 self.assert_pack(194 "F", "F;32NF", 4, 2.387939260590663e-38, 6.301941157072183e-36195 )196class TestLibUnpack(PillowTestCase):197 def assert_unpack(self, mode, rawmode, data, *pixels):198 """199 data - either raw bytes with data or just number of bytes in rawmode.200 """201 if isinstance(data, int):202 data_len = data * len(pixels)203 data = bytes(range(1, data_len + 1))204 im = Image.frombytes(mode, (len(pixels), 1), data, "raw", rawmode, 0, 1)205 for x, pixel in enumerate(pixels):206 self.assertEqual(pixel, im.getpixel((x, 0)))207 def test_1(self):208 self.assert_unpack("1", "1", b"\x01", 0, 0, 0, 0, 0, 0, 0, X)209 self.assert_unpack("1", "1;I", b"\x01", X, X, X, X, X, X, X, 0)210 self.assert_unpack("1", "1;R", b"\x01", X, 0, 0, 0, 0, 0, 0, 0)211 self.assert_unpack("1", "1;IR", b"\x01", 0, X, X, X, X, X, X, X)212 self.assert_unpack("1", "1", b"\xaa", X, 0, X, 0, X, 0, X, 0)213 self.assert_unpack("1", "1;I", b"\xaa", 0, X, 0, X, 0, X, 0, X)214 self.assert_unpack("1", "1;R", b"\xaa", 0, X, 0, X, 0, X, 0, X)215 self.assert_unpack("1", "1;IR", b"\xaa", X, 0, X, 0, X, 0, X, 0)216 self.assert_unpack("1", "1;8", b"\x00\x01\x02\xff", 0, X, X, X)217 def test_L(self):218 self.assert_unpack("L", "L;2", b"\xe4", 255, 170, 85, 0)219 self.assert_unpack("L", "L;2I", b"\xe4", 0, 85, 170, 255)220 self.assert_unpack("L", "L;2R", b"\xe4", 0, 170, 85, 255)221 self.assert_unpack("L", "L;2IR", b"\xe4", 255, 85, 170, 0)222 self.assert_unpack("L", "L;4", b"\x02\xef", 0, 34, 238, 255)223 self.assert_unpack("L", "L;4I", b"\x02\xef", 255, 221, 17, 0)224 self.assert_unpack("L", "L;4R", b"\x02\xef", 68, 0, 255, 119)225 self.assert_unpack("L", "L;4IR", b"\x02\xef", 187, 255, 0, 136)226 self.assert_unpack("L", "L", 1, 1, 2, 3, 4)227 self.assert_unpack("L", "L;I", 1, 254, 253, 252, 251)228 self.assert_unpack("L", "L;R", 1, 128, 64, 192, 32)229 self.assert_unpack("L", "L;16", 2, 2, 4, 6, 8)230 self.assert_unpack("L", "L;16B", 2, 1, 3, 5, 7)231 self.assert_unpack("L", "L;16", b"\x00\xc6\x00\xaf", 198, 175)232 self.assert_unpack("L", "L;16B", b"\xc6\x00\xaf\x00", 198, 175)233 def test_LA(self):234 self.assert_unpack("LA", "LA", 2, (1, 2), (3, 4), (5, 6))235 self.assert_unpack("LA", "LA;L", 2, (1, 4), (2, 5), (3, 6))236 def test_La(self):237 self.assert_unpack("La", "La", 2, (1, 2), (3, 4), (5, 6))238 def test_P(self):239 self.assert_unpack("P", "P;1", b"\xe4", 1, 1, 1, 0, 0, 1, 0, 0)240 self.assert_unpack("P", "P;2", b"\xe4", 3, 2, 1, 0)241 # erroneous?242 # self.assert_unpack("P", "P;2L", b'\xe4', 1, 1, 1, 0)243 self.assert_unpack("P", "P;4", b"\x02\xef", 0, 2, 14, 15)244 # erroneous?245 # self.assert_unpack("P", "P;4L", b'\x02\xef', 2, 10, 10, 0)246 self.assert_unpack("P", "P", 1, 1, 2, 3, 4)247 self.assert_unpack("P", "P;R", 1, 128, 64, 192, 32)248 def test_PA(self):249 self.assert_unpack("PA", "PA", 2, (1, 2), (3, 4), (5, 6))250 self.assert_unpack("PA", "PA;L", 2, (1, 4), (2, 5), (3, 6))251 def test_RGB(self):252 self.assert_unpack("RGB", "RGB", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))253 self.assert_unpack("RGB", "RGB;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))254 self.assert_unpack("RGB", "RGB;R", 3, (128, 64, 192), (32, 160, 96))255 self.assert_unpack("RGB", "RGB;16L", 6, (2, 4, 6), (8, 10, 12))256 self.assert_unpack("RGB", "RGB;16B", 6, (1, 3, 5), (7, 9, 11))257 self.assert_unpack("RGB", "BGR", 3, (3, 2, 1), (6, 5, 4), (9, 8, 7))258 self.assert_unpack("RGB", "RGB;15", 2, (8, 131, 0), (24, 0, 8))259 self.assert_unpack("RGB", "BGR;15", 2, (0, 131, 8), (8, 0, 24))260 self.assert_unpack("RGB", "RGB;16", 2, (8, 64, 0), (24, 129, 0))261 self.assert_unpack("RGB", "BGR;16", 2, (0, 64, 8), (0, 129, 24))262 self.assert_unpack("RGB", "RGB;4B", 2, (17, 0, 34), (51, 0, 68))263 self.assert_unpack("RGB", "RGBX", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))264 self.assert_unpack("RGB", "RGBX;L", 4, (1, 4, 7), (2, 5, 8), (3, 6, 9))265 self.assert_unpack("RGB", "BGRX", 4, (3, 2, 1), (7, 6, 5), (11, 10, 9))266 self.assert_unpack("RGB", "XRGB", 4, (2, 3, 4), (6, 7, 8), (10, 11, 12))267 self.assert_unpack("RGB", "XBGR", 4, (4, 3, 2), (8, 7, 6), (12, 11, 10))268 self.assert_unpack(269 "RGB",270 "YCC;P",271 b"D]\x9c\x82\x1a\x91\xfaOC\xe7J\x12", # random data272 (127, 102, 0),273 (192, 227, 0),274 (213, 255, 170),275 (98, 255, 133),276 )277 self.assert_unpack("RGB", "R", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))278 self.assert_unpack("RGB", "G", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))279 self.assert_unpack("RGB", "B", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))280 def test_RGBA(self):281 self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))282 self.assert_unpack(283 "RGBA", "LA;16B", 4, (1, 1, 1, 3), (5, 5, 5, 7), (9, 9, 9, 11)284 )285 self.assert_unpack(286 "RGBA", "RGBA", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)287 )288 self.assert_unpack(289 "RGBA", "RGBAX", 5, (1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14)290 )291 self.assert_unpack(292 "RGBA", "RGBAXX", 6, (1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16)293 )294 self.assert_unpack(295 "RGBA",296 "RGBa",297 4,298 (63, 127, 191, 4),299 (159, 191, 223, 8),300 (191, 212, 233, 12),301 )302 self.assert_unpack(303 "RGBA",304 "RGBa",305 b"\x01\x02\x03\x00\x10\x20\x30\x7f\x10\x20\x30\xff",306 (0, 0, 0, 0),307 (32, 64, 96, 127),308 (16, 32, 48, 255),309 )310 self.assert_unpack(311 "RGBA",312 "RGBaX",313 b"\x01\x02\x03\x00-\x10\x20\x30\x7f-\x10\x20\x30\xff-",314 (0, 0, 0, 0),315 (32, 64, 96, 127),316 (16, 32, 48, 255),317 )318 self.assert_unpack(319 "RGBA",320 "RGBaXX",321 b"\x01\x02\x03\x00==\x10\x20\x30\x7f!!\x10\x20\x30\xff??",322 (0, 0, 0, 0),323 (32, 64, 96, 127),324 (16, 32, 48, 255),325 )326 self.assert_unpack(327 "RGBA",328 "RGBa;16L",329 8,330 (63, 127, 191, 8),331 (159, 191, 223, 16),332 (191, 212, 233, 24),333 )334 self.assert_unpack(335 "RGBA",336 "RGBa;16L",337 b"\x88\x01\x88\x02\x88\x03\x88\x00\x88\x10\x88\x20\x88\x30\x88\xff",338 (0, 0, 0, 0),339 (16, 32, 48, 255),340 )341 self.assert_unpack(342 "RGBA",343 "RGBa;16B",344 8,345 (36, 109, 182, 7),346 (153, 187, 221, 15),347 (188, 210, 232, 23),348 )349 self.assert_unpack(350 "RGBA",351 "RGBa;16B",352 b"\x01\x88\x02\x88\x03\x88\x00\x88\x10\x88\x20\x88\x30\x88\xff\x88",353 (0, 0, 0, 0),354 (16, 32, 48, 255),355 )356 self.assert_unpack(357 "RGBA",358 "BGRa",359 4,360 (191, 127, 63, 4),361 (223, 191, 159, 8),362 (233, 212, 191, 12),363 )364 self.assert_unpack(365 "RGBA",366 "BGRa",367 b"\x01\x02\x03\x00\x10\x20\x30\xff",368 (0, 0, 0, 0),369 (48, 32, 16, 255),370 )371 self.assert_unpack(372 "RGBA",373 "RGBA;I",374 4,375 (254, 253, 252, 4),376 (250, 249, 248, 8),377 (246, 245, 244, 12),378 )379 self.assert_unpack(380 "RGBA", "RGBA;L", 4, (1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)381 )382 self.assert_unpack("RGBA", "RGBA;15", 2, (8, 131, 0, 0), (24, 0, 8, 0))383 self.assert_unpack("RGBA", "BGRA;15", 2, (0, 131, 8, 0), (8, 0, 24, 0))384 self.assert_unpack("RGBA", "RGBA;4B", 2, (17, 0, 34, 0), (51, 0, 68, 0))385 self.assert_unpack("RGBA", "RGBA;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16))386 self.assert_unpack("RGBA", "RGBA;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15))387 self.assert_unpack(388 "RGBA", "BGRA", 4, (3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12)389 )390 self.assert_unpack(391 "RGBA", "ARGB", 4, (2, 3, 4, 1), (6, 7, 8, 5), (10, 11, 12, 9)392 )393 self.assert_unpack(394 "RGBA", "ABGR", 4, (4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9)395 )396 self.assert_unpack(397 "RGBA",398 "YCCA;P",399 b"]bE\x04\xdd\xbej\xed57T\xce\xac\xce:\x11", # random data400 (0, 161, 0, 4),401 (255, 255, 255, 237),402 (27, 158, 0, 206),403 (0, 118, 0, 17),404 )405 self.assert_unpack("RGBA", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))406 self.assert_unpack("RGBA", "G", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))407 self.assert_unpack("RGBA", "B", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))408 self.assert_unpack("RGBA", "A", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))409 def test_RGBa(self):410 self.assert_unpack(411 "RGBa", "RGBa", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)412 )413 self.assert_unpack(414 "RGBa", "BGRa", 4, (3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12)415 )416 self.assert_unpack(417 "RGBa", "aRGB", 4, (2, 3, 4, 1), (6, 7, 8, 5), (10, 11, 12, 9)418 )419 self.assert_unpack(420 "RGBa", "aBGR", 4, (4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9)421 )422 def test_RGBX(self):423 self.assert_unpack("RGBX", "RGB", 3, (1, 2, 3, X), (4, 5, 6, X), (7, 8, 9, X))424 self.assert_unpack("RGBX", "RGB;L", 3, (1, 4, 7, X), (2, 5, 8, X), (3, 6, 9, X))425 self.assert_unpack("RGBX", "RGB;16B", 6, (1, 3, 5, X), (7, 9, 11, X))426 self.assert_unpack("RGBX", "BGR", 3, (3, 2, 1, X), (6, 5, 4, X), (9, 8, 7, X))427 self.assert_unpack("RGBX", "RGB;15", 2, (8, 131, 0, X), (24, 0, 8, X))428 self.assert_unpack("RGBX", "BGR;15", 2, (0, 131, 8, X), (8, 0, 24, X))429 self.assert_unpack("RGBX", "RGB;4B", 2, (17, 0, 34, X), (51, 0, 68, X))430 self.assert_unpack(431 "RGBX", "RGBX", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)432 )433 self.assert_unpack(434 "RGBX", "RGBXX", 5, (1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14)435 )436 self.assert_unpack(437 "RGBX", "RGBXXX", 6, (1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16)438 )439 self.assert_unpack(440 "RGBX", "RGBX;L", 4, (1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)441 )442 self.assert_unpack("RGBX", "RGBX;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16))443 self.assert_unpack("RGBX", "RGBX;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15))444 self.assert_unpack(445 "RGBX", "BGRX", 4, (3, 2, 1, X), (7, 6, 5, X), (11, 10, 9, X)446 )447 self.assert_unpack(448 "RGBX", "XRGB", 4, (2, 3, 4, X), (6, 7, 8, X), (10, 11, 12, X)449 )450 self.assert_unpack(451 "RGBX", "XBGR", 4, (4, 3, 2, X), (8, 7, 6, X), (12, 11, 10, X)452 )453 self.assert_unpack(454 "RGBX",455 "YCC;P",456 b"D]\x9c\x82\x1a\x91\xfaOC\xe7J\x12", # random data457 (127, 102, 0, X),458 (192, 227, 0, X),459 (213, 255, 170, X),460 (98, 255, 133, X),461 )462 self.assert_unpack("RGBX", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))463 self.assert_unpack("RGBX", "G", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))464 self.assert_unpack("RGBX", "B", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))465 self.assert_unpack("RGBX", "X", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))466 def test_CMYK(self):467 self.assert_unpack(468 "CMYK", "CMYK", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)469 )470 self.assert_unpack(471 "CMYK", "CMYKX", 5, (1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14)472 )473 self.assert_unpack(474 "CMYK", "CMYKXX", 6, (1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16)475 )476 self.assert_unpack(477 "CMYK",478 "CMYK;I",479 4,480 (254, 253, 252, 251),481 (250, 249, 248, 247),482 (246, 245, 244, 243),483 )484 self.assert_unpack(485 "CMYK", "CMYK;L", 4, (1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)486 )487 self.assert_unpack("CMYK", "C", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))488 self.assert_unpack("CMYK", "M", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))489 self.assert_unpack("CMYK", "Y", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))490 self.assert_unpack("CMYK", "K", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))491 self.assert_unpack(492 "CMYK", "C;I", 1, (254, 0, 0, 0), (253, 0, 0, 0), (252, 0, 0, 0)493 )494 self.assert_unpack(495 "CMYK", "M;I", 1, (0, 254, 0, 0), (0, 253, 0, 0), (0, 252, 0, 0)496 )497 self.assert_unpack(498 "CMYK", "Y;I", 1, (0, 0, 254, 0), (0, 0, 253, 0), (0, 0, 252, 0)499 )500 self.assert_unpack(501 "CMYK", "K;I", 1, (0, 0, 0, 254), (0, 0, 0, 253), (0, 0, 0, 252)502 )503 def test_YCbCr(self):504 self.assert_unpack("YCbCr", "YCbCr", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))505 self.assert_unpack("YCbCr", "YCbCr;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))506 self.assert_unpack("YCbCr", "YCbCrK", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))507 self.assert_unpack("YCbCr", "YCbCrX", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))508 def test_LAB(self):509 self.assert_unpack("LAB", "LAB", 3, (1, 130, 131), (4, 133, 134), (7, 136, 137))510 self.assert_unpack("LAB", "L", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))511 self.assert_unpack("LAB", "A", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))512 self.assert_unpack("LAB", "B", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))513 def test_HSV(self):514 self.assert_unpack("HSV", "HSV", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))515 self.assert_unpack("HSV", "H", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))516 self.assert_unpack("HSV", "S", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))517 self.assert_unpack("HSV", "V", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))518 def test_I(self):519 self.assert_unpack("I", "I;8", 1, 0x01, 0x02, 0x03, 0x04)520 self.assert_unpack("I", "I;8S", b"\x01\x83", 1, -125)521 self.assert_unpack("I", "I;16", 2, 0x0201, 0x0403)522 self.assert_unpack("I", "I;16S", b"\x83\x01\x01\x83", 0x0183, -31999)523 self.assert_unpack("I", "I;16B", 2, 0x0102, 0x0304)524 self.assert_unpack("I", "I;16BS", b"\x83\x01\x01\x83", -31999, 0x0183)525 self.assert_unpack("I", "I;32", 4, 0x04030201, 0x08070605)526 self.assert_unpack(527 "I", "I;32S", b"\x83\x00\x00\x01\x01\x00\x00\x83", 0x01000083, -2097151999528 )529 self.assert_unpack("I", "I;32B", 4, 0x01020304, 0x05060708)530 self.assert_unpack(531 "I", "I;32BS", b"\x83\x00\x00\x01\x01\x00\x00\x83", -2097151999, 0x01000083532 )533 if sys.byteorder == "little":534 self.assert_unpack("I", "I", 4, 0x04030201, 0x08070605)535 self.assert_unpack("I", "I;16N", 2, 0x0201, 0x0403)536 self.assert_unpack("I", "I;16NS", b"\x83\x01\x01\x83", 0x0183, -31999)537 self.assert_unpack("I", "I;32N", 4, 0x04030201, 0x08070605)538 self.assert_unpack(539 "I",540 "I;32NS",541 b"\x83\x00\x00\x01\x01\x00\x00\x83",542 0x01000083,543 -2097151999,544 )545 else:546 self.assert_unpack("I", "I", 4, 0x01020304, 0x05060708)547 self.assert_unpack("I", "I;16N", 2, 0x0102, 0x0304)548 self.assert_unpack("I", "I;16NS", b"\x83\x01\x01\x83", -31999, 0x0183)549 self.assert_unpack("I", "I;32N", 4, 0x01020304, 0x05060708)550 self.assert_unpack(551 "I",552 "I;32NS",553 b"\x83\x00\x00\x01\x01\x00\x00\x83",554 -2097151999,555 0x01000083,556 )557 def test_F_int(self):558 self.assert_unpack("F", "F;8", 1, 0x01, 0x02, 0x03, 0x04)559 self.assert_unpack("F", "F;8S", b"\x01\x83", 1, -125)560 self.assert_unpack("F", "F;16", 2, 0x0201, 0x0403)561 self.assert_unpack("F", "F;16S", b"\x83\x01\x01\x83", 0x0183, -31999)562 self.assert_unpack("F", "F;16B", 2, 0x0102, 0x0304)563 self.assert_unpack("F", "F;16BS", b"\x83\x01\x01\x83", -31999, 0x0183)564 self.assert_unpack("F", "F;32", 4, 67305984, 134678016)565 self.assert_unpack(566 "F", "F;32S", b"\x83\x00\x00\x01\x01\x00\x00\x83", 16777348, -2097152000567 )568 self.assert_unpack("F", "F;32B", 4, 0x01020304, 0x05060708)569 self.assert_unpack(570 "F", "F;32BS", b"\x83\x00\x00\x01\x01\x00\x00\x83", -2097152000, 16777348571 )572 if sys.byteorder == "little":573 self.assert_unpack("F", "F;16N", 2, 0x0201, 0x0403)574 self.assert_unpack("F", "F;16NS", b"\x83\x01\x01\x83", 0x0183, -31999)575 self.assert_unpack("F", "F;32N", 4, 67305984, 134678016)576 self.assert_unpack(577 "F",578 "F;32NS",579 b"\x83\x00\x00\x01\x01\x00\x00\x83",580 16777348,581 -2097152000,582 )583 else:584 self.assert_unpack("F", "F;16N", 2, 0x0102, 0x0304)585 self.assert_unpack("F", "F;16NS", b"\x83\x01\x01\x83", -31999, 0x0183)586 self.assert_unpack("F", "F;32N", 4, 0x01020304, 0x05060708)587 self.assert_unpack(588 "F",589 "F;32NS",590 b"\x83\x00\x00\x01\x01\x00\x00\x83",591 -2097152000,592 16777348,593 )594 def test_F_float(self):595 self.assert_unpack(596 "F", "F;32F", 4, 1.539989614439558e-36, 4.063216068939723e-34597 )598 self.assert_unpack(599 "F", "F;32BF", 4, 2.387939260590663e-38, 6.301941157072183e-36600 )601 self.assert_unpack(602 "F",603 "F;64F",604 b"333333\xc3?\x00\x00\x00\x00\x00J\x93\xc0", # by struct.pack605 0.15000000596046448,606 -1234.5,607 )608 self.assert_unpack(609 "F",610 "F;64BF",611 b"?\xc3333333\xc0\x93J\x00\x00\x00\x00\x00", # by struct.pack612 0.15000000596046448,613 -1234.5,614 )615 if sys.byteorder == "little":616 self.assert_unpack(617 "F", "F", 4, 1.539989614439558e-36, 4.063216068939723e-34618 )619 self.assert_unpack(620 "F", "F;32NF", 4, 1.539989614439558e-36, 4.063216068939723e-34621 )622 self.assert_unpack(623 "F",624 "F;64NF",625 b"333333\xc3?\x00\x00\x00\x00\x00J\x93\xc0",626 0.15000000596046448,627 -1234.5,628 )629 else:630 self.assert_unpack(631 "F", "F", 4, 2.387939260590663e-38, 6.301941157072183e-36632 )633 self.assert_unpack(634 "F", "F;32NF", 4, 2.387939260590663e-38, 6.301941157072183e-36635 )636 self.assert_unpack(637 "F",638 "F;64NF",639 b"?\xc3333333\xc0\x93J\x00\x00\x00\x00\x00",640 0.15000000596046448,641 -1234.5,642 )643 def test_I16(self):644 self.assert_unpack("I;16", "I;16", 2, 0x0201, 0x0403, 0x0605)645 self.assert_unpack("I;16B", "I;16B", 2, 0x0102, 0x0304, 0x0506)646 self.assert_unpack("I;16L", "I;16L", 2, 0x0201, 0x0403, 0x0605)647 self.assert_unpack("I;16", "I;12", 2, 0x0010, 0x0203, 0x0040)648 if sys.byteorder == "little":649 self.assert_unpack("I;16", "I;16N", 2, 0x0201, 0x0403, 0x0605)650 self.assert_unpack("I;16B", "I;16N", 2, 0x0201, 0x0403, 0x0605)651 self.assert_unpack("I;16L", "I;16N", 2, 0x0201, 0x0403, 0x0605)652 else:653 self.assert_unpack("I;16", "I;16N", 2, 0x0102, 0x0304, 0x0506)654 self.assert_unpack("I;16B", "I;16N", 2, 0x0102, 0x0304, 0x0506)655 self.assert_unpack("I;16L", "I;16N", 2, 0x0102, 0x0304, 0x0506)656 def test_CMYK16(self):657 self.assert_unpack("CMYK", "CMYK;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16))658 self.assert_unpack("CMYK", "CMYK;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15))659 if sys.byteorder == "little":660 self.assert_unpack("CMYK", "CMYK;16N", 8, (2, 4, 6, 8), (10, 12, 14, 16))661 else:662 self.assert_unpack("CMYK", "CMYK;16N", 8, (1, 3, 5, 7), (9, 11, 13, 15))663 def test_value_error(self):664 self.assertRaises(ValueError, self.assert_unpack, "L", "L", 0, 0)665 self.assertRaises(ValueError, self.assert_unpack, "RGB", "RGB", 2, 0)...

Full Screen

Full Screen

xdrlib.py

Source:xdrlib.py Github

copy

Full Screen

...141 self.__pos = j = i+4142 data = self.__buf[i:j]143 if len(data) < 4:144 raise EOFError145 x = struct.unpack('>L', data)[0]146 try:147 return int(x)148 except OverflowError:149 return x150151 def unpack_int(self):152 i = self.__pos153 self.__pos = j = i+4154 data = self.__buf[i:j]155 if len(data) < 4:156 raise EOFError157 return struct.unpack('>l', data)[0]158159 unpack_enum = unpack_int160161 def unpack_bool(self):162 return bool(self.unpack_int())163164 def unpack_uhyper(self):165 hi = self.unpack_uint()166 lo = self.unpack_uint()167 return long(hi)<<32 | lo168169 def unpack_hyper(self):170 x = self.unpack_uhyper()171 if x >= 0x8000000000000000L:172 x = x - 0x10000000000000000L173 return x174175 def unpack_float(self):176 i = self.__pos177 self.__pos = j = i+4178 data = self.__buf[i:j]179 if len(data) < 4:180 raise EOFError181 return struct.unpack('>f', data)[0]182183 def unpack_double(self):184 i = self.__pos185 self.__pos = j = i+8186 data = self.__buf[i:j]187 if len(data) < 8:188 raise EOFError189 return struct.unpack('>d', data)[0]190191 def unpack_fstring(self, n):192 if n < 0:193 raise ValueError, 'fstring size must be nonnegative'194 i = self.__pos195 j = i + (n+3)//4*4196 if j > len(self.__buf):197 raise EOFError198 self.__pos = j199 return self.__buf[i:i+n]200201 unpack_fopaque = unpack_fstring202203 def unpack_string(self): ...

Full Screen

Full Screen

test_unpack_sequence.py

Source:test_unpack_sequence.py Github

copy

Full Screen

...164 pyfunc = unpack_nrt165 cr = compile_isolated(pyfunc, (), flags=no_pyobj_flags)166 cfunc = cr.entry_point167 self.assertPreciseEqual(cfunc(), pyfunc())168 def test_invalid_unpack(self):169 pyfunc = unpack_arbitrary170 with self.assertRaises(errors.TypingError) as raises:171 compile_isolated(pyfunc, (types.int32,), flags=no_pyobj_flags)172 self.assertIn("failed to unpack int32", str(raises.exception))173if __name__ == '__main__':...

Full Screen

Full Screen

packetDecoder.py

Source:packetDecoder.py Github

copy

Full Screen

1import ctypes, struct, json2from struct import pack_into3def decodeDetailedMarketData(packet_buffer):4 return {5 "mode" : struct.unpack('>b', packet_buffer[0:1])[0],6 "exchange_code" : struct.unpack('>b', packet_buffer[1:2])[0],7 "instrument_token" : struct.unpack('>I', packet_buffer[2:6])[0],8 "last_traded_price" : struct.unpack('>I', packet_buffer[6:10])[0],9 "last_traded_time" : struct.unpack('>I', packet_buffer[10:14])[0],10 "last_traded_quantity" : struct.unpack('>I', packet_buffer[14:18])[0],11 "trade_volume" : struct.unpack('>I', packet_buffer[18:22])[0],12 "best_bid_price" : struct.unpack('>I', packet_buffer[22:26])[0],13 "best_bid_quantity" : struct.unpack('>I', packet_buffer[26:30])[0],14 "best_ask_price" : struct.unpack('>I', packet_buffer[30:34])[0],15 "best_ask_quantity" : struct.unpack('>I', packet_buffer[34:38])[0],16 "total_buy_quantity" : struct.unpack('>Q', packet_buffer[38:46])[0],17 "total_sell_quantity" : struct.unpack('>Q', packet_buffer[46:54])[0],18 "average_trade_price" : struct.unpack('>I', packet_buffer[54:58])[0],19 "exchange_timestamp" : struct.unpack('>I', packet_buffer[58:62])[0],20 "open_price" : struct.unpack('>I', packet_buffer[62:66])[0],21 "high_price" : struct.unpack('>I', packet_buffer[66:70])[0],22 "low_price" : struct.unpack('>I', packet_buffer[70:74])[0],23 "close_price" : struct.unpack('>I', packet_buffer[74:78])[0],24 "yearly_high_price" : struct.unpack('>I', packet_buffer[78:82])[0],25 "yearly_low_price" : struct.unpack('>I', packet_buffer[82:86])[0],26 "lowDPR": struct.unpack('>I', packet_buffer[86:90])[0],27 "highDPR": struct.unpack('>I', packet_buffer[90:94])[0],28 "currentOpenInterest": struct.unpack('>I', packet_buffer[94:98])[0],29 "initialOpenInterest": struct.unpack('>I', packet_buffer[98:102])[0],30 }31def decodeCompactMarketData(packet_buffer):32 return {33 "mode" : struct.unpack('>b', packet_buffer[0:1])[0],34 "exchange_code" : struct.unpack('>b', packet_buffer[1:2])[0],35 "instrument_token" : struct.unpack('>I', packet_buffer[2:6])[0],36 "last_traded_price" : struct.unpack('>I', packet_buffer[6:10])[0],37 "change": struct.unpack('>I', packet_buffer[10:14])[0],38 "last_traded_time": struct.unpack('>I', packet_buffer[14:18])[0],39 "lowDPR": struct.unpack('>I', packet_buffer[18:22])[0],40 "highDPR": struct.unpack('>I', packet_buffer[22:26])[0],41 "currentOpenInterest": struct.unpack('>I', packet_buffer[26:30])[0],42 "initialOpenInterest": struct.unpack('>I', packet_buffer[30:34])[0],43 "bidPrice": struct.unpack('>I', packet_buffer[34:38])[0],44 "askPrice": struct.unpack('>I', packet_buffer[38:42])[0],45 }46def decodeSnapquoteData(packet_buffer):47 return {48 "mode" : struct.unpack('>b', packet_buffer[0:1])[0],49 "exchange_code" : struct.unpack('>b', packet_buffer[1:2])[0],50 "instrument_token" : struct.unpack('>I', packet_buffer[2:6])[0],51 "buyers": [52 struct.unpack('>I', packet_buffer[6:10])[0],53 struct.unpack('>I', packet_buffer[10:14])[0],54 struct.unpack('>I', packet_buffer[14:18])[0],55 struct.unpack('>I', packet_buffer[18:22])[0],56 struct.unpack('>I', packet_buffer[22:26])[0]57 ],58 "bidPrices": [59 struct.unpack('>I', packet_buffer[26:30])[0],60 struct.unpack('>I', packet_buffer[30:34])[0],61 struct.unpack('>I', packet_buffer[34:38])[0],62 struct.unpack('>I', packet_buffer[38:42])[0],63 struct.unpack('>I', packet_buffer[42:46])[0]64 ],65 "bidQtys": [66 struct.unpack('>I', packet_buffer[46:50])[0],67 struct.unpack('>I', packet_buffer[50:54])[0],68 struct.unpack('>I', packet_buffer[54:58])[0],69 struct.unpack('>I', packet_buffer[58:62])[0],70 struct.unpack('>I', packet_buffer[62:66])[0]71 ],72 "sellers": [73 struct.unpack('>I', packet_buffer[66:70])[0],74 struct.unpack('>I', packet_buffer[70:74])[0],75 struct.unpack('>I', packet_buffer[74:78])[0],76 struct.unpack('>I', packet_buffer[78:82])[0],77 struct.unpack('>I', packet_buffer[82:86])[0]78 ],79 "askPrices": [80 struct.unpack('>I', packet_buffer[86:90])[0],81 struct.unpack('>I', packet_buffer[90:94])[0],82 struct.unpack('>I', packet_buffer[94:98])[0],83 struct.unpack('>I', packet_buffer[98:102])[0],84 struct.unpack('>I', packet_buffer[102:106])[0]85 ],86 "askQtys": [87 struct.unpack('>I', packet_buffer[106:110])[0],88 struct.unpack('>I', packet_buffer[110:114])[0],89 struct.unpack('>I', packet_buffer[114:118])[0],90 struct.unpack('>I', packet_buffer[118:122])[0],91 struct.unpack('>I', packet_buffer[122:126])[0]92 ],93 "averageTradePrice": struct.unpack('>I', packet_buffer[126:130])[0],94 "open": struct.unpack('>I', packet_buffer[130:134])[0],95 "high": struct.unpack('>I', packet_buffer[134:138])[0],96 "low" : struct.unpack('>I', packet_buffer[138:142])[0],97 "close" : struct.unpack('>I', packet_buffer[142:146])[0],98 "totalBuyQty" : struct.unpack('>Q', packet_buffer[146:154])[0],99 "totalSellQty": struct.unpack('>Q', packet_buffer[154:162])[0],100 "volume" : struct.unpack('>I', packet_buffer[162:166])[0],101 }102def decodeOrderUpdate(packet_buffer):103 order_update_packet = packet_buffer.decode("utf-8")104 order_update_obj = json.loads(order_update_packet[5:])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run webdriver_manager automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful