Skip to content

Commit 55e5e39

Browse files
authored
Fix 2.7 common tests (#2145)
1 parent 87eb761 commit 55e5e39

File tree

9 files changed

+66
-15
lines changed

9 files changed

+66
-15
lines changed

Diff for: scripts/runtox.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ fi
1616
searchstring="$1"
1717

1818
export TOX_PARALLEL_NO_SPINNER=1
19-
exec $TOXPATH -vv -p auto -e "$($TOXPATH -l | grep "$searchstring" | tr $'\n' ',')" -- "${@:2}"
19+
ENV="$($TOXPATH -l | grep "$searchstring" | tr $'\n' ',')"
20+
21+
# Run the common 2.7 suite without the -p flag, otherwise we hit an encoding
22+
# issue in tox.
23+
if [ "$ENV" = py2.7-common, ] || [ "$ENV" = py2.7-gevent, ]; then
24+
exec $TOXPATH -vv -e "$ENV" -- "${@:2}"
25+
else
26+
exec $TOXPATH -vv -p auto -e "$ENV" -- "${@:2}"
27+
fi

Diff for: sentry_sdk/integrations/socket.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
import socket
24
from sentry_sdk import Hub
35
from sentry_sdk._types import MYPY

Diff for: tests/integrations/threading/test_threading.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import gc
2-
2+
import sys
33
from threading import Thread
44

55
import pytest
@@ -121,6 +121,7 @@ def run(self):
121121
assert exception["type"] == "ZeroDivisionError"
122122

123123

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

@@ -141,3 +142,24 @@ def target():
141142
assert Thread.run.__qualname__ == original_run.__qualname__
142143
assert t.run.__name__ == "run"
143144
assert t.run.__qualname__ == original_run.__qualname__
145+
146+
147+
@pytest.mark.skipif(
148+
sys.version_info > (2, 7),
149+
reason="simpler test for py2.7 without py3 only __qualname__",
150+
)
151+
def test_wrapper_attributes_no_qualname(sentry_init):
152+
sentry_init(default_integrations=False, integrations=[ThreadingIntegration()])
153+
154+
def target():
155+
assert t.run.__name__ == "run"
156+
157+
t = Thread(target=target)
158+
t.start()
159+
t.join()
160+
161+
assert Thread.start.__name__ == "start"
162+
assert t.start.__name__ == "start"
163+
164+
assert Thread.run.__name__ == "run"
165+
assert t.run.__name__ == "run"

Diff for: tests/test_exceptiongroup.py

+3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def test_exceptiongroup_simple():
194194
assert frame["context_line"] == " raise ExceptionGroup("
195195

196196

197+
@minimum_python_311
197198
def test_exception_chain_cause():
198199
exception_chain_cause = ValueError("Exception with cause")
199200
exception_chain_cause.__context__ = TypeError("Exception in __context__")
@@ -235,6 +236,7 @@ def test_exception_chain_cause():
235236
assert exception_values == expected_exception_values
236237

237238

239+
@minimum_python_311
238240
def test_exception_chain_context():
239241
exception_chain_context = ValueError("Exception with context")
240242
exception_chain_context.__context__ = TypeError("Exception in __context__")
@@ -273,6 +275,7 @@ def test_exception_chain_context():
273275
assert exception_values == expected_exception_values
274276

275277

278+
@minimum_python_311
276279
def test_simple_exception():
277280
simple_excpetion = ValueError("A simple exception")
278281

Diff for: tests/test_profiler.py

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_profiler_invalid_mode(mode, make_options, teardown_profiling):
8181
setup_profiler(make_options(mode))
8282

8383

84+
@requires_python_version(3, 3)
8485
@pytest.mark.parametrize(
8586
"mode",
8687
[
@@ -116,6 +117,7 @@ def test_profiler_setup_twice(make_options, teardown_profiling):
116117
assert not setup_profiler(make_options())
117118

118119

120+
@requires_python_version(3, 3)
119121
@pytest.mark.parametrize(
120122
"mode",
121123
[
@@ -173,6 +175,7 @@ def test_profiles_sample_rate(
173175
assert len(items["profile"]) == profile_count
174176

175177

178+
@requires_python_version(3, 3)
176179
@pytest.mark.parametrize(
177180
"mode",
178181
[
@@ -234,6 +237,7 @@ def test_profiles_sampler(
234237
assert len(items["profile"]) == profile_count
235238

236239

240+
@requires_python_version(3, 3)
237241
def test_minimum_unique_samples_required(
238242
sentry_init,
239243
capture_envelopes,
@@ -260,6 +264,7 @@ def test_minimum_unique_samples_required(
260264
assert len(items["profile"]) == 0
261265

262266

267+
@requires_python_version(3, 3)
263268
def test_profile_captured(
264269
sentry_init,
265270
capture_envelopes,
@@ -349,6 +354,7 @@ def static_method():
349354
return inspect.currentframe()
350355

351356

357+
@requires_python_version(3, 3)
352358
@pytest.mark.parametrize(
353359
("frame", "frame_name"),
354360
[
@@ -428,6 +434,7 @@ def test_get_frame_name(frame, frame_name):
428434
assert get_frame_name(frame) == frame_name
429435

430436

437+
@requires_python_version(3, 3)
431438
@pytest.mark.parametrize(
432439
("get_frame", "function"),
433440
[
@@ -455,6 +462,7 @@ def test_extract_frame(get_frame, function):
455462
assert isinstance(extracted_frame["lineno"], int)
456463

457464

465+
@requires_python_version(3, 3)
458466
@pytest.mark.parametrize(
459467
("depth", "max_stack_depth", "actual_depth"),
460468
[
@@ -493,6 +501,7 @@ def test_extract_stack_with_max_depth(depth, max_stack_depth, actual_depth):
493501
assert frames[actual_depth]["function"] == "<lambda>", actual_depth
494502

495503

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

516525

526+
@requires_python_version(3, 3)
517527
def test_get_current_thread_id_explicit_thread():
518528
results = Queue(maxsize=1)
519529

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

537547

548+
@requires_python_version(3, 3)
538549
@requires_gevent
539550
def test_get_current_thread_id_gevent_in_thread():
540551
results = Queue(maxsize=1)
@@ -550,6 +561,7 @@ def target():
550561
assert thread.ident == results.get(timeout=1)
551562

552563

564+
@requires_python_version(3, 3)
553565
def test_get_current_thread_id_running_thread():
554566
results = Queue(maxsize=1)
555567

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

564576

577+
@requires_python_version(3, 3)
565578
def test_get_current_thread_id_main_thread():
566579
results = Queue(maxsize=1)
567580

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

628641

642+
@requires_python_version(3, 3)
629643
@pytest.mark.parametrize(
630644
("scheduler_class",),
631645
[
@@ -684,6 +698,7 @@ def ensure_running(self):
684698
]
685699

686700

701+
@requires_python_version(3, 3)
687702
@pytest.mark.parametrize(
688703
("samples", "expected"),
689704
[

Diff for: tests/test_scrubber.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ def test_breadcrumb_extra_scrubbing(sentry_init, capture_events):
105105
"password": "[Filtered]",
106106
}
107107

108-
assert event["_meta"] == {
109-
"extra": {"auth": {"": {"rem": [["!config", "s"]]}}},
110-
"breadcrumbs": {
111-
"values": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
112-
},
108+
assert event["_meta"]["extra"]["auth"] == {"": {"rem": [["!config", "s"]]}}
109+
assert event["_meta"]["breadcrumbs"] == {
110+
"values": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
113111
}
114112

115113

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

125123
(event,) = events
126124
assert event["spans"][0]["data"] == {"password": "[Filtered]", "datafoo": "databar"}
127-
assert event["_meta"] == {
128-
"spans": {"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}}
125+
assert event["_meta"]["spans"] == {
126+
"0": {"data": {"password": {"": {"rem": [["!config", "s"]]}}}}
129127
}
130128

131129

Diff for: tests/test_serializer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def test_bytes_serialization_repr(message_normalizer):
7676
def test_bytearray_serialization_decode(message_normalizer):
7777
binary = bytearray(b"abc123\x80\xf0\x9f\x8d\x95")
7878
result = message_normalizer(binary, should_repr_strings=False)
79-
assert result == "abc123\ufffd\U0001f355"
79+
# fmt: off
80+
assert result == u"abc123\ufffd\U0001f355"
81+
# fmt: on
8082

8183

8284
@pytest.mark.xfail(sys.version_info < (3,), reason="Known safe_repr bugs in Py2.7")

Diff for: tests/utils/test_general.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -587,5 +587,7 @@ def test_strip_string():
587587
assert stripped_text.value.count("a") == 1021 # + '...' is 1024
588588

589589
# If text has unicode characters, it counts bytes and not number of characters.
590-
text_with_unicode_character = "éê"
591-
assert strip_string(text_with_unicode_character, max_length=2).value == "é..."
590+
# fmt: off
591+
text_with_unicode_character = u"éê"
592+
assert strip_string(text_with_unicode_character, max_length=2).value == u"é..."
593+
# fmt: on

Diff for: tox.ini

+2-3
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ setenv =
472472
requests: TESTPATH=tests/integrations/requests
473473
rq: TESTPATH=tests/integrations/rq
474474
sanic: TESTPATH=tests/integrations/sanic
475-
starlette: TESTPATH=tests/integrations/starlette
476-
starlite: TESTPATH=tests/integrations/starlite
475+
starlette: TESTPATH=tests/integrations/starlette
476+
starlite: TESTPATH=tests/integrations/starlite
477477
sqlalchemy: TESTPATH=tests/integrations/sqlalchemy
478478
tornado: TESTPATH=tests/integrations/tornado
479479
trytond: TESTPATH=tests/integrations/trytond
@@ -530,7 +530,6 @@ commands =
530530
; Running `py.test` as an executable suffers from an import error
531531
; when loading tests in scenarios. In particular, django fails to
532532
; load the settings from the test module.
533-
534533
{py2.7}: python -m pytest --ignore-glob='*py3.py' -rsx -s --durations=5 -vvv {env:TESTPATH} {posargs}
535534
{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}
536535

0 commit comments

Comments
 (0)