@@ -207,7 +207,9 @@ def test_process_remote_default():
207
207
locals = False ,
208
208
method = StackMethod .AUTO ,
209
209
)
210
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
210
+ assert print_thread_mock .mock_calls == [
211
+ call (thread , NativeReportingMode .OFF ) for thread in threads
212
+ ]
211
213
212
214
213
215
def test_process_remote_no_block ():
@@ -238,13 +240,54 @@ def test_process_remote_no_block():
238
240
locals = False ,
239
241
method = StackMethod .AUTO ,
240
242
)
241
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
243
+ assert print_thread_mock .mock_calls == [
244
+ call (thread , NativeReportingMode .OFF ) for thread in threads
245
+ ]
246
+
247
+
248
+ @pytest .mark .parametrize (
249
+ "argument, mode" ,
250
+ [
251
+ ["--native" , NativeReportingMode .PYTHON ],
252
+ ["--native-all" , NativeReportingMode .ALL ],
253
+ ["--native-last" , NativeReportingMode .LAST ],
254
+ ],
255
+ )
256
+ def test_process_remote_native (argument , mode ):
257
+ # GIVEN
258
+
259
+ argv = ["pystack" , "remote" , "31" , argument ]
260
+
261
+ threads = [Mock (), Mock (), Mock ()]
262
+
263
+ # WHEN
264
+
265
+ with patch (
266
+ "pystack.__main__.get_process_threads"
267
+ ) as get_process_threads_mock , patch (
268
+ "pystack.__main__.print_thread"
269
+ ) as print_thread_mock , patch (
270
+ "sys.argv" , argv
271
+ ):
272
+ get_process_threads_mock .return_value = threads
273
+ main ()
274
+
275
+ # THEN
276
+
277
+ get_process_threads_mock .assert_called_with (
278
+ 31 ,
279
+ stop_process = True ,
280
+ native_mode = mode ,
281
+ locals = False ,
282
+ method = StackMethod .AUTO ,
283
+ )
284
+ assert print_thread_mock .mock_calls == [call (thread , mode ) for thread in threads ]
242
285
243
286
244
- def test_process_remote_native ():
287
+ def test_process_remote_native_last ():
245
288
# GIVEN
246
289
247
- argv = ["pystack" , "remote" , "31" , "--native" ]
290
+ argv = ["pystack" , "remote" , "31" , "--native-last " ]
248
291
249
292
threads = [Mock (), Mock (), Mock ()]
250
293
@@ -265,11 +308,13 @@ def test_process_remote_native():
265
308
get_process_threads_mock .assert_called_with (
266
309
31 ,
267
310
stop_process = True ,
268
- native_mode = NativeReportingMode .PYTHON ,
311
+ native_mode = NativeReportingMode .LAST ,
269
312
locals = False ,
270
313
method = StackMethod .AUTO ,
271
314
)
272
- assert print_thread_mock .mock_calls == [call (thread , True ) for thread in threads ]
315
+ assert print_thread_mock .mock_calls == [
316
+ call (thread , NativeReportingMode .LAST ) for thread in threads
317
+ ]
273
318
274
319
275
320
def test_process_remote_locals ():
@@ -300,7 +345,9 @@ def test_process_remote_locals():
300
345
locals = True ,
301
346
method = StackMethod .AUTO ,
302
347
)
303
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
348
+ assert print_thread_mock .mock_calls == [
349
+ call (thread , NativeReportingMode .OFF ) for thread in threads
350
+ ]
304
351
305
352
306
353
def test_process_remote_native_no_block (capsys ):
@@ -357,7 +404,9 @@ def test_process_remote_exhaustive():
357
404
locals = False ,
358
405
method = StackMethod .ALL ,
359
406
)
360
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
407
+ assert print_thread_mock .mock_calls == [
408
+ call (thread , NativeReportingMode .OFF ) for thread in threads
409
+ ]
361
410
362
411
363
412
@pytest .mark .parametrize (
@@ -432,7 +481,9 @@ def test_process_core_default_without_executable():
432
481
locals = False ,
433
482
method = StackMethod .AUTO ,
434
483
)
435
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
484
+ assert print_thread_mock .mock_calls == [
485
+ call (thread , NativeReportingMode .OFF ) for thread in threads
486
+ ]
436
487
437
488
438
489
def test_process_core_default_gzip_without_executable ():
@@ -486,7 +537,9 @@ def test_process_core_default_gzip_without_executable():
486
537
locals = False ,
487
538
method = StackMethod .AUTO ,
488
539
)
489
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
540
+ assert print_thread_mock .mock_calls == [
541
+ call (thread , NativeReportingMode .OFF ) for thread in threads
542
+ ]
490
543
gzip_open_mock .assert_called_with (Path ("corefile.gz" ), "rb" )
491
544
492
545
@@ -580,14 +633,17 @@ def test_process_core_default_with_executable():
580
633
locals = False ,
581
634
method = StackMethod .AUTO ,
582
635
)
583
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
636
+ assert print_thread_mock .mock_calls == [
637
+ call (thread , NativeReportingMode .OFF ) for thread in threads
638
+ ]
584
639
585
640
586
641
@pytest .mark .parametrize (
587
642
"argument, mode" ,
588
643
[
589
644
["--native" , NativeReportingMode .PYTHON ],
590
645
["--native-all" , NativeReportingMode .ALL ],
646
+ ["--native-last" , NativeReportingMode .LAST ],
591
647
],
592
648
)
593
649
def test_process_core_native (argument , mode ):
@@ -627,7 +683,49 @@ def test_process_core_native(argument, mode):
627
683
locals = False ,
628
684
method = StackMethod .AUTO ,
629
685
)
630
- assert print_thread_mock .mock_calls == [call (thread , True ) for thread in threads ]
686
+ assert print_thread_mock .mock_calls == [call (thread , mode ) for thread in threads ]
687
+
688
+
689
+ def test_process_core_native_last ():
690
+ # GIVEN
691
+
692
+ argv = ["pystack" , "core" , "corefile" , "executable" , "--native-last" ]
693
+
694
+ threads = [Mock (), Mock (), Mock ()]
695
+
696
+ # WHEN
697
+
698
+ with patch (
699
+ "pystack.__main__.get_process_threads_for_core"
700
+ ) as get_process_threads_mock , patch (
701
+ "pystack.__main__.print_thread"
702
+ ) as print_thread_mock , patch (
703
+ "sys.argv" , argv
704
+ ), patch (
705
+ "pathlib.Path.exists" , return_value = True
706
+ ), patch (
707
+ "pystack.__main__.CoreFileAnalyzer"
708
+ ), patch (
709
+ "pystack.__main__.is_elf" , return_value = True
710
+ ), patch (
711
+ "pystack.__main__.is_gzip" , return_value = False
712
+ ):
713
+ get_process_threads_mock .return_value = threads
714
+ main ()
715
+
716
+ # THEN
717
+
718
+ get_process_threads_mock .assert_called_with (
719
+ Path ("corefile" ),
720
+ Path ("executable" ),
721
+ library_search_path = "" ,
722
+ native_mode = NativeReportingMode .LAST ,
723
+ locals = False ,
724
+ method = StackMethod .AUTO ,
725
+ )
726
+ assert print_thread_mock .mock_calls == [
727
+ call (thread , NativeReportingMode .LAST ) for thread in threads
728
+ ]
631
729
632
730
633
731
def test_process_core_locals ():
@@ -667,7 +765,9 @@ def test_process_core_locals():
667
765
locals = True ,
668
766
method = StackMethod .AUTO ,
669
767
)
670
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
768
+ assert print_thread_mock .mock_calls == [
769
+ call (thread , NativeReportingMode .OFF ) for thread in threads
770
+ ]
671
771
672
772
673
773
def test_process_core_with_search_path ():
@@ -714,7 +814,9 @@ def test_process_core_with_search_path():
714
814
locals = False ,
715
815
method = StackMethod .AUTO ,
716
816
)
717
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
817
+ assert print_thread_mock .mock_calls == [
818
+ call (thread , NativeReportingMode .OFF ) for thread in threads
819
+ ]
718
820
719
821
720
822
def test_process_core_with_search_root ():
@@ -762,7 +864,9 @@ def test_process_core_with_search_root():
762
864
locals = False ,
763
865
method = StackMethod .AUTO ,
764
866
)
765
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
867
+ assert print_thread_mock .mock_calls == [
868
+ call (thread , NativeReportingMode .OFF ) for thread in threads
869
+ ]
766
870
767
871
768
872
def test_process_core_with_not_readable_search_root ():
@@ -947,7 +1051,9 @@ def test_process_core_exhaustive():
947
1051
locals = False ,
948
1052
method = StackMethod .ALL ,
949
1053
)
950
- assert print_thread_mock .mock_calls == [call (thread , False ) for thread in threads ]
1054
+ assert print_thread_mock .mock_calls == [
1055
+ call (thread , NativeReportingMode .OFF ) for thread in threads
1056
+ ]
951
1057
952
1058
953
1059
def test_default_colored_output ():
0 commit comments