@@ -100,128 +100,6 @@ def baz(spam):
100100 self .assertEqual (baz .foo , 'bar' )
101101 self .assertEqual (baz .__doc__ , "Whee!" )
102102
103- class NestedTestCase (unittest .TestCase ):
104-
105- # XXX This needs more work
106-
107- def test_nested (self ):
108- @contextmanager
109- def a ():
110- yield 1
111- @contextmanager
112- def b ():
113- yield 2
114- @contextmanager
115- def c ():
116- yield 3
117- with nested (a (), b (), c ()) as (x , y , z ):
118- self .assertEqual (x , 1 )
119- self .assertEqual (y , 2 )
120- self .assertEqual (z , 3 )
121-
122- def test_nested_cleanup (self ):
123- state = []
124- @contextmanager
125- def a ():
126- state .append (1 )
127- try :
128- yield 2
129- finally :
130- state .append (3 )
131- @contextmanager
132- def b ():
133- state .append (4 )
134- try :
135- yield 5
136- finally :
137- state .append (6 )
138- try :
139- with nested (a (), b ()) as (x , y ):
140- state .append (x )
141- state .append (y )
142- 1 / 0
143- except ZeroDivisionError :
144- self .assertEqual (state , [1 , 4 , 2 , 5 , 6 , 3 ])
145- else :
146- self .fail ("Didn't raise ZeroDivisionError" )
147-
148- def test_nested_right_exception (self ):
149- state = []
150- @contextmanager
151- def a ():
152- yield 1
153- class b (object ):
154- def __enter__ (self ):
155- return 2
156- def __exit__ (self , * exc_info ):
157- try :
158- raise Exception ()
159- except :
160- pass
161- try :
162- with nested (a (), b ()) as (x , y ):
163- 1 / 0
164- except ZeroDivisionError :
165- self .assertEqual ((x , y ), (1 , 2 ))
166- except Exception :
167- self .fail ("Reraised wrong exception" )
168- else :
169- self .fail ("Didn't raise ZeroDivisionError" )
170-
171- def test_nested_b_swallows (self ):
172- @contextmanager
173- def a ():
174- yield
175- @contextmanager
176- def b ():
177- try :
178- yield
179- except :
180- # Swallow the exception
181- pass
182- try :
183- with nested (a (), b ()):
184- 1 / 0
185- except ZeroDivisionError :
186- self .fail ("Didn't swallow ZeroDivisionError" )
187-
188- def test_nested_break (self ):
189- @contextmanager
190- def a ():
191- yield
192- state = 0
193- while True :
194- state += 1
195- with nested (a (), a ()):
196- break
197- state += 10
198- self .assertEqual (state , 1 )
199-
200- def test_nested_continue (self ):
201- @contextmanager
202- def a ():
203- yield
204- state = 0
205- while state < 3 :
206- state += 1
207- with nested (a (), a ()):
208- continue
209- state += 10
210- self .assertEqual (state , 3 )
211-
212- def test_nested_return (self ):
213- @contextmanager
214- def a ():
215- try :
216- yield
217- except :
218- pass
219- def foo ():
220- with nested (a (), a ()):
221- return 1
222- return 10
223- self .assertEqual (foo (), 1 )
224-
225103class ClosingTestCase (unittest .TestCase ):
226104
227105 # XXX This needs more work
0 commit comments