Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
fail_cpp_exception.py34 linesDownload Raw Back to tests
1# -*- coding: utf-8 -*-
2"""
3Helper for testing a C++ exception throw aborts the process.
4
5Takes one argument, the name of the function in :mod:`_test_extension_cpp` to call.
6"""
7import sys
8import greenlet
9from greenlet.tests import _test_extension_cpp
10print('fail_cpp_exception is running')
11
12def run_unhandled_exception_in_greenlet_aborts():
13    def _():
14        _test_extension_cpp.test_exception_switch_and_do_in_g2(
15            _test_extension_cpp.test_exception_throw_nonstd
16        )
17    g1 = greenlet.greenlet(_)
18    g1.switch()
19
20
21func_name = sys.argv[1]
22try:
23    func = getattr(_test_extension_cpp, func_name)
24except AttributeError:
25    if func_name == run_unhandled_exception_in_greenlet_aborts.__name__:
26        func = run_unhandled_exception_in_greenlet_aborts
27    elif func_name == 'run_as_greenlet_target':
28        g = greenlet.greenlet(_test_extension_cpp.test_exception_throw_std)
29        func = g.switch
30    else:
31        raise
32print('raising', func, flush=True)
33func()
34 
codekingpro/portable-devtools · Team Ai