@@ -338,6 +338,52 @@ def test_kernprof_bad_temp_script(stdin):
338338 assert not os .path .exists (os .path .dirname (tmp_script ))
339339
340340
341+ @pytest .mark .parametrize ('debug' , [True , False ])
342+ def test_bad_prof_mod_target (debug ):
343+ """
344+ Test the handling of bad paths in `--prof-mod` targets.
345+ """
346+ with contextlib .ExitStack () as stack :
347+ enter = stack .enter_context
348+ enter (ub .ChDir (enter (tempfile .TemporaryDirectory ())))
349+ proc = ub .cmd (['kernprof' , '-l' , '-p' , './nonexistent.py' ,
350+ '-c' , 'print("Output: foo")' ],
351+ env = {** os .environ , 'LINE_PROFILER_DEBUG' : str (debug )})
352+ print (proc .stdout )
353+ print (proc .stderr , file = sys .stderr )
354+ proc .check_returncode ()
355+ assert os .listdir () # Profile results
356+ assert 'Output: foo' in proc .stdout
357+ assert re .search (r"1 .* target .*: \['\./nonexistent\.py'\]" , proc .stderr )
358+
359+
360+ @pytest .mark .parametrize ('builtin' , [True , False ])
361+ @pytest .mark .parametrize ('module' , [True , False ])
362+ def test_call_with_diagnostics (module , builtin ):
363+ """
364+ Test the output of call signatures in debug messages.
365+ """
366+ to_run = ['-m' , 'calendar' ] if module else ['-c' , 'print("Output: foo")' ]
367+ with contextlib .ExitStack () as stack :
368+ enter = stack .enter_context
369+ enter (ub .ChDir (enter (tempfile .TemporaryDirectory ())))
370+ cmd = ['kernprof' ]
371+ if builtin :
372+ cmd += ['-b' ]
373+ proc = ub .cmd (cmd + to_run ,
374+ env = {** os .environ , 'LINE_PROFILER_DEBUG' : 'true' })
375+ print (proc .stdout )
376+ print (proc .stderr , file = sys .stderr )
377+ proc .check_returncode ()
378+ assert os .listdir () # Profile results
379+ has_runctx_call = re .search (
380+ r'Calling: .+\.runctx\(.+\)' , proc .stdout , flags = re .DOTALL )
381+ has_execfile_call = re .search (
382+ r'execfile\(.+\)' , proc .stdout , flags = re .DOTALL )
383+ assert bool (has_runctx_call ) == (not builtin )
384+ assert bool (has_execfile_call ) == (not module )
385+
386+
341387class TestKernprof (unittest .TestCase ):
342388
343389 def test_enable_disable (self ):
0 commit comments