Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2.7 tests #2145

Merged
merged 41 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a015f97
Fix UnicodeEncodeError on 2.7
sentrivana May 26, 2023
561f4ba
attempt
sentrivana May 26, 2023
22ab0c4
fail a test explicitly
sentrivana Jun 5, 2023
c279ef1
Do not encode cached value to determine size (#2143)
sentrivana Jun 5, 2023
b4b1910
Merge branch 'master' into ivana/fix-2.7-tests
sentrivana Jun 5, 2023
5be026c
.
sentrivana Jun 5, 2023
a8c6a3a
more locale fun
sentrivana Jun 5, 2023
c925bef
more locales
sentrivana Jun 5, 2023
6f2bfd8
in tox.ini maybe?
sentrivana Jun 5, 2023
d879898
Merge branch 'master' into ivana/fix-2.7-tests
sentrivana Jun 5, 2023
97d8d9f
maybe in passenv?
sentrivana Jun 5, 2023
4817a0c
another attempt
sentrivana Jun 5, 2023
274ce06
attempt
sentrivana Jun 5, 2023
6b1c0ed
test output
sentrivana Jun 5, 2023
7be749e
?
sentrivana Jun 5, 2023
06a4cbc
?
sentrivana Jun 5, 2023
1be53cc
another attempt
sentrivana Jun 5, 2023
402b848
Remove extra space
sentrivana Jun 5, 2023
63eee7a
.
sentrivana Jun 5, 2023
2708e0b
quotes?
sentrivana Jun 5, 2023
3b62ae6
??
sentrivana Jun 5, 2023
49e6a99
.
sentrivana Jun 5, 2023
b0dba47
.
sentrivana Jun 5, 2023
759f984
.
sentrivana Jun 5, 2023
f4da3cd
.
sentrivana Jun 5, 2023
b4f6eb8
.
sentrivana Jun 5, 2023
534462f
.
sentrivana Jun 5, 2023
9b9f84e
.
sentrivana Jun 5, 2023
fab1c8e
.
sentrivana Jun 5, 2023
b66c73c
Merge branch 'master' into ivana/fix-2.7-tests
sentrivana Jun 6, 2023
d4b055c
remove locale stuff
sentrivana Jun 6, 2023
6036689
.
sentrivana Jun 6, 2023
58b7e74
test fixes
sentrivana Jun 6, 2023
6f2f508
.
sentrivana Jun 6, 2023
1a94f79
skip if old
sentrivana Jun 6, 2023
002d9f6
mark all exceptiongroup tests with >=3.11
sentrivana Jun 6, 2023
2145268
Disable profiler tests for py2.7
sentrivana Jun 6, 2023
ba7288d
unicode stuff
sentrivana Jun 6, 2023
0fe22ec
more tests
sentrivana Jun 6, 2023
044ef9f
unicode...
sentrivana Jun 6, 2023
473b0b0
this actually should work
sentrivana Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"]]}}}}}
Comment on lines +108 to +110
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this because in py2.7 there's an additional 'sys.argv': {'': {'len': 11}}}} in event["_meta"]["extra"], I'm guessing from here. Unsure why this only happens on 2.7 but it doesn't seem to be something that needs to be fixed.

}


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"] == {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ^

"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}
}


Expand Down
1 change: 1 addition & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_bytes_serialization_repr(message_normalizer):
assert result == r"b'abc123\x80\xf0\x9f\x8d\x95'"


@pytest.mark.xfail(sys.version_info < (3,), reason="Known safe_repr bugs in Py2.7")
def test_bytearray_serialization_decode(message_normalizer):
binary = bytearray(b"abc123\x80\xf0\x9f\x8d\x95")
result = message_normalizer(binary, should_repr_strings=False)
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