Skip to content

Commit

Permalink
Fix 2.7 common tests (#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Jun 7, 2023
1 parent 87eb761 commit 55e5e39
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 15 deletions.
10 changes: 9 additions & 1 deletion scripts/runtox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ fi
searchstring="$1"

export TOX_PARALLEL_NO_SPINNER=1
exec $TOXPATH -vv -p auto -e "$($TOXPATH -l | grep "$searchstring" | tr $'\n' ',')" -- "${@:2}"
ENV="$($TOXPATH -l | grep "$searchstring" | tr $'\n' ',')"

# Run the common 2.7 suite without the -p flag, otherwise we hit an encoding
# issue in tox.
if [ "$ENV" = py2.7-common, ] || [ "$ENV" = py2.7-gevent, ]; then
exec $TOXPATH -vv -e "$ENV" -- "${@:2}"
else
exec $TOXPATH -vv -p auto -e "$ENV" -- "${@:2}"
fi
2 changes: 2 additions & 0 deletions sentry_sdk/integrations/socket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import

import socket
from sentry_sdk import Hub
from sentry_sdk._types import MYPY
Expand Down
24 changes: 23 additions & 1 deletion tests/integrations/threading/test_threading.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gc

import sys
from threading import Thread

import pytest
Expand Down Expand Up @@ -121,6 +121,7 @@ def run(self):
assert exception["type"] == "ZeroDivisionError"


@pytest.mark.skipif(sys.version_info < (3, 2), reason="no __qualname__ in older python")
def test_wrapper_attributes(sentry_init):
sentry_init(default_integrations=False, integrations=[ThreadingIntegration()])

Expand All @@ -141,3 +142,24 @@ def target():
assert Thread.run.__qualname__ == original_run.__qualname__
assert t.run.__name__ == "run"
assert t.run.__qualname__ == original_run.__qualname__


@pytest.mark.skipif(
sys.version_info > (2, 7),
reason="simpler test for py2.7 without py3 only __qualname__",
)
def test_wrapper_attributes_no_qualname(sentry_init):
sentry_init(default_integrations=False, integrations=[ThreadingIntegration()])

def target():
assert t.run.__name__ == "run"

t = Thread(target=target)
t.start()
t.join()

assert Thread.start.__name__ == "start"
assert t.start.__name__ == "start"

assert Thread.run.__name__ == "run"
assert t.run.__name__ == "run"
3 changes: 3 additions & 0 deletions tests/test_exceptiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def test_exceptiongroup_simple():
assert frame["context_line"] == " raise ExceptionGroup("


@minimum_python_311
def test_exception_chain_cause():
exception_chain_cause = ValueError("Exception with cause")
exception_chain_cause.__context__ = TypeError("Exception in __context__")
Expand Down Expand Up @@ -235,6 +236,7 @@ def test_exception_chain_cause():
assert exception_values == expected_exception_values


@minimum_python_311
def test_exception_chain_context():
exception_chain_context = ValueError("Exception with context")
exception_chain_context.__context__ = TypeError("Exception in __context__")
Expand Down Expand Up @@ -273,6 +275,7 @@ def test_exception_chain_context():
assert exception_values == expected_exception_values


@minimum_python_311
def test_simple_exception():
simple_excpetion = ValueError("A simple exception")

Expand Down
15 changes: 15 additions & 0 deletions tests/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_profiler_invalid_mode(mode, make_options, teardown_profiling):
setup_profiler(make_options(mode))


@requires_python_version(3, 3)
@pytest.mark.parametrize(
"mode",
[
Expand Down Expand Up @@ -116,6 +117,7 @@ def test_profiler_setup_twice(make_options, teardown_profiling):
assert not setup_profiler(make_options())


@requires_python_version(3, 3)
@pytest.mark.parametrize(
"mode",
[
Expand Down Expand Up @@ -173,6 +175,7 @@ def test_profiles_sample_rate(
assert len(items["profile"]) == profile_count


@requires_python_version(3, 3)
@pytest.mark.parametrize(
"mode",
[
Expand Down Expand Up @@ -234,6 +237,7 @@ def test_profiles_sampler(
assert len(items["profile"]) == profile_count


@requires_python_version(3, 3)
def test_minimum_unique_samples_required(
sentry_init,
capture_envelopes,
Expand All @@ -260,6 +264,7 @@ def test_minimum_unique_samples_required(
assert len(items["profile"]) == 0


@requires_python_version(3, 3)
def test_profile_captured(
sentry_init,
capture_envelopes,
Expand Down Expand Up @@ -349,6 +354,7 @@ def static_method():
return inspect.currentframe()


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("frame", "frame_name"),
[
Expand Down Expand Up @@ -428,6 +434,7 @@ def test_get_frame_name(frame, frame_name):
assert get_frame_name(frame) == frame_name


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("get_frame", "function"),
[
Expand Down Expand Up @@ -455,6 +462,7 @@ def test_extract_frame(get_frame, function):
assert isinstance(extracted_frame["lineno"], int)


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("depth", "max_stack_depth", "actual_depth"),
[
Expand Down Expand Up @@ -493,6 +501,7 @@ def test_extract_stack_with_max_depth(depth, max_stack_depth, actual_depth):
assert frames[actual_depth]["function"] == "<lambda>", actual_depth


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("frame", "depth"),
[(get_frame(depth=1), len(inspect.stack()))],
Expand All @@ -514,6 +523,7 @@ def test_extract_stack_with_cache(frame, depth):
assert frame1 is frame2, i


@requires_python_version(3, 3)
def test_get_current_thread_id_explicit_thread():
results = Queue(maxsize=1)

Expand All @@ -535,6 +545,7 @@ def target2():
assert thread1.ident == results.get(timeout=1)


@requires_python_version(3, 3)
@requires_gevent
def test_get_current_thread_id_gevent_in_thread():
results = Queue(maxsize=1)
Expand All @@ -550,6 +561,7 @@ def target():
assert thread.ident == results.get(timeout=1)


@requires_python_version(3, 3)
def test_get_current_thread_id_running_thread():
results = Queue(maxsize=1)

Expand All @@ -562,6 +574,7 @@ def target():
assert thread.ident == results.get(timeout=1)


@requires_python_version(3, 3)
def test_get_current_thread_id_main_thread():
results = Queue(maxsize=1)

Expand Down Expand Up @@ -626,6 +639,7 @@ def test_thread_scheduler_single_background_thread(scheduler_class):
assert len(get_scheduler_threads(scheduler)) == 0


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("scheduler_class",),
[
Expand Down Expand Up @@ -684,6 +698,7 @@ def ensure_running(self):
]


@requires_python_version(3, 3)
@pytest.mark.parametrize(
("samples", "expected"),
[
Expand Down
12 changes: 5 additions & 7 deletions tests/test_scrubber.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ def test_breadcrumb_extra_scrubbing(sentry_init, capture_events):
"password": "[Filtered]",
}

assert event["_meta"] == {
"extra": {"auth": {"": {"rem": [["!config", "s"]]}}},
"breadcrumbs": {
"values": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
},
assert event["_meta"]["extra"]["auth"] == {"": {"rem": [["!config", "s"]]}}
assert event["_meta"]["breadcrumbs"] == {
"values": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
}


Expand All @@ -124,8 +122,8 @@ def test_span_data_scrubbing(sentry_init, capture_events):

(event,) = events
assert event["spans"][0]["data"] == {"password": "[Filtered]", "datafoo": "databar"}
assert event["_meta"] == {
"spans": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
assert event["_meta"]["spans"] == {
"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}
}


Expand Down
4 changes: 3 additions & 1 deletion tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def test_bytes_serialization_repr(message_normalizer):
def test_bytearray_serialization_decode(message_normalizer):
binary = bytearray(b"abc123\x80\xf0\x9f\x8d\x95")
result = message_normalizer(binary, should_repr_strings=False)
assert result == "abc123\ufffd\U0001f355"
# fmt: off
assert result == u"abc123\ufffd\U0001f355"
# fmt: on


@pytest.mark.xfail(sys.version_info < (3,), reason="Known safe_repr bugs in Py2.7")
Expand Down
6 changes: 4 additions & 2 deletions tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,5 +587,7 @@ def test_strip_string():
assert stripped_text.value.count("a") == 1021 # + '...' is 1024

# If text has unicode characters, it counts bytes and not number of characters.
text_with_unicode_character = "éê"
assert strip_string(text_with_unicode_character, max_length=2).value == "é..."
# fmt: off
text_with_unicode_character = u"éê"
assert strip_string(text_with_unicode_character, max_length=2).value == u"é..."
# fmt: on
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ setenv =
requests: TESTPATH=tests/integrations/requests
rq: TESTPATH=tests/integrations/rq
sanic: TESTPATH=tests/integrations/sanic
starlette: TESTPATH=tests/integrations/starlette
starlite: TESTPATH=tests/integrations/starlite
starlette: TESTPATH=tests/integrations/starlette
starlite: TESTPATH=tests/integrations/starlite
sqlalchemy: TESTPATH=tests/integrations/sqlalchemy
tornado: TESTPATH=tests/integrations/tornado
trytond: TESTPATH=tests/integrations/trytond
Expand Down Expand Up @@ -530,7 +530,6 @@ commands =
; Running `py.test` as an executable suffers from an import error
; when loading tests in scenarios. In particular, django fails to
; load the settings from the test module.

{py2.7}: python -m pytest --ignore-glob='*py3.py' -rsx -s --durations=5 -vvv {env:TESTPATH} {posargs}
{py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}: python -m pytest -rsx -s --durations=5 -vvv {env:TESTPATH} {posargs}

Expand Down

0 comments on commit 55e5e39

Please sign in to comment.