@@ -546,8 +546,7 @@ def func(current):
546546 self .assertIsInstance (cell , cell_type )
547547 self .assertIs (cell .cell_contents , result )
548548
549- def testSetstateFailure (self ):
550- # incomplete, just one of many failure modes of stackless._stackless._wrap.frame.__setstate__
549+ def _test_setstate_prepare (self ):
551550 foo = "foo"
552551
553552 def f1 (bar = "bar" ):
@@ -567,14 +566,43 @@ def f2():
567566
568567 r = f2 ()
569568 self .assertEqual (len (r ), 3 )
569+
570+ # r is a tuple (frame_type, (f_code), (state))
571+ # state is a tuple of the form
572+ # ('f_code', 'valid', 'exec_name', 'f_globals', 'have_locals',
573+ # 'f_locals', 'f_trace', 'f_lasti', 'f_lineno',
574+ # 'blockstack_as_tuple', 'localsplus_as_tuple')
575+ return r
576+
577+ def test_setstate_OK (self ):
578+ r = self ._test_setstate_prepare ()
570579 wrap_frame = r [0 ](* r [1 ])
571580 self .assertIsInstance (wrap_frame , stackless ._stackless ._wrap .frame )
572- invalid_state = r [2 ][:- 2 ] + ((("Not a" , "tuple of 3" , "integers" ),), r [2 ][- 1 ])
573- self .assertRaisesRegex (TypeError , "an integer is required" , wrap_frame .__setstate__ , invalid_state )
574581 # must not raise an assertion
575582 wrap_frame .__setstate__ (r [2 ])
576583 self .assertIs (type (wrap_frame ), types .FrameType )
577584
585+ def test_setstate_invalid_blockstack (self ):
586+ r = self ._test_setstate_prepare ()
587+ # incomplete, just one of many failure modes of stackless._stackless._wrap.frame.__setstate__
588+ wrap_frame = r [0 ](* r [1 ])
589+ invalid_state = r [2 ][:- 2 ] + ((("Not a" , "tuple of 3" , "integers" ),), r [2 ][- 1 ])
590+ self .assertRaisesRegex (TypeError , "an integer is required" , wrap_frame .__setstate__ , invalid_state )
591+
592+ def test_setstate_invalid_state (self ):
593+ r = self ._test_setstate_prepare ()
594+ # incomplete, just one of many failure modes of stackless._stackless._wrap.frame.__setstate__
595+ wrap_frame = r [0 ](* r [1 ])
596+ invalid_state = ('completely' , 'wrong' )
597+ self .assertRaisesRegex (TypeError , "takes exactly 11 arguments" , wrap_frame .__setstate__ , invalid_state )
598+
599+ def test_setstate_different_code (self ):
600+ r = self ._test_setstate_prepare ()
601+ # incomplete, just one of many failure modes of stackless._stackless._wrap.frame.__setstate__
602+ wrap_frame = r [0 ]((lambda :None ).__code__ )
603+ invalid_state = r [2 ]
604+ self .assertRaisesRegex (TypeError , "invalid code object for frame_setstate" , wrap_frame .__setstate__ , invalid_state )
605+
578606
579607class TestDictViewPickling (StacklessPickleTestCase ):
580608
0 commit comments