Skip to content

Commit ec5b85a

Browse files
authored
Remove Python 2 unicode literals, fmt (getsentry#2642)
1 parent 9703685 commit ec5b85a

5 files changed

Lines changed: 14 additions & 34 deletions

File tree

tests/integrations/logging/test_logging.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ def test_custom_log_level_names(sentry_init, capture_events):
128128
}
129129

130130
# set custom log level names
131-
# fmt: off
132-
logging.addLevelName(logging.DEBUG, u"custom level debüg: ")
133-
# fmt: on
131+
logging.addLevelName(logging.DEBUG, "custom level debüg: ")
134132
logging.addLevelName(logging.INFO, "")
135133
logging.addLevelName(logging.WARN, "custom level warn: ")
136134
logging.addLevelName(logging.WARNING, "custom level warning: ")

tests/test_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,7 @@ def test_scope_initialized_before_client(sentry_init, capture_events):
683683
def test_weird_chars(sentry_init, capture_events):
684684
sentry_init()
685685
events = capture_events()
686-
# fmt: off
687-
capture_message(u"föö".encode("latin1"))
688-
# fmt: on
686+
capture_message("föö".encode("latin1"))
689687
(event,) = events
690688
assert json.loads(json.dumps(event)) == event
691689

tests/test_metrics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,9 @@ def test_tag_normalization(sentry_init, capture_envelopes):
755755
ts = time.time()
756756
envelopes = capture_envelopes()
757757

758-
# fmt: off
759758
metrics.distribution("a", 1.0, tags={"foo-bar": "%$foo"}, timestamp=ts)
760759
metrics.distribution("b", 1.0, tags={"foo$$$bar": "blah{}"}, timestamp=ts)
761-
metrics.distribution("c", 1.0, tags={u"foö-bar": u"snöwmän"}, timestamp=ts)
762-
# fmt: on
760+
metrics.distribution("c", 1.0, tags={"foö-bar": "snöwmän"}, timestamp=ts)
763761
Hub.current.flush()
764762

765763
(envelope,) = envelopes
@@ -781,13 +779,11 @@ def test_tag_normalization(sentry_init, capture_envelopes):
781779
"environment": "not-fun-env",
782780
}
783781

784-
# fmt: off
785782
assert m[2][4] == {
786-
"fo_-bar": u"snöwmän",
783+
"fo_-bar": "snöwmän",
787784
"release": "fun-release@1.0.0",
788785
"environment": "not-fun-env",
789786
}
790-
# fmt: on
791787

792788

793789
def test_before_emit_metric(sentry_init, capture_envelopes):

tests/test_serializer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def inner(body, **kwargs):
6161
def test_bytes_serialization_decode(message_normalizer):
6262
binary = b"abc123\x80\xf0\x9f\x8d\x95"
6363
result = message_normalizer(binary, should_repr_strings=False)
64-
# fmt: off
65-
assert result == u"abc123\ufffd\U0001f355"
66-
# fmt: on
64+
assert result == "abc123\ufffd\U0001f355"
6765

6866

6967
@pytest.mark.xfail(sys.version_info < (3,), reason="Known safe_repr bugs in Py2.7")
@@ -76,9 +74,7 @@ def test_bytes_serialization_repr(message_normalizer):
7674
def test_bytearray_serialization_decode(message_normalizer):
7775
binary = bytearray(b"abc123\x80\xf0\x9f\x8d\x95")
7876
result = message_normalizer(binary, should_repr_strings=False)
79-
# fmt: off
80-
assert result == u"abc123\ufffd\U0001f355"
81-
# fmt: on
77+
assert result == "abc123\ufffd\U0001f355"
8278

8379

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

tests/utils/test_general.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,15 @@ def test_safe_repr_never_broken_for_strings(x):
3737

3838

3939
def test_safe_repr_regressions():
40-
# fmt: off
41-
assert u"лошадь" in safe_repr(u"лошадь")
42-
# fmt: on
40+
assert "лошадь" in safe_repr("лошадь")
4341

4442

4543
@pytest.mark.xfail(
4644
sys.version_info < (3,),
4745
reason="Fixing this in Python 2 would break other behaviors",
4846
)
49-
# fmt: off
50-
@pytest.mark.parametrize("prefix", ("", "abcd", u"лошадь"))
51-
@pytest.mark.parametrize("character", u"\x00\x07\x1b\n")
52-
# fmt: on
47+
@pytest.mark.parametrize("prefix", ("", "abcd", "лошадь"))
48+
@pytest.mark.parametrize("character", "\x00\x07\x1b\n")
5349
def test_safe_repr_non_printable(prefix, character):
5450
"""Check that non-printable characters are escaped"""
5551
string = prefix + character
@@ -517,27 +513,25 @@ def test_iter_stacktraces():
517513
) == {1, 2, 3}
518514

519515

520-
# fmt: off
521516
@pytest.mark.parametrize(
522517
("original", "base64_encoded"),
523518
[
524519
# ascii only
525520
("Dogs are great!", "RG9ncyBhcmUgZ3JlYXQh"),
526521
# emoji
527-
(u"🐶", "8J+Qtg=="),
522+
("🐶", "8J+Qtg=="),
528523
# non-ascii
529524
(
530-
u"Καλό κορίτσι, Μάιζεϊ!",
525+
"Καλό κορίτσι, Μάιζεϊ!",
531526
"zprOsc67z4wgzrrOv8+Bzq/PhM+DzrksIM6czqzOuc62zrXPiiE=",
532527
),
533528
# mix of ascii and non-ascii
534529
(
535-
u"Of margir hundar! Ég geri ráð fyrir að ég þurfi stærra rúm.",
530+
"Of margir hundar! Ég geri ráð fyrir að ég þurfi stærra rúm.",
536531
"T2YgbWFyZ2lyIGh1bmRhciEgw4lnIGdlcmkgcsOhw7AgZnlyaXIgYcOwIMOpZyDDvnVyZmkgc3TDpnJyYSByw7ptLg==",
537532
),
538533
],
539534
)
540-
# fmt: on
541535
def test_successful_base64_conversion(original, base64_encoded):
542536
# all unicode characters should be handled correctly
543537
assert to_base64(original) == base64_encoded
@@ -587,7 +581,5 @@ def test_strip_string():
587581
assert stripped_text.value.count("a") == 1021 # + '...' is 1024
588582

589583
# If text has unicode characters, it counts bytes and not number of characters.
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
584+
text_with_unicode_character = "éê"
585+
assert strip_string(text_with_unicode_character, max_length=2).value == "é..."

0 commit comments

Comments
 (0)