@@ -361,6 +361,88 @@ def test_annotate(self):
361
361
highest protocol among opcodes = 0
362
362
''' , annotate = 20 )
363
363
364
+ def test_string (self ):
365
+ self .check_dis (b"S'abc'\n ." , '''\
366
+ 0: S STRING 'abc'
367
+ 7: . STOP
368
+ highest protocol among opcodes = 0
369
+ ''' )
370
+ self .check_dis (b'S"abc"\n .' , '''\
371
+ 0: S STRING 'abc'
372
+ 7: . STOP
373
+ highest protocol among opcodes = 0
374
+ ''' )
375
+ self .check_dis (b"S'\xc3 \xb5 '\n ." , '''\
376
+ 0: S STRING '\\ xc3\\ xb5'
377
+ 6: . STOP
378
+ highest protocol among opcodes = 0
379
+ ''' )
380
+
381
+ def test_string_without_quotes (self ):
382
+ self .check_dis_error (b"Sabc'\n ." , '' ,
383
+ 'no string quotes around b"abc\' "' )
384
+ self .check_dis_error (b'Sabc"\n .' , '' ,
385
+ "no string quotes around b'abc\" '" )
386
+ self .check_dis_error (b"S'abc\n ." , '' ,
387
+ '''strinq quote b"'" not found at both ends of b"'abc"''' )
388
+ self .check_dis_error (b'S"abc\n .' , '' ,
389
+ r"""strinq quote b'"' not found at both ends of b'"abc'""" )
390
+ self .check_dis_error (b"S'abc\" \n ." , '' ,
391
+ r"""strinq quote b"'" not found at both ends of b'\\'abc"'""" )
392
+ self .check_dis_error (b"S\" abc'\n ." , '' ,
393
+ r"""strinq quote b'"' not found at both ends of b'"abc\\''""" )
394
+
395
+ def test_binstring (self ):
396
+ self .check_dis (b"T\x03 \x00 \x00 \x00 abc." , '''\
397
+ 0: T BINSTRING 'abc'
398
+ 8: . STOP
399
+ highest protocol among opcodes = 1
400
+ ''' )
401
+ self .check_dis (b"T\x02 \x00 \x00 \x00 \xc3 \xb5 ." , '''\
402
+ 0: T BINSTRING '\\ xc3\\ xb5'
403
+ 7: . STOP
404
+ highest protocol among opcodes = 1
405
+ ''' )
406
+
407
+ def test_short_binstring (self ):
408
+ self .check_dis (b"U\x03 abc." , '''\
409
+ 0: U SHORT_BINSTRING 'abc'
410
+ 5: . STOP
411
+ highest protocol among opcodes = 1
412
+ ''' )
413
+ self .check_dis (b"U\x02 \xc3 \xb5 ." , '''\
414
+ 0: U SHORT_BINSTRING '\\ xc3\\ xb5'
415
+ 4: . STOP
416
+ highest protocol among opcodes = 1
417
+ ''' )
418
+
419
+ def test_global (self ):
420
+ self .check_dis (b"cmodule\n name\n ." , '''\
421
+ 0: c GLOBAL 'module name'
422
+ 13: . STOP
423
+ highest protocol among opcodes = 0
424
+ ''' )
425
+ self .check_dis (b"cm\xc3 \xb6 dule\n n\xc3 \xa4 me\n ." , '''\
426
+ 0: c GLOBAL 'm\xf6 dule n\xe4 me'
427
+ 15: . STOP
428
+ highest protocol among opcodes = 0
429
+ ''' )
430
+
431
+ def test_inst (self ):
432
+ self .check_dis (b"(imodule\n name\n ." , '''\
433
+ 0: ( MARK
434
+ 1: i INST 'module name' (MARK at 0)
435
+ 14: . STOP
436
+ highest protocol among opcodes = 0
437
+ ''' )
438
+
439
+ def test_persid (self ):
440
+ self .check_dis (b"Pabc\n ." , '''\
441
+ 0: P PERSID 'abc'
442
+ 5: . STOP
443
+ highest protocol among opcodes = 0
444
+ ''' )
445
+
364
446
365
447
class MiscTestCase (unittest .TestCase ):
366
448
def test__all__ (self ):
0 commit comments