15
15
CodeMapping ,
16
16
CodeMappingTreesHelper ,
17
17
FrameFilename ,
18
+ NeedsExtension ,
18
19
UnexpectedPathException ,
19
20
UnsupportedFrameFilename ,
20
21
convert_stacktrace_frame_path_to_source_path ,
26
27
from sentry .testutils .silo import assume_test_silo_mode
27
28
from sentry .utils .event_frames import EventFrame
28
29
29
- sentry_files = [
30
+ SENTRY_FILES = [
30
31
"bin/__init__.py" ,
31
32
"bin/example1.py" ,
32
33
"bin/example2.py" ,
37
38
"src/sentry/wsgi.py" ,
38
39
"src/sentry_plugins/slack/client.py" ,
39
40
]
40
-
41
-
42
41
UNSUPPORTED_FRAME_FILENAMES = [
43
42
"async https://s1.sentry-cdn.com/_static/dist/sentry/entrypoints/app.js" ,
44
43
"/gtm.js" , # Top source; starts with backslash
47
46
"[native code]" ,
48
47
"O$t" ,
49
48
"async https://s1.sentry-cdn.com/_static/dist/sentry/entrypoints/app.js" ,
50
- "/foo/bar/baz" , # no extension
51
- "README" , # no extension
49
+ "README" , # top level file
52
50
"ssl.py" ,
53
51
# XXX: The following will need to be supported
54
52
"initialization.dart" ,
55
53
"backburner.js" ,
56
54
]
55
+ NO_EXTENSION_FRAME_FILENAMES = [
56
+ "/foo/bar/baz" , # no extension
57
+ ]
57
58
58
59
59
60
class TestRepoFiles (TestCase ):
60
61
"""These evaluate which files should be included as part of a repo."""
61
62
62
63
def test_filter_source_code_files (self ) -> None :
63
- source_code_files = filter_source_code_files (sentry_files )
64
+ source_code_files = filter_source_code_files (SENTRY_FILES )
64
65
65
66
assert source_code_files .index ("bin/__init__.py" ) == 0
66
67
assert source_code_files .index ("docs-ui/.eslintrc.js" ) == 3
@@ -109,19 +110,6 @@ def test_buckets_logic() -> None:
109
110
110
111
111
112
class TestFrameFilename :
112
- def test_frame_filename_package_and_more_than_one_level (self ) -> None :
113
- pytest .skip ("This test is outdated because of refactors have been made to code mappings" )
114
- # ff = FrameFilename("getsentry/billing/tax/manager.py")
115
- # assert f"{ff.root}/{ff.dir_path}/{ff.file_name}" == "getsentry/billing/tax/manager.py"
116
- # assert f"{ff.dir_path}/{ff.file_name}" == ff.file_and_dir_path
117
-
118
- def test_frame_filename_package_and_no_levels (self ) -> None :
119
- pytest .skip ("This test is outdated because of refactors have been made to code mappings" )
120
- # ff = FrameFilename("root/bar.py")
121
- # assert f"{ff.root}/{ff.file_name}" == "root/bar.py"
122
- # assert f"{ff.root}/{ff.file_and_dir_path}" == "root/bar.py"
123
- # assert ff.dir_path == ""
124
-
125
113
def test_frame_filename_repr (self ) -> None :
126
114
path = "getsentry/billing/tax/manager.py"
127
115
assert FrameFilename ({"filename" : path }).__repr__ () == f"FrameFilename: { path } "
@@ -131,6 +119,11 @@ def test_raises_unsupported(self) -> None:
131
119
with pytest .raises (UnsupportedFrameFilename ):
132
120
FrameFilename ({"filename" : filepath })
133
121
122
+ def test_raises_no_extension (self ) -> None :
123
+ for filepath in NO_EXTENSION_FRAME_FILENAMES :
124
+ with pytest .raises (NeedsExtension ):
125
+ FrameFilename ({"filename" : filepath })
126
+
134
127
@pytest .mark .parametrize (
135
128
"frame_filename, prefix" ,
136
129
[
@@ -167,7 +160,7 @@ def setUp(self) -> None:
167
160
self .bar_repo = RepoAndBranch ("Test-Organization/bar" , "main" )
168
161
self .code_mapping_helper = CodeMappingTreesHelper (
169
162
{
170
- self .foo_repo .name : RepoTree (self .foo_repo , files = sentry_files ),
163
+ self .foo_repo .name : RepoTree (self .foo_repo , files = SENTRY_FILES ),
171
164
self .bar_repo .name : RepoTree (self .bar_repo , files = ["sentry/web/urls.py" ]),
172
165
}
173
166
)
@@ -303,52 +296,76 @@ def test_list_file_matches_multiple(self) -> None:
303
296
assert matches == expected_matches
304
297
305
298
def test_find_roots_starts_with_period_slash (self ) -> None :
306
- stacktrace_root , source_path = find_roots ("./app/" , "static/app/" )
299
+ stacktrace_root , source_path = find_roots (
300
+ FrameFilename ({"filename" : "./app/foo.tsx" }), "static/app/foo.tsx"
301
+ )
307
302
assert stacktrace_root == "./"
308
303
assert source_path == "static/"
309
304
310
305
def test_find_roots_starts_with_period_slash_no_containing_directory (self ) -> None :
311
- stacktrace_root , source_path = find_roots ("./app/" , "app/" )
306
+ stacktrace_root , source_path = find_roots (
307
+ FrameFilename ({"filename" : "./app/foo.tsx" }), "app/foo.tsx"
308
+ )
312
309
assert stacktrace_root == "./"
313
310
assert source_path == ""
314
311
315
312
def test_find_roots_not_matching (self ) -> None :
316
- stacktrace_root , source_path = find_roots ("sentry/" , "src/sentry/" )
313
+ stacktrace_root , source_path = find_roots (
314
+ FrameFilename ({"filename" : "sentry/foo.py" }), "src/sentry/foo.py"
315
+ )
317
316
assert stacktrace_root == "sentry/"
318
317
assert source_path == "src/sentry/"
319
318
320
319
def test_find_roots_equal (self ) -> None :
321
- stacktrace_root , source_path = find_roots ("source/" , "source/" )
320
+ stacktrace_root , source_path = find_roots (
321
+ FrameFilename ({"filename" : "source/foo.py" }), "source/foo.py"
322
+ )
322
323
assert stacktrace_root == ""
323
324
assert source_path == ""
324
325
325
326
def test_find_roots_starts_with_period_slash_two_levels (self ) -> None :
326
- stacktrace_root , source_path = find_roots ("./app/" , "app/foo/app/" )
327
+ stacktrace_root , source_path = find_roots (
328
+ FrameFilename ({"filename" : "./app/foo.tsx" }), "app/foo/app/foo.tsx"
329
+ )
327
330
assert stacktrace_root == "./"
328
331
assert source_path == "app/foo/"
329
332
330
333
def test_find_roots_starts_with_app (self ) -> None :
331
- stacktrace_root , source_path = find_roots ("app:///utils/" , "utils/" )
334
+ stacktrace_root , source_path = find_roots (
335
+ FrameFilename ({"filename" : "app:///utils/foo.tsx" }), "utils/foo.tsx"
336
+ )
332
337
assert stacktrace_root == "app:///"
333
338
assert source_path == ""
334
339
335
340
def test_find_roots_starts_with_multiple_dot_dot_slash (self ) -> None :
336
- stacktrace_root , source_path = find_roots ("../../../../../../packages/" , "packages/" )
341
+ stacktrace_root , source_path = find_roots (
342
+ FrameFilename ({"filename" : "../../../../../../packages/foo.tsx" }),
343
+ "packages/foo.tsx" ,
344
+ )
337
345
assert stacktrace_root == "../../../../../../"
338
346
assert source_path == ""
339
347
340
348
def test_find_roots_starts_with_app_dot_dot_slash (self ) -> None :
341
- stacktrace_root , source_path = find_roots ("app:///../services/" , "services/" )
349
+ stacktrace_root , source_path = find_roots (
350
+ FrameFilename ({"filename" : "app:///../services/foo.tsx" }),
351
+ "services/foo.tsx" ,
352
+ )
342
353
assert stacktrace_root == "app:///../"
343
354
assert source_path == ""
344
355
345
356
def test_find_roots_bad_stack_path (self ) -> None :
346
357
with pytest .raises (UnexpectedPathException ):
347
- find_roots ("https://yrurlsinyourstackpath.com/" , "sentry/something.py" )
358
+ find_roots (
359
+ FrameFilename ({"filename" : "https://yrurlsinyourstackpath.com/" }),
360
+ "sentry/something.py" ,
361
+ )
348
362
349
363
def test_find_roots_bad_source_path (self ) -> None :
350
364
with pytest .raises (UnexpectedPathException ):
351
- find_roots ("sentry/random.py" , "nothing/something.js" )
365
+ find_roots (
366
+ FrameFilename ({"filename" : "sentry/random.py" }),
367
+ "nothing/something.js" ,
368
+ )
352
369
353
370
354
371
class TestConvertStacktraceFramePathToSourcePath (TestCase ):
0 commit comments