@@ -2145,6 +2145,56 @@ def test_gecko_collector_with_location_info(self):
21452145 # Verify function name is in string table
21462146 self .assertIn ("handle_request" , string_array )
21472147
2148+ def test_jsonl_collector_with_location_info (self ):
2149+ """Test JsonlCollector handles LocationInfo properly."""
2150+ collapsed_out = tempfile .NamedTemporaryFile (delete = False )
2151+ self .addCleanup (close_and_unlink , collapsed_out )
2152+
2153+ collector = JsonlCollector (sample_interval_usec = 1000 )
2154+ run_id = collector .run_id
2155+
2156+ # Frame with LocationInfo
2157+ frame = MockFrameInfo ("test.py" , 42 , "my_function" )
2158+ frames = [
2159+ MockInterpreterInfo (
2160+ 0 , [MockThreadInfo (1 , [frame ], status = THREAD_STATUS_HAS_GIL )]
2161+ )
2162+ ]
2163+ collector .collect (frames )
2164+
2165+ # Should extract lineno from location
2166+ with captured_stdout (), captured_stderr ():
2167+ collector .export (collapsed_out .name )
2168+
2169+ # Check file contents
2170+ with open (collapsed_out .name , "r" ) as f :
2171+ content = f .read ()
2172+
2173+ lines = content .strip ().split ("\n " )
2174+ self .assertEqual (len (lines ), 5 )
2175+
2176+ def jsonl (obj ):
2177+ return json .dumps (obj , separators = ("," , ":" ))
2178+
2179+ expected = [
2180+ jsonl ({"type" : "meta" , "v" : 1 , "run_id" : run_id ,
2181+ "sample_interval_usec" : 1000 }),
2182+ jsonl ({"type" : "str_def" , "v" : 1 , "run_id" : run_id ,
2183+ "defs" : [{"str_id" : 1 , "value" : "my_function" },
2184+ {"str_id" : 2 , "value" : "test.py" }]}),
2185+ jsonl ({"type" : "frame_def" , "v" : 1 , "run_id" : run_id ,
2186+ "defs" : [{"frame_id" : 1 , "path_str_id" : 2 , "func_str_id" : 1 ,
2187+ "line" : 42 , "end_line" : 42 }]}),
2188+ jsonl ({"type" : "agg" , "v" : 1 , "run_id" : run_id ,
2189+ "kind" : "frame" , "scope" : "final" , "samples_total" : 1 ,
2190+ "entries" : [{"frame_id" : 1 , "self" : 1 , "cumulative" : 1 }]}),
2191+ jsonl ({"type" : "end" , "v" : 1 , "run_id" : run_id ,
2192+ "samples_total" : 1 }),
2193+ ]
2194+
2195+ for exp in expected :
2196+ self .assertIn (exp , lines )
2197+
21482198
21492199class TestOpcodeHandling (unittest .TestCase ):
21502200 """Tests for opcode field handling in collectors."""
0 commit comments