@@ -433,16 +433,16 @@ mod test {
433
433
where
434
434
T : de:: DeserializeOwned + PartialEq + std:: fmt:: Debug ,
435
435
{
436
- let gil = Python :: acquire_gil ( ) ;
437
- let py = gil . python ( ) ;
438
- let locals = PyDict :: new ( py ) ;
439
- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
440
- . unwrap ( ) ;
441
- let obj = locals . get_item ( " obj" ) . unwrap ( ) ;
442
- let actual : T = depythonize ( obj ) . unwrap ( ) ;
443
- assert_eq ! ( & actual , expected ) ;
444
- let actual_json : JsonValue = depythonize ( obj ) . unwrap ( ) ;
445
- assert_eq ! ( & actual_json , expected_json ) ;
436
+ Python :: with_gil ( |py| {
437
+ let locals = PyDict :: new ( py ) ;
438
+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
439
+ . unwrap ( ) ;
440
+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
441
+ let actual : T = depythonize ( obj) . unwrap ( ) ;
442
+ assert_eq ! ( & actual , expected ) ;
443
+ let actual_json : JsonValue = depythonize ( obj ) . unwrap ( ) ;
444
+ assert_eq ! ( & actual_json , expected_json ) ;
445
+ } ) ;
446
446
}
447
447
448
448
#[ test]
@@ -489,16 +489,16 @@ mod test {
489
489
490
490
let code = "{'foo': 'Foo'}" ;
491
491
492
- let gil = Python :: acquire_gil ( ) ;
493
- let py = gil . python ( ) ;
494
- let locals = PyDict :: new ( py ) ;
495
- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
496
- . unwrap ( ) ;
497
- let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
498
- assert ! ( matches! (
499
- * depythonize :: < Struct > ( obj ) . unwrap_err ( ) . inner ,
500
- ErrorImpl :: Message ( msg ) if msg == "missing field `bar`"
501
- ) ) ;
492
+ Python :: with_gil ( |py| {
493
+ let locals = PyDict :: new ( py ) ;
494
+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
495
+ . unwrap ( ) ;
496
+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
497
+ assert ! ( matches! (
498
+ * depythonize :: < Struct > ( obj ) . unwrap_err ( ) . inner ,
499
+ ErrorImpl :: Message ( msg ) if msg == "missing field `bar`"
500
+ ) ) ;
501
+ } )
502
502
}
503
503
504
504
#[ test]
@@ -519,16 +519,16 @@ mod test {
519
519
520
520
let code = "('cat', -10.05, 'foo')" ;
521
521
522
- let gil = Python :: acquire_gil ( ) ;
523
- let py = gil . python ( ) ;
524
- let locals = PyDict :: new ( py ) ;
525
- py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
526
- . unwrap ( ) ;
527
- let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
528
- assert ! ( matches! (
529
- * depythonize :: < TupleStruct > ( obj ) . unwrap_err ( ) . inner ,
530
- ErrorImpl :: IncorrectSequenceLength { expected , got } if expected == 2 && got == 3
531
- ) ) ;
522
+ Python :: with_gil ( |py| {
523
+ let locals = PyDict :: new ( py ) ;
524
+ py . run ( & format ! ( "obj = {}" , code ) , None , Some ( locals ) )
525
+ . unwrap ( ) ;
526
+ let obj = locals . get_item ( "obj" ) . unwrap ( ) ;
527
+ assert ! ( matches! (
528
+ * depythonize :: < TupleStruct > ( obj ) . unwrap_err ( ) . inner ,
529
+ ErrorImpl :: IncorrectSequenceLength { expected , got } if expected == 2 && got == 3
530
+ ) ) ;
531
+ } )
532
532
}
533
533
534
534
#[ test]
0 commit comments