File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 3434 ensure_integration_enabled ,
3535 to_string ,
3636 exc_info_from_error ,
37+ get_lines_from_file ,
3738)
3839
3940
@@ -1037,3 +1038,31 @@ class NotAnException:
10371038 exc_info_from_error (NotAnException ())
10381039
10391040 assert "Expected Exception object to report, got <class" in str (exc .value )
1041+
1042+
1043+ def test_get_lines_from_file_handle_linecache_errors ():
1044+ expected_result = ([], None , [])
1045+
1046+ class Loader :
1047+ @staticmethod
1048+ def get_source (module ):
1049+ raise IOError ("something went wrong" )
1050+
1051+ result = get_lines_from_file ("filename" , 10 , loader = Loader ())
1052+ assert result == expected_result
1053+
1054+ with mock .patch (
1055+ "sentry_sdk.utils.linecache.getlines" ,
1056+ side_effect = OSError ("something went wrong" ),
1057+ ):
1058+ result = get_lines_from_file ("filename" , 10 )
1059+ assert result == expected_result
1060+
1061+ lines = ["line1" , "line2" , "line3" ]
1062+
1063+ def fake_getlines (filename ):
1064+ return lines
1065+
1066+ with mock .patch ("sentry_sdk.utils.linecache.getlines" , fake_getlines ):
1067+ result = get_lines_from_file ("filename" , 10 )
1068+ assert result == expected_result
You can’t perform that action at this time.
0 commit comments