Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sentry-python/tests/utils/test_general.py at dcramer-patch-1 · willcodefortea/sentry-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
willcodefortea
/
sentry-python
Public
forked from
getsentry/sentry-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
dcramer-patch-1
Breadcrumbs
sentry-python
/
tests
/
utils
/
test_general.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
159 lines (127 loc) · 4.3 KB
dcramer-patch-1
Breadcrumbs
sentry-python
/
tests
/
utils
/
test_general.py
Copy path
Top
File metadata and controls
Code
Blame
159 lines (127 loc) · 4.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# coding: utf-8
import
sys
import
os
import
pytest
from
sentry_sdk
.
utils
import
(
BadDsn
,
Dsn
,
safe_repr
,
exceptions_from_error_tuple
,
filename_for_module
,
handle_in_app_impl
,
iter_event_stacktraces
,
)
from
sentry_sdk
.
_compat
import
text_type
try
:
from
hypothesis
import
given
import
hypothesis
.
strategies
as
st
except
ImportError
:
pass
else
:
any_string
=
st
.
one_of
(
st
.
binary
(),
st
.
text
())
@
given
(
x
=
any_string
)
def
test_safe_repr_never_broken_for_strings
(
x
):
r
=
safe_repr
(
x
)
assert
isinstance
(
r
,
text_type
)
assert
u"broken repr"
not
in
r
def
test_safe_repr_regressions
():
assert
u"лошадь"
in
safe_repr
(
u"лошадь"
)
@
pytest
.
mark
.
xfail
(
sys
.
version_info
<
(
3
,),
reason
=
"Fixing this in Python 2 would break other behaviors"
,
)
@
pytest
.
mark
.
parametrize
(
"prefix"
, (
u""
,
u"abcd"
,
u"лошадь"
))
@
pytest
.
mark
.
parametrize
(
"character"
,
u"
\x00
\x07
\x1b
\n
"
)
def
test_safe_repr_non_printable
(
prefix
,
character
):
"""Check that non-printable characters are escaped"""
string
=
prefix
+
character
assert
character
not
in
safe_repr
(
string
)
assert
character
not
in
safe_repr
(
string
.
encode
(
"utf-8"
))
def
test_abs_path
():
"""Check if abs_path is actually an absolute path. This can happen either
with eval/exec like here, or when the file in the frame is relative to
__main__"""
code
=
compile
(
"1/0"
,
"test.py"
,
"exec"
)
try
:
exec
(
code
, {})
except
Exception
:
exceptions
=
exceptions_from_error_tuple
(
sys
.
exc_info
())
(
exception
,)
=
exceptions
frame1
,
frame2
=
frames
=
exception
[
"stacktrace"
][
"frames"
]
for
frame
in
frames
:
assert
os
.
path
.
abspath
(
frame
[
"abs_path"
])
==
frame
[
"abs_path"
]
assert
frame1
[
"filename"
]
==
"tests/utils/test_general.py"
assert
frame2
[
"filename"
]
==
"test.py"
def
test_filename
():
x
=
filename_for_module
assert
x
(
"bogus"
,
"bogus"
)
==
"bogus"
assert
x
(
"os"
,
os
.
__file__
)
==
"os.py"
assert
x
(
"pytest"
,
pytest
.
__file__
)
==
"pytest.py"
import
sentry_sdk
.
utils
assert
x
(
"sentry_sdk.utils"
,
sentry_sdk
.
utils
.
__file__
)
==
"sentry_sdk/utils.py"
@
pytest
.
mark
.
parametrize
(
"given,expected_store,expected_envelope"
,
[
(
"https://foobar@sentry.io/123"
,
"https://sentry.io/api/123/store/"
,
"https://sentry.io/api/123/envelope/"
,
),
(
"https://foobar@sentry.io/bam/123"
,
"https://sentry.io/bam/api/123/store/"
,
"https://sentry.io/bam/api/123/envelope/"
,
),
(
"https://foobar@sentry.io/bam/baz/123"
,
"https://sentry.io/bam/baz/api/123/store/"
,
"https://sentry.io/bam/baz/api/123/envelope/"
,
),
],
)
def
test_parse_dsn_paths
(
given
,
expected_store
,
expected_envelope
):
dsn
=
Dsn
(
given
)
auth
=
dsn
.
to_auth
()
assert
auth
.
store_api_url
==
expected_store
assert
auth
.
get_api_url
(
"store"
)
==
expected_store
assert
auth
.
get_api_url
(
"envelope"
)
==
expected_envelope
@
pytest
.
mark
.
parametrize
(
"dsn"
,
[
"https://foobar@sentry.io"
"https://foobar@sentry.io/"
"https://foobar@sentry.io/asdf"
"https://foobar@sentry.io/asdf/"
"https://foobar@sentry.io/asdf/123/"
],
)
def
test_parse_invalid_dsn
(
dsn
):
with
pytest
.
raises
(
BadDsn
):
dsn
=
Dsn
(
dsn
)
@
pytest
.
mark
.
parametrize
(
"empty"
, [
None
, []])
def
test_in_app
(
empty
):
assert
handle_in_app_impl
(
[{
"module"
:
"foo"
}, {
"module"
:
"bar"
}],
in_app_include
=
[
"foo"
],
in_app_exclude
=
empty
,
)
==
[{
"module"
:
"foo"
,
"in_app"
:
True
}, {
"module"
:
"bar"
}]
assert
handle_in_app_impl
(
[{
"module"
:
"foo"
}, {
"module"
:
"bar"
}],
in_app_include
=
[
"foo"
],
in_app_exclude
=
[
"foo"
],
)
==
[{
"module"
:
"foo"
,
"in_app"
:
True
}, {
"module"
:
"bar"
}]
assert
handle_in_app_impl
(
[{
"module"
:
"foo"
}, {
"module"
:
"bar"
}],
in_app_include
=
empty
,
in_app_exclude
=
[
"foo"
],
)
==
[{
"module"
:
"foo"
,
"in_app"
:
False
}, {
"module"
:
"bar"
,
"in_app"
:
True
}]
def
test_iter_stacktraces
():
assert
set
(
iter_event_stacktraces
(
{
"threads"
: {
"values"
: [{
"stacktrace"
:
1
}]},
"stacktrace"
:
2
,
"exception"
: {
"values"
: [{
"stacktrace"
:
3
}]},
}
)
)
==
{
1
,
2
,
3
}
You can’t perform that action at this time.