File tree Expand file tree Collapse file tree 3 files changed +49
-7
lines changed Expand file tree Collapse file tree 3 files changed +49
-7
lines changed Original file line number Diff line number Diff line change @@ -119,8 +119,6 @@ def fooLacksEnter():
119
119
with foo : pass
120
120
self .assertRaisesRegex (AttributeError , '__enter__' , fooLacksEnter )
121
121
122
- # TODO: RUSTPYTHON
123
- @unittest .expectedFailure
124
122
def testEnterAttributeError2 (self ):
125
123
class LacksEnterAndExit (object ):
126
124
pass
Original file line number Diff line number Diff line change 1
1
import asyncio
2
-
2
+ import unittest
3
3
4
4
class ContextManager :
5
5
async def __aenter__ (self ):
@@ -70,3 +70,44 @@ async def a(s, m):
70
70
"hello3" ,
71
71
"hello4" ,
72
72
]
73
+
74
+
75
+ class TestAsyncWith (unittest .TestCase ):
76
+ def testAenterAttributeError1 (self ):
77
+ class LacksAenter (object ):
78
+ async def __aexit__ (self , * exc ):
79
+ pass
80
+
81
+ async def foo ():
82
+ async with LacksAenter ():
83
+ pass
84
+
85
+ with self .assertRaisesRegex (AttributeError , '__aenter__' ):
86
+ foo ().send (None )
87
+
88
+ def testAenterAttributeError2 (self ):
89
+ class LacksAenterAndAexit (object ):
90
+ pass
91
+
92
+ async def foo ():
93
+ async with LacksAenterAndAexit ():
94
+ pass
95
+
96
+ with self .assertRaisesRegex (AttributeError , '__aenter__' ):
97
+ foo ().send (None )
98
+
99
+ def testAexitAttributeError (self ):
100
+ class LacksAexit (object ):
101
+ async def __aenter__ (self ):
102
+ pass
103
+
104
+ async def foo ():
105
+ async with LacksAexit ():
106
+ pass
107
+
108
+ with self .assertRaisesRegex (AttributeError , '__aexit__' ):
109
+ foo ().send (None )
110
+
111
+
112
+ if __name__ == "__main__" :
113
+ unittest .main ()
Original file line number Diff line number Diff line change @@ -775,20 +775,23 @@ impl ExecutingFrame<'_> {
775
775
}
776
776
bytecode:: Instruction :: SetupWith { end } => {
777
777
let context_manager = self . pop_value ( ) ;
778
+ let enter_res = vm. call_special_method (
779
+ context_manager. clone ( ) ,
780
+ identifier ! ( vm, __enter__) ,
781
+ ( ) ,
782
+ ) ?;
778
783
let exit = context_manager. get_attr ( identifier ! ( vm, __exit__) , vm) ?;
779
784
self . push_value ( exit) ;
780
- // Call enter:
781
- let enter_res =
782
- vm. call_special_method ( context_manager, identifier ! ( vm, __enter__) , ( ) ) ?;
783
785
self . push_block ( BlockType :: Finally { handler : * end } ) ;
784
786
self . push_value ( enter_res) ;
785
787
Ok ( None )
786
788
}
787
789
bytecode:: Instruction :: BeforeAsyncWith => {
788
790
let mgr = self . pop_value ( ) ;
791
+ let aenter_res =
792
+ vm. call_special_method ( mgr. clone ( ) , identifier ! ( vm, __aenter__) , ( ) ) ?;
789
793
let aexit = mgr. get_attr ( identifier ! ( vm, __aexit__) , vm) ?;
790
794
self . push_value ( aexit) ;
791
- let aenter_res = vm. call_special_method ( mgr, identifier ! ( vm, __aenter__) , ( ) ) ?;
792
795
self . push_value ( aenter_res) ;
793
796
794
797
Ok ( None )
You can’t perform that action at this time.
0 commit comments