Repository navigation
Expand file tree
/
Copy pathpy_test_middleware.py
More file actions
63 lines (49 loc) · 1.49 KB
/
Copy pathpy_test_middleware.py
File metadata and controls
63 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Test module for middleware-style exception handling.
This module tests that erlang.call() works correctly even when wrapped
in try/except blocks that catch and re-raise exceptions, simulating
ASGI/WSGI middleware behavior.
"""
import erlang
def call_with_try_except(key):
"""Wraps erlang.call in try/except that catches and re-raises."""
try:
return erlang.call('get_value', key)
except Exception as e:
# This simulates middleware logging
raise
def call_with_base_exception(key):
"""Wraps erlang.call in try/except that catches BaseException."""
try:
return erlang.call('get_value', key)
except BaseException as e:
# Catches everything including SuspensionRequired
raise
def call_with_nested_try(key):
"""Multiple nested try/except blocks."""
try:
try:
return erlang.call('get_value', key)
except Exception:
raise
except Exception:
raise
def call_with_finally(key):
"""Try/finally pattern common in cleanup code."""
cleanup_ran = False
try:
return erlang.call('get_value', key)
finally:
cleanup_ran = True
def call_through_layers(key):
"""Simulates calling through multiple middleware layers."""
def inner():
try:
return erlang.call('get_value', key)
except Exception:
raise
def outer():
try:
return inner()
except Exception:
raise
return outer()