Mercurial > hg
comparison tests/test-cbor.py @ 51700:7f0cb9ee0534
Backout accidental publication of a large range of revisions
I accidentally published 25e7f9dcad0f::bd1483fd7088, this is the inverse.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 23 Jul 2024 10:02:46 +0200 |
parents | 493034cc3265 |
children | ca7bde5dbafb |
comparison
equal
deleted
inserted
replaced
51699:bd1483fd7088 | 51700:7f0cb9ee0534 |
---|---|
214 ] | 214 ] |
215 | 215 |
216 for size in lens: | 216 for size in lens: |
217 if size < 24: | 217 if size < 24: |
218 hlen = 1 | 218 hlen = 1 |
219 elif size < 2**8: | 219 elif size < 2 ** 8: |
220 hlen = 2 | 220 hlen = 2 |
221 elif size < 2**16: | 221 elif size < 2 ** 16: |
222 hlen = 3 | 222 hlen = 3 |
223 elif size < 2**32: | 223 elif size < 2 ** 32: |
224 hlen = 5 | 224 hlen = 5 |
225 else: | 225 else: |
226 assert False | 226 assert False |
227 | 227 |
228 source = b'x' * size | 228 source = b'x' * size |
485 cborutil.decodeitem(encoded[0:2]), | 485 cborutil.decodeitem(encoded[0:2]), |
486 (True, -42, 2, cborutil.SPECIAL_NONE), | 486 (True, -42, 2, cborutil.SPECIAL_NONE), |
487 ) | 487 ) |
488 | 488 |
489 def testdecodepartialushort(self): | 489 def testdecodepartialushort(self): |
490 encoded = b''.join(cborutil.streamencode(2**15)) | 490 encoded = b''.join(cborutil.streamencode(2 ** 15)) |
491 | 491 |
492 self.assertEqual( | 492 self.assertEqual( |
493 cborutil.decodeitem(encoded[0:1]), | 493 cborutil.decodeitem(encoded[0:1]), |
494 (False, None, -2, cborutil.SPECIAL_NONE), | 494 (False, None, -2, cborutil.SPECIAL_NONE), |
495 ) | 495 ) |
497 cborutil.decodeitem(encoded[0:2]), | 497 cborutil.decodeitem(encoded[0:2]), |
498 (False, None, -1, cborutil.SPECIAL_NONE), | 498 (False, None, -1, cborutil.SPECIAL_NONE), |
499 ) | 499 ) |
500 self.assertEqual( | 500 self.assertEqual( |
501 cborutil.decodeitem(encoded[0:5]), | 501 cborutil.decodeitem(encoded[0:5]), |
502 (True, 2**15, 3, cborutil.SPECIAL_NONE), | 502 (True, 2 ** 15, 3, cborutil.SPECIAL_NONE), |
503 ) | 503 ) |
504 | 504 |
505 def testdecodepartialshort(self): | 505 def testdecodepartialshort(self): |
506 encoded = b''.join(cborutil.streamencode(-1024)) | 506 encoded = b''.join(cborutil.streamencode(-1024)) |
507 | 507 |
517 cborutil.decodeitem(encoded[0:3]), | 517 cborutil.decodeitem(encoded[0:3]), |
518 (True, -1024, 3, cborutil.SPECIAL_NONE), | 518 (True, -1024, 3, cborutil.SPECIAL_NONE), |
519 ) | 519 ) |
520 | 520 |
521 def testdecodepartialulong(self): | 521 def testdecodepartialulong(self): |
522 encoded = b''.join(cborutil.streamencode(2**28)) | 522 encoded = b''.join(cborutil.streamencode(2 ** 28)) |
523 | 523 |
524 self.assertEqual( | 524 self.assertEqual( |
525 cborutil.decodeitem(encoded[0:1]), | 525 cborutil.decodeitem(encoded[0:1]), |
526 (False, None, -4, cborutil.SPECIAL_NONE), | 526 (False, None, -4, cborutil.SPECIAL_NONE), |
527 ) | 527 ) |
537 cborutil.decodeitem(encoded[0:4]), | 537 cborutil.decodeitem(encoded[0:4]), |
538 (False, None, -1, cborutil.SPECIAL_NONE), | 538 (False, None, -1, cborutil.SPECIAL_NONE), |
539 ) | 539 ) |
540 self.assertEqual( | 540 self.assertEqual( |
541 cborutil.decodeitem(encoded[0:5]), | 541 cborutil.decodeitem(encoded[0:5]), |
542 (True, 2**28, 5, cborutil.SPECIAL_NONE), | 542 (True, 2 ** 28, 5, cborutil.SPECIAL_NONE), |
543 ) | 543 ) |
544 | 544 |
545 def testdecodepartiallong(self): | 545 def testdecodepartiallong(self): |
546 encoded = b''.join(cborutil.streamencode(-1048580)) | 546 encoded = b''.join(cborutil.streamencode(-1048580)) |
547 | 547 |
565 cborutil.decodeitem(encoded[0:5]), | 565 cborutil.decodeitem(encoded[0:5]), |
566 (True, -1048580, 5, cborutil.SPECIAL_NONE), | 566 (True, -1048580, 5, cborutil.SPECIAL_NONE), |
567 ) | 567 ) |
568 | 568 |
569 def testdecodepartialulonglong(self): | 569 def testdecodepartialulonglong(self): |
570 encoded = b''.join(cborutil.streamencode(2**32)) | 570 encoded = b''.join(cborutil.streamencode(2 ** 32)) |
571 | 571 |
572 self.assertEqual( | 572 self.assertEqual( |
573 cborutil.decodeitem(encoded[0:1]), | 573 cborutil.decodeitem(encoded[0:1]), |
574 (False, None, -8, cborutil.SPECIAL_NONE), | 574 (False, None, -8, cborutil.SPECIAL_NONE), |
575 ) | 575 ) |
601 cborutil.decodeitem(encoded[0:8]), | 601 cborutil.decodeitem(encoded[0:8]), |
602 (False, None, -1, cborutil.SPECIAL_NONE), | 602 (False, None, -1, cborutil.SPECIAL_NONE), |
603 ) | 603 ) |
604 self.assertEqual( | 604 self.assertEqual( |
605 cborutil.decodeitem(encoded[0:9]), | 605 cborutil.decodeitem(encoded[0:9]), |
606 (True, 2**32, 9, cborutil.SPECIAL_NONE), | 606 (True, 2 ** 32, 9, cborutil.SPECIAL_NONE), |
607 ) | 607 ) |
608 | 608 |
609 with self.assertRaisesRegex( | 609 with self.assertRaisesRegex( |
610 cborutil.CBORDecodeError, 'input data not fully consumed' | 610 cborutil.CBORDecodeError, 'input data not fully consumed' |
611 ): | 611 ): |