3838# SOFTWARE.
3939
4040import unittest
41- import test .support
41+ import subprocess
42+ import sys
43+ import textwrap
4244
4345
4446class ExceptStarPrintTest (unittest .TestCase ):
45- def test_01 (self ):
46- with test .support .captured_output ("stderr" ) as stderr :
47- eg = ExceptionGroup ("eg" , [ValueError (1 ), TypeError (2 )])
48- self .assertEqual ()
49- assert stderr .getvalue () == "xffgh"
47+ def test_01_eg_simple (self ):
48+ script = textwrap .dedent ("""
49+ raise ExceptionGroup("eg", [
50+ ValueError(1),
51+ TypeError(2)
52+ ])
53+ """ )
54+ p = subprocess .run ([sys .executable , "-c" , script ], capture_output = True )
55+ expected = [b' + Exception Group Traceback (most recent call last):' ,
56+ b' | File "<string>", line 2, in <module>' ,
57+ b' | ExceptionGroup: eg (2 sub-exceptions)' ,
58+ b' +-+---------------- 1 ----------------' ,
59+ b' | ValueError: 1' ,
60+ b' +---------------- 2 ----------------' ,
61+ b' | TypeError: 2' ,
62+ b' +------------------------------------' ]
63+ self .assertEqual (p .stderr .splitlines (), expected )
64+
65+ def test_02_eg_nested (self ):
66+ script = textwrap .dedent ("""
67+ raise ExceptionGroup("EG", [
68+ TypeError("1"),
69+ ExceptionGroup("2", [
70+ IndexError("2.1"),
71+ ValueError("2.2"),
72+ ExceptionGroup("2.3", [
73+ IndexError("2.3.1"),
74+ ExceptionGroup("2.3.2", [
75+ TypeError("2.3.2.1"),
76+ IndexError("2.3.2.2"),
77+ ExceptionGroup("2.3.2.3", [
78+ ImportError("2.3.2.3.1"),
79+ ValueError("2.3.2.3.2")
80+ ])
81+ ]),
82+ IndexError("2.3.3"),
83+ IndexError("2.3.4"),
84+ IndexError("2.3.5"),
85+ IndexError("2.3.6"),
86+ ]),
87+ ExceptionGroup("2.4", [
88+ IndexError("2.4.1"),
89+ ExceptionGroup("2.4.2", [
90+ TypeError("2.4.2.1"),
91+ IndexError("2.4.2.2"),
92+ ExceptionGroup("2.4.3", [
93+ ImportError("2.4.3.1"),
94+ ValueError("2.4.3.2")
95+ ])
96+ ])
97+ ])
98+ ]),
99+ ValueError("3"),
100+ ValueError("4"),
101+ ValueError("5"),
102+ ])
103+ """ )
104+ p = subprocess .run ([sys .executable , "-c" , script ], capture_output = True )
105+ expected = [b' + Exception Group Traceback (most recent call last):' ,
106+ b' | File "<string>", line 2, in <module>' ,
107+ b' | ExceptionGroup: EG (5 sub-exceptions)' ,
108+ b' +-+---------------- 1 ----------------' ,
109+ b' | TypeError: 1' ,
110+ b' +---------------- 2 ----------------' ,
111+ b' | ExceptionGroup: 2 (4 sub-exceptions)' ,
112+ b' +-+---------------- 1 ----------------' ,
113+ b' | IndexError: 2.1' ,
114+ b' +---------------- 2 ----------------' ,
115+ b' | ValueError: 2.2' ,
116+ b' +---------------- 3 ----------------' ,
117+ b' | ExceptionGroup: 2.3 (6 sub-exceptions)' ,
118+ b' +-+---------------- 1 ----------------' ,
119+ b' | IndexError: 2.3.1' ,
120+ b' +---------------- 2 ----------------' ,
121+ b' | ExceptionGroup: 2.3.2 (3 sub-exceptions)' ,
122+ b' +-+---------------- 1 ----------------' ,
123+ b' | TypeError: 2.3.2.1' ,
124+ b' +---------------- 2 ----------------' ,
125+ b' | IndexError: 2.3.2.2' ,
126+ b' +---------------- 3 ----------------' ,
127+ b' | ExceptionGroup: 2.3.2.3 (2 sub-exceptions)' ,
128+ b' +-+---------------- 1 ----------------' ,
129+ b' | ImportError: 2.3.2.3.1' ,
130+ b' +---------------- 2 ----------------' ,
131+ b' | ValueError: 2.3.2.3.2' ,
132+ b' +------------------------------------' ,
133+ b' +---------------- 3 ----------------' ,
134+ b' | IndexError: 2.3.3' ,
135+ b' +---------------- 4 ----------------' ,
136+ b' | IndexError: 2.3.4' ,
137+ b' +---------------- 5 ----------------' ,
138+ b' | IndexError: 2.3.5' ,
139+ b' +---------------- 6 ----------------' ,
140+ b' | IndexError: 2.3.6' ,
141+ b' +------------------------------------' ,
142+ b' +---------------- 4 ----------------' ,
143+ b' | ExceptionGroup: 2.4 (2 sub-exceptions)' ,
144+ b' +-+---------------- 1 ----------------' ,
145+ b' | IndexError: 2.4.1' ,
146+ b' +---------------- 2 ----------------' ,
147+ b' | ExceptionGroup: 2.4.2 (3 sub-exceptions)' ,
148+ b' +-+---------------- 1 ----------------' ,
149+ b' | TypeError: 2.4.2.1' ,
150+ b' +---------------- 2 ----------------' ,
151+ b' | IndexError: 2.4.2.2' ,
152+ b' +---------------- 3 ----------------' ,
153+ b' | ExceptionGroup: 2.4.3 (2 sub-exceptions)' ,
154+ b' +-+---------------- 1 ----------------' ,
155+ b' | ImportError: 2.4.3.1' ,
156+ b' +---------------- 2 ----------------' ,
157+ b' | ValueError: 2.4.3.2' ,
158+ b' +------------------------------------' ,
159+ b' +---------------- 3 ----------------' ,
160+ b' | ValueError: 3' ,
161+ b' +---------------- 4 ----------------' ,
162+ b' | ValueError: 4' ,
163+ b' +---------------- 5 ----------------' ,
164+ b' | ValueError: 5' ,
165+ b' +------------------------------------' ]
166+ self .maxDiff = None
167+ self .assertEqual (p .stderr .splitlines (), expected )
168+
169+ def test_03_eg_nested_truncated (self ):
170+ script = textwrap .dedent ("""
171+ raise ExceptionGroup("EG", [
172+ TypeError("1"),
173+ ExceptionGroup("2", [
174+ IndexError("2.1"),
175+ ValueError("2.2"),
176+ ExceptionGroup("2.3", [
177+ IndexError("2.3.1"),
178+ ExceptionGroup("2.3.2", [
179+ TypeError("2.3.2.1"),
180+ IndexError("2.3.2.2"),
181+ ExceptionGroup("2.3.2.3", [
182+ ExceptionGroup("2.3.2.3.1", [
183+ ExceptionGroup("2.3.2.3.1.1", [
184+ ExceptionGroup("2.3.2.3.1.1.1", [
185+ ExceptionGroup("2.3.2.3.1.1.1.1", [
186+ ExceptionGroup("2.3.2.3.1.1.1.1.1", [
187+ ExceptionGroup("2.3.2.3.1.1.1.1.1.1", [
188+ ExceptionGroup("2.3.2.3.1.1.1.1.1.1.1", [
189+ ExceptionGroup("2.3.2.3.1.1.1.1.1.1.1.1", [
190+ ExceptionGroup("2.3.2.3.1.1.1.1.1.1.1.1.1", [
191+ IndexError(1)
192+ ]),
193+ ]),
194+ ]),
195+ ]),
196+ ImportError("2.3.2.3.1.1.1.1.1.2"),
197+ IndexError("2.3.2.3.1.1.1.1.1.3"),
198+ ]),
199+ ]),
200+ ]),
201+ ]),
202+ ]),
203+ ImportError("2.3.2.3.1"),
204+ ValueError("2.3.2.3.2")
205+ ])
206+ ]),
207+ IndexError("2.3.3"),
208+ IndexError("2.3.4"),
209+ IndexError("2.3.5"),
210+ IndexError("2.3.6"),
211+ IndexError("2.3.7"),
212+ IndexError("2.3.8"),
213+ IndexError("2.3.9"),
214+ IndexError("2.3.10"),
215+ IndexError("2.3.11"),
216+ IndexError("2.3.12"),
217+ IndexError("2.3.13"),
218+ IndexError("2.3.14"),
219+ IndexError("2.3.15"),
220+ IndexError("2.3.16"),
221+ IndexError("2.3.17"),
222+ IndexError("2.3.18"),
223+ ]),
224+ ExceptionGroup("2.4", [
225+ IndexError("2.4.1"),
226+ ExceptionGroup("2.4.2", [
227+ TypeError("2.4.2.1"),
228+ IndexError("2.4.2.2"),
229+ ExceptionGroup("2.4.3", [
230+ ImportError("2.4.3.1"),
231+ ValueError("2.4.3.2")
232+ ])
233+ ])
234+ ])
235+ ]),
236+ ValueError("3"),
237+ ValueError("4"),
238+ ValueError("5"),
239+ ValueError("6"),
240+ ValueError("7"),
241+ ValueError("8"),
242+ ValueError("9"),
243+ ValueError("10"),
244+ ValueError("11"),
245+ ValueError("12"),
246+ ValueError("13"),
247+ ValueError("14"),
248+ ValueError("15"),
249+ ValueError("16"),
250+ ValueError("17"),
251+ ValueError("18"),
252+ ValueError("19"),
253+ ValueError("20"),
254+ ValueError("21"),
255+ ValueError("22"),
256+ ValueError("23"),
257+ ])
258+ """ )
259+ p = subprocess .run ([sys .executable , "-c" , script ], capture_output = True )
260+ expected = [b' + Exception Group Traceback (most recent call last):' ,
261+ b' | File "<string>", line 2, in <module>' ,
262+ b' | ExceptionGroup: EG (23 sub-exceptions)' ,
263+ b' +-+---------------- 1 ----------------' ,
264+ b' | TypeError: 1' ,
265+ b' +---------------- 2 ----------------' ,
266+ b' | ExceptionGroup: 2 (4 sub-exceptions)' ,
267+ b' +-+---------------- 1 ----------------' ,
268+ b' | IndexError: 2.1' ,
269+ b' +---------------- 2 ----------------' ,
270+ b' | ValueError: 2.2' ,
271+ b' +---------------- 3 ----------------' ,
272+ b' | ExceptionGroup: 2.3 (18 sub-exceptions)' ,
273+ b' +-+---------------- 1 ----------------' ,
274+ b' | IndexError: 2.3.1' ,
275+ b' +---------------- 2 ----------------' ,
276+ b' | ExceptionGroup: 2.3.2 (3 sub-exceptions)' ,
277+ b' +-+---------------- 1 ----------------' ,
278+ b' | TypeError: 2.3.2.1' ,
279+ b' +---------------- 2 ----------------' ,
280+ b' | IndexError: 2.3.2.2' ,
281+ b' +---------------- 3 ----------------' ,
282+ b' | ExceptionGroup: 2.3.2.3 (3 sub-exceptions)' ,
283+ b' +-+---------------- 1 ----------------' ,
284+ b' | ExceptionGroup: 2.3.2.3.1 (1 sub-exception)' ,
285+ b' +-+---------------- 1 ----------------' ,
286+ b' | ExceptionGroup: 2.3.2.3.1.1 (1 sub-exception)' ,
287+ b' +-+---------------- 1 ----------------' ,
288+ b' | ExceptionGroup: 2.3.2.3.1.1.1 (1 sub-exception)' ,
289+ b' +-+---------------- 1 ----------------' ,
290+ b' | ExceptionGroup: 2.3.2.3.1.1.1.1 (1 sub-exception)' ,
291+ b' +-+---------------- 1 ----------------' ,
292+ b' | ExceptionGroup: 2.3.2.3.1.1.1.1.1 (3 sub-exceptions)' ,
293+ b' +-+---------------- 1 ----------------' ,
294+ b' | ... (max_group_depth is 10)' ,
295+ b' +---------------- 2 ----------------' ,
296+ b' | ImportError: 2.3.2.3.1.1.1.1.1.2' ,
297+ b' +---------------- 3 ----------------' ,
298+ b' | IndexError: 2.3.2.3.1.1.1.1.1.3' ,
299+ b' +------------------------------------' ,
300+ b' +---------------- 2 ----------------' ,
301+ b' | ImportError: 2.3.2.3.1' ,
302+ b' +---------------- 3 ----------------' ,
303+ b' | ValueError: 2.3.2.3.2' ,
304+ b' +------------------------------------' ,
305+ b' +---------------- 3 ----------------' ,
306+ b' | IndexError: 2.3.3' ,
307+ b' +---------------- 4 ----------------' ,
308+ b' | IndexError: 2.3.4' ,
309+ b' +---------------- 5 ----------------' ,
310+ b' | IndexError: 2.3.5' ,
311+ b' +---------------- 6 ----------------' ,
312+ b' | IndexError: 2.3.6' ,
313+ b' +---------------- 7 ----------------' ,
314+ b' | IndexError: 2.3.7' ,
315+ b' +---------------- 8 ----------------' ,
316+ b' | IndexError: 2.3.8' ,
317+ b' +---------------- 9 ----------------' ,
318+ b' | IndexError: 2.3.9' ,
319+ b' +---------------- 10 ----------------' ,
320+ b' | IndexError: 2.3.10' ,
321+ b' +---------------- 11 ----------------' ,
322+ b' | IndexError: 2.3.11' ,
323+ b' +---------------- 12 ----------------' ,
324+ b' | IndexError: 2.3.12' ,
325+ b' +---------------- 13 ----------------' ,
326+ b' | IndexError: 2.3.13' ,
327+ b' +---------------- 14 ----------------' ,
328+ b' | IndexError: 2.3.14' ,
329+ b' +---------------- 15 ----------------' ,
330+ b' | IndexError: 2.3.15' ,
331+ b' +---------------- ... ----------------' ,
332+ b' | and 3 more exceptions' ,
333+ b' +------------------------------------' ,
334+ b' +---------------- 4 ----------------' ,
335+ b' | ExceptionGroup: 2.4 (2 sub-exceptions)' ,
336+ b' +-+---------------- 1 ----------------' ,
337+ b' | IndexError: 2.4.1' ,
338+ b' +---------------- 2 ----------------' ,
339+ b' | ExceptionGroup: 2.4.2 (3 sub-exceptions)' ,
340+ b' +-+---------------- 1 ----------------' ,
341+ b' | TypeError: 2.4.2.1' ,
342+ b' +---------------- 2 ----------------' ,
343+ b' | IndexError: 2.4.2.2' ,
344+ b' +---------------- 3 ----------------' ,
345+ b' | ExceptionGroup: 2.4.3 (2 sub-exceptions)' ,
346+ b' +-+---------------- 1 ----------------' ,
347+ b' | ImportError: 2.4.3.1' ,
348+ b' +---------------- 2 ----------------' ,
349+ b' | ValueError: 2.4.3.2' ,
350+ b' +------------------------------------' ,
351+ b' +---------------- 3 ----------------' ,
352+ b' | ValueError: 3' ,
353+ b' +---------------- 4 ----------------' ,
354+ b' | ValueError: 4' ,
355+ b' +---------------- 5 ----------------' ,
356+ b' | ValueError: 5' ,
357+ b' +---------------- 6 ----------------' ,
358+ b' | ValueError: 6' ,
359+ b' +---------------- 7 ----------------' ,
360+ b' | ValueError: 7' ,
361+ b' +---------------- 8 ----------------' ,
362+ b' | ValueError: 8' ,
363+ b' +---------------- 9 ----------------' ,
364+ b' | ValueError: 9' ,
365+ b' +---------------- 10 ----------------' ,
366+ b' | ValueError: 10' ,
367+ b' +---------------- 11 ----------------' ,
368+ b' | ValueError: 11' ,
369+ b' +---------------- 12 ----------------' ,
370+ b' | ValueError: 12' ,
371+ b' +---------------- 13 ----------------' ,
372+ b' | ValueError: 13' ,
373+ b' +---------------- 14 ----------------' ,
374+ b' | ValueError: 14' ,
375+ b' +---------------- 15 ----------------' ,
376+ b' | ValueError: 15' ,
377+ b' +---------------- ... ----------------' ,
378+ b' | and 8 more exceptions' ,
379+ b' +------------------------------------' ]
380+ self .maxDiff = None
381+ self .assertEqual (p .stderr .splitlines (), expected )
0 commit comments