Skip to content

Commit

Permalink
Minor improvements (#2714)
Browse files Browse the repository at this point in the history
- better name for Pyramid event processor
- better test data and output for AWS Lambda tests
- one better asset in threading test
- minor tox cleanup to make gevent more prominent
  • Loading branch information
antonpirker committed Feb 7, 2024
1 parent 2186e22 commit c77a123
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/pyramid.py
Expand Up @@ -215,7 +215,7 @@ def size_of_file(self, postdata):

def _make_event_processor(weak_request, integration):
# type: (Callable[[], Request], PyramidIntegration) -> EventProcessor
def event_processor(event, hint):
def pyramid_event_processor(event, hint):
# type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any]
request = weak_request()
if request is None:
Expand All @@ -231,4 +231,4 @@ def event_processor(event, hint):

return event

return event_processor
return pyramid_event_processor
12 changes: 9 additions & 3 deletions tests/integrations/aws_lambda/client.py
Expand Up @@ -240,7 +240,7 @@ def run_lambda_function(
FunctionName=full_fn_name,
)
print(
"Lambda function in AWS already existing, taking it (and do not create a local one)"
f"Lambda function {full_fn_name} in AWS already existing, taking it (and do not create a local one)"
)
except client.exceptions.ResourceNotFoundException:
function_exists_in_aws = False
Expand All @@ -251,9 +251,14 @@ def run_lambda_function(
dir_already_existing = os.path.isdir(base_dir)

if dir_already_existing:
print("Local Lambda function directory already exists, skipping creation")
print(
f"Local Lambda function directory ({base_dir}) already exists, skipping creation"
)

if not dir_already_existing:
print(
f"Creating Lambda function package ({full_fn_name}) locally in directory {base_dir}"
)
os.mkdir(base_dir)
_create_lambda_package(
base_dir, code, initial_handler, layer, syntax_check, subprocess_kwargs
Expand Down Expand Up @@ -316,9 +321,10 @@ def clean_up():

waiter = client.get_waiter("function_active_v2")
waiter.wait(FunctionName=full_fn_name)
print(f"Created Lambda function in AWS: {full_fn_name}")
except client.exceptions.ResourceConflictException:
print(
"Lambda function already exists, this is fine, we will just invoke it."
f"Lambda function ({full_fn_name}) already existing in AWS, this is fine, we will just invoke it."
)

response = client.invoke(
Expand Down
20 changes: 10 additions & 10 deletions tests/integrations/aws_lambda/test_aws.py
Expand Up @@ -462,23 +462,23 @@ def test_handler(event, context):
[
{
"headers": {
"Host": "x.io",
"X-Forwarded-Proto": "http"
"Host": "x1.io",
"X-Forwarded-Proto": "https"
},
"httpMethod": "GET",
"path": "/somepath",
"path": "/path1",
"queryStringParameters": {
"done": "true"
"done": "false"
},
"dog": "Maisey"
},
{
"headers": {
"Host": "x.io",
"Host": "x2.io",
"X-Forwarded-Proto": "http"
},
"httpMethod": "GET",
"path": "/somepath",
"httpMethod": "POST",
"path": "/path2",
"queryStringParameters": {
"done": "true"
},
Expand Down Expand Up @@ -539,11 +539,11 @@ def test_handler(event, context):

if has_request_data:
request_data = {
"headers": {"Host": "x.io", "X-Forwarded-Proto": "http"},
"headers": {"Host": "x1.io", "X-Forwarded-Proto": "https"},
"method": "GET",
"url": "http://x.io/somepath",
"url": "https://x1.io/path1",
"query_string": {
"done": "true",
"done": "false",
},
}
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/threading/test_threading.py
Expand Up @@ -131,7 +131,8 @@ def run(self):
t.join()
del t

assert not gc.collect()
unreachable_objects = gc.collect()
assert unreachable_objects == 0


@pytest.mark.forked
Expand Down
49 changes: 25 additions & 24 deletions tox.ini
Expand Up @@ -8,6 +8,9 @@ envlist =
# === Common ===
{py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common

# === Gevent ===
{py2.7,py3.6,py3.8,py3.10,py3.11}-gevent

# === Integrations ===
# General format is {pythonversion}-{integrationname}-v{frameworkversion}
# 1 blank line between different integrations
Expand Down Expand Up @@ -112,9 +115,6 @@ envlist =
{py3.10,py3.11,py3.12}-flask-v{3}
{py3.10,py3.11,py3.12}-flask-latest

# Gevent
{py2.7,py3.6,py3.8,py3.10,py3.11}-gevent

# GCP
{py3.7}-gcp

Expand Down Expand Up @@ -235,18 +235,32 @@ deps =
# with the -r flag
-r test-requirements.txt

py3.8-common: hypothesis

linters: -r linter-requirements.txt
linters: werkzeug<2.3.0

# Common
# === Common ===
py3.8-common: hypothesis
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common: pytest-asyncio<=0.21.1
# See https://github.com/pytest-dev/pytest/issues/9621
# and https://github.com/pytest-dev/pytest-forked/issues/67
# for justification of the upper bound on pytest
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common: pytest<7.0.0

# === Gevent ===
# See http://www.gevent.org/install.html#older-versions-of-python
# for justification of the versions pinned below
py3.5-gevent: gevent==20.9.0
# See https://stackoverflow.com/questions/51496550/runtime-warning-greenlet-greenlet-size-changed
# for justification why greenlet is pinned here
py3.5-gevent: greenlet==0.4.17
{py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: gevent>=22.10.0, <22.11.0
# See https://github.com/pytest-dev/pytest/issues/9621
# and https://github.com/pytest-dev/pytest-forked/issues/67
# for justification of the upper bound on pytest
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest<7.0.0

# === Integrations ===

# AIOHTTP
aiohttp-v3.4: aiohttp~=3.4.0
aiohttp-v3.8: aiohttp~=3.8.0
Expand Down Expand Up @@ -360,7 +374,8 @@ deps =

# FastAPI
fastapi: httpx
fastapi: anyio<4.0.0 # thats a dep of httpx
# (this is a dependency of httpx)
fastapi: anyio<4.0.0
fastapi: pytest-asyncio<=0.21.1
fastapi: python-multipart
fastapi: requests
Expand All @@ -379,19 +394,6 @@ deps =
flask-v3: Flask~=3.0
flask-latest: Flask

# Gevent
# See http://www.gevent.org/install.html#older-versions-of-python
# for justification of the versions pinned below
py3.5-gevent: gevent==20.9.0
# See https://stackoverflow.com/questions/51496550/runtime-warning-greenlet-greenlet-size-changed
# for justification why greenlet is pinned here
py3.5-gevent: greenlet==0.4.17
{py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: gevent>=22.10.0, <22.11.0
# See https://github.com/pytest-dev/pytest/issues/9621
# and https://github.com/pytest-dev/pytest-forked/issues/67
# for justification of the upper bound on pytest
{py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest<7.0.0

# GQL
gql-v{3.4}: gql[all]~=3.4.0
gql-latest: gql[all]
Expand Down Expand Up @@ -525,7 +527,8 @@ deps =
starlette: python-multipart
starlette: requests
starlette: httpx
starlette: anyio<4.0.0 # thats a dep of httpx
# (this is a dependency of httpx)
starlette: anyio<4.0.0
starlette: jinja2
starlette-v0.19: starlette~=0.19.0
starlette-v0.20: starlette~=0.20.0
Expand All @@ -540,7 +543,6 @@ deps =
starlite: requests
starlite: cryptography
starlite: pydantic<2.0.0
{py3.8,py3.9}-starlite: typing-extensions==4.5.0 # this is used by pydantic, which is used by starlite. When the problem is fixed in here or pydantic, this can be removed
starlite-v{1.48}: starlite~=1.48.0
starlite-v{1.51}: starlite~=1.51.0

Expand Down Expand Up @@ -576,6 +578,7 @@ deps =
setenv =
PYTHONDONTWRITEBYTECODE=1
common: TESTPATH=tests
gevent: TESTPATH=tests
aiohttp: TESTPATH=tests/integrations/aiohttp
ariadne: TESTPATH=tests/integrations/ariadne
arq: TESTPATH=tests/integrations/arq
Expand All @@ -593,8 +596,6 @@ setenv =
falcon: TESTPATH=tests/integrations/falcon
fastapi: TESTPATH=tests/integrations/fastapi
flask: TESTPATH=tests/integrations/flask
# run all tests with gevent
gevent: TESTPATH=tests
gcp: TESTPATH=tests/integrations/gcp
gql: TESTPATH=tests/integrations/gql
graphene: TESTPATH=tests/integrations/graphene
Expand Down

0 comments on commit c77a123

Please sign in to comment.