1515import asyncio
1616import logging
1717import pytest
18- from testing_support .sample_asgi_applications import simple_app_v2_raw , simple_app_v3_raw , simple_app_v2 , simple_app_v3 , AppWithDescriptor
19- from testing_support .fixtures import validate_transaction_metrics , override_application_settings , function_not_called
18+ from testing_support .sample_asgi_applications import (
19+ simple_app_v2_raw ,
20+ simple_app_v3_raw ,
21+ simple_app_v2 ,
22+ simple_app_v3 ,
23+ AppWithDescriptor ,
24+ simple_app_v2_init_exc ,
25+ )
26+ from testing_support .fixtures import (
27+ validate_transaction_metrics ,
28+ override_application_settings ,
29+ function_not_called ,
30+ validate_transaction_errors ,
31+ )
2032from newrelic .api .asgi_application import asgi_application , ASGIApplicationWrapper
2133from testing_support .asgi_testing import AsgiTest
2234
23- #Setup test apps from sample_asgi_applications.py
35+ # Setup test apps from sample_asgi_applications.py
2436simple_app_v2_original = AsgiTest (simple_app_v2_raw )
2537simple_app_v3_original = AsgiTest (simple_app_v3_raw )
2638
2739simple_app_v3_wrapped = AsgiTest (simple_app_v3 )
2840simple_app_v2_wrapped = AsgiTest (simple_app_v2 )
41+ simple_app_v2_init_exc = AsgiTest (simple_app_v2_init_exc )
2942
30- #Test naming scheme logic and ASGIApplicationWrapper for a single callable
43+ # Test naming scheme logic and ASGIApplicationWrapper for a single callable
3144@pytest .mark .parametrize ("naming_scheme" , (None , "component" , "framework" ))
3245def test_single_callable_naming_scheme (naming_scheme ):
3346
@@ -49,7 +62,7 @@ def _test():
4962 _test ()
5063
5164
52- #Test the default naming scheme logic and ASGIApplicationWrapper for a double callable
65+ # Test the default naming scheme logic and ASGIApplicationWrapper for a double callable
5366@validate_transaction_metrics (name = "" , group = "Uri" )
5467def test_double_callable_default_naming_scheme ():
5568 response = simple_app_v2_wrapped .make_request ("GET" , "/" )
@@ -58,24 +71,26 @@ def test_double_callable_default_naming_scheme():
5871 assert response .body == b""
5972
6073
61- #No harm test on single callable asgi app with agent disabled to ensure proper response
74+ # No harm test on single callable asgi app with agent disabled to ensure proper response
6275def test_single_callable_raw ():
6376 response = simple_app_v3_original .make_request ("GET" , "/" )
6477 assert response .status == 200
6578 assert response .headers == {}
6679 assert response .body == b""
6780
6881
69- #No harm test on double callable asgi app with agent disabled to ensure proper response
82+ # No harm test on double callable asgi app with agent disabled to ensure proper response
7083def test_double_callable_raw ():
7184 response = simple_app_v2_original .make_request ("GET" , "/" )
7285 assert response .status == 200
7386 assert response .headers == {}
7487 assert response .body == b""
7588
7689
77- #Test asgi_application decorator with parameters passed in on a single callable
78- @pytest .mark .parametrize ("name, group" , ((None , "group" ), ("name" , "group" ), ("" , "group" )))
90+ # Test asgi_application decorator with parameters passed in on a single callable
91+ @pytest .mark .parametrize (
92+ "name, group" , ((None , "group" ), ("name" , "group" ), ("" , "group" ))
93+ )
7994def test_asgi_application_decorator_single_callable (name , group ):
8095 if name :
8196 expected_name = name
@@ -97,7 +112,7 @@ def _test():
97112 _test ()
98113
99114
100- #Test asgi_application decorator using default values on a double callable
115+ # Test asgi_application decorator using default values on a double callable
101116@validate_transaction_metrics (name = "" , group = "Uri" )
102117def test_asgi_application_decorator_no_params_double_callable ():
103118 asgi_decorator = asgi_application ()
@@ -109,8 +124,10 @@ def test_asgi_application_decorator_no_params_double_callable():
109124 assert response .body == b""
110125
111126
112- #Test for presence of framework info based on whether framework is specified
113- @validate_transaction_metrics (name = "test" , custom_metrics = [("Python/Framework/framework/v1" , 1 )])
127+ # Test for presence of framework info based on whether framework is specified
128+ @validate_transaction_metrics (
129+ name = "test" , custom_metrics = [("Python/Framework/framework/v1" , 1 )]
130+ )
114131def test_framework_metrics ():
115132 asgi_decorator = asgi_application (name = "test" , framework = ("framework" , "v1" ))
116133 decorated_application = asgi_decorator (simple_app_v2_raw )
@@ -157,3 +174,12 @@ async def _test():
157174 loop = asyncio .get_event_loop ()
158175 with pytest .raises (ValueError ):
159176 loop .run_until_complete (_test ())
177+
178+
179+ @pytest .mark .parametrize (
180+ "app" , (simple_app_v3_wrapped , simple_app_v2_wrapped , simple_app_v2_init_exc )
181+ )
182+ @validate_transaction_errors (errors = ["builtins:ValueError" ])
183+ def test_exception_capture (app ):
184+ with pytest .raises (ValueError ):
185+ app .make_request ("GET" , "/exc" )
0 commit comments