@@ -56,10 +56,8 @@ fn instance_method_with_args() {
56
56
let obj = PyCell :: new ( py, InstanceMethodWithArgs { member : 7 } ) . unwrap ( ) ;
57
57
let obj_ref = obj. borrow ( ) ;
58
58
assert_eq ! ( obj_ref. method( 6 ) , 42 ) ;
59
- let d = [ ( "obj" , obj) ] . into_py_dict ( py) ;
60
- py. run ( "assert obj.method(3) == 21" , None , Some ( d) ) . unwrap ( ) ;
61
- py. run ( "assert obj.method(multiplier=6) == 42" , None , Some ( d) )
62
- . unwrap ( ) ;
59
+ py_assert ! ( py, obj, "obj.method(3) == 21" ) ;
60
+ py_assert ! ( py, obj, "obj.method(multiplier=6) == 42" ) ;
63
61
}
64
62
65
63
#[ pyclass]
@@ -85,15 +83,10 @@ fn class_method() {
85
83
let py = gil. python ( ) ;
86
84
87
85
let d = [ ( "C" , py. get_type :: < ClassMethod > ( ) ) ] . into_py_dict ( py) ;
88
- let run = |code| {
89
- py. run ( code, None , Some ( d) )
90
- . map_err ( |e| e. print ( py) )
91
- . unwrap ( )
92
- } ;
93
- run ( "assert C.method() == 'ClassMethod.method()!'" ) ;
94
- run ( "assert C().method() == 'ClassMethod.method()!'" ) ;
95
- run ( "assert C.method.__doc__ == 'Test class method.'" ) ;
96
- run ( "assert C().method.__doc__ == 'Test class method.'" ) ;
86
+ py_assert ! ( py, * d, "C.method() == 'ClassMethod.method()!'" ) ;
87
+ py_assert ! ( py, * d, "C().method() == 'ClassMethod.method()!'" ) ;
88
+ py_assert ! ( py, * d, "C.method.__doc__ == 'Test class method.'" ) ;
89
+ py_assert ! ( py, * d, "C().method.__doc__ == 'Test class method.'" ) ;
97
90
}
98
91
99
92
#[ pyclass]
@@ -113,12 +106,11 @@ fn class_method_with_args() {
113
106
let py = gil. python ( ) ;
114
107
115
108
let d = [ ( "C" , py. get_type :: < ClassMethodWithArgs > ( ) ) ] . into_py_dict ( py) ;
116
- py. run (
117
- "assert C.method('abc') == 'ClassMethodWithArgs.method(abc)'" ,
118
- None ,
119
- Some ( d) ,
120
- )
121
- . unwrap ( ) ;
109
+ py_assert ! (
110
+ py,
111
+ * d,
112
+ "C.method('abc') == 'ClassMethodWithArgs.method(abc)'"
113
+ ) ;
122
114
}
123
115
124
116
#[ pyclass]
@@ -146,15 +138,10 @@ fn static_method() {
146
138
assert_eq ! ( StaticMethod :: method( py) , "StaticMethod.method()!" ) ;
147
139
148
140
let d = [ ( "C" , py. get_type :: < StaticMethod > ( ) ) ] . into_py_dict ( py) ;
149
- let run = |code| {
150
- py. run ( code, None , Some ( d) )
151
- . map_err ( |e| e. print ( py) )
152
- . unwrap ( )
153
- } ;
154
- run ( "assert C.method() == 'StaticMethod.method()!'" ) ;
155
- run ( "assert C().method() == 'StaticMethod.method()!'" ) ;
156
- run ( "assert C.method.__doc__ == 'Test static method.'" ) ;
157
- run ( "assert C().method.__doc__ == 'Test static method.'" ) ;
141
+ py_assert ! ( py, * d, "C.method() == 'StaticMethod.method()!'" ) ;
142
+ py_assert ! ( py, * d, "C().method() == 'StaticMethod.method()!'" ) ;
143
+ py_assert ! ( py, * d, "C.method.__doc__ == 'Test static method.'" ) ;
144
+ py_assert ! ( py, * d, "C().method.__doc__ == 'Test static method.'" ) ;
158
145
}
159
146
160
147
#[ pyclass]
@@ -176,8 +163,7 @@ fn static_method_with_args() {
176
163
assert_eq ! ( StaticMethodWithArgs :: method( py, 1234 ) , "0x4d2" ) ;
177
164
178
165
let d = [ ( "C" , py. get_type :: < StaticMethodWithArgs > ( ) ) ] . into_py_dict ( py) ;
179
- py. run ( "assert C.method(1337) == '0x539'" , None , Some ( d) )
180
- . unwrap ( ) ;
166
+ py_assert ! ( py, * d, "C.method(1337) == '0x539'" ) ;
181
167
}
182
168
183
169
#[ pyclass]
@@ -449,15 +435,17 @@ fn meth_doc() {
449
435
let gil = Python :: acquire_gil ( ) ;
450
436
let py = gil. python ( ) ;
451
437
let d = [ ( "C" , py. get_type :: < MethDocs > ( ) ) ] . into_py_dict ( py) ;
452
- let run = |code| {
453
- py. run ( code, None , Some ( d) )
454
- . map_err ( |e| e. print ( py) )
455
- . unwrap ( )
456
- } ;
457
-
458
- run ( "assert C.__doc__ == 'A class with \" documentation\" .'" ) ;
459
- run ( "assert C.method.__doc__ == 'A method with \" documentation\" as well.'" ) ;
460
- run ( "assert C.x.__doc__ == '`int`: a very \" important\" member of \\ 'this\\ ' instance.'" ) ;
438
+ py_assert ! ( py, * d, "C.__doc__ == 'A class with \" documentation\" .'" ) ;
439
+ py_assert ! (
440
+ py,
441
+ * d,
442
+ "C.method.__doc__ == 'A method with \" documentation\" as well.'"
443
+ ) ;
444
+ py_assert ! (
445
+ py,
446
+ * d,
447
+ "C.x.__doc__ == '`int`: a very \" important\" member of \\ 'this\\ ' instance.'"
448
+ ) ;
461
449
}
462
450
463
451
#[ pyclass]
@@ -530,20 +518,31 @@ fn method_with_pyclassarg() {
530
518
let py = gil. python ( ) ;
531
519
let obj1 = PyCell :: new ( py, MethodWithPyClassArg { value : 10 } ) . unwrap ( ) ;
532
520
let obj2 = PyCell :: new ( py, MethodWithPyClassArg { value : 10 } ) . unwrap ( ) ;
533
- let objs = [ ( "obj1" , obj1) , ( "obj2" , obj2) ] . into_py_dict ( py) ;
534
- let run = |code| {
535
- py. run ( code, None , Some ( objs) )
536
- . map_err ( |e| e. print ( py) )
537
- . unwrap ( )
538
- } ;
539
- run ( "obj = obj1.add(obj2); assert obj.value == 20" ) ;
540
- run ( "obj = obj1.add_pyref(obj2); assert obj.value == 20" ) ;
541
- run ( "obj = obj1.optional_add(); assert obj.value == 20" ) ;
542
- run ( "obj = obj1.optional_add(obj2); assert obj.value == 20" ) ;
543
- run ( "obj1.inplace_add(obj2); assert obj.value == 20" ) ;
544
- run ( "obj1.inplace_add_pyref(obj2); assert obj2.value == 30" ) ;
545
- run ( "obj1.optional_inplace_add(); assert obj2.value == 30" ) ;
546
- run ( "obj1.optional_inplace_add(obj2); assert obj2.value == 40" ) ;
521
+ let d = [ ( "obj1" , obj1) , ( "obj2" , obj2) ] . into_py_dict ( py) ;
522
+ py_run ! ( py, * d, "obj = obj1.add(obj2); assert obj.value == 20" ) ;
523
+ py_run ! ( py, * d, "obj = obj1.add_pyref(obj2); assert obj.value == 20" ) ;
524
+ py_run ! ( py, * d, "obj = obj1.optional_add(); assert obj.value == 20" ) ;
525
+ py_run ! (
526
+ py,
527
+ * d,
528
+ "obj = obj1.optional_add(obj2); assert obj.value == 20"
529
+ ) ;
530
+ py_run ! ( py, * d, "obj1.inplace_add(obj2); assert obj.value == 20" ) ;
531
+ py_run ! (
532
+ py,
533
+ * d,
534
+ "obj1.inplace_add_pyref(obj2); assert obj2.value == 30"
535
+ ) ;
536
+ py_run ! (
537
+ py,
538
+ * d,
539
+ "obj1.optional_inplace_add(); assert obj2.value == 30"
540
+ ) ;
541
+ py_run ! (
542
+ py,
543
+ * d,
544
+ "obj1.optional_inplace_add(obj2); assert obj2.value == 40"
545
+ ) ;
547
546
}
548
547
549
548
#[ pyclass]
0 commit comments