Skip to content

Commit da9702f

Browse files
committed
Update the tests
1 parent 995b203 commit da9702f

File tree

2 files changed

+231
-40
lines changed

2 files changed

+231
-40
lines changed

tests/unit/test_main.py

Lines changed: 122 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def test_process_remote_default():
207207
locals=False,
208208
method=StackMethod.AUTO,
209209
)
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+
]
211213

212214

213215
def test_process_remote_no_block():
@@ -238,13 +240,54 @@ def test_process_remote_no_block():
238240
locals=False,
239241
method=StackMethod.AUTO,
240242
)
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]
242285

243286

244-
def test_process_remote_native():
287+
def test_process_remote_native_last():
245288
# GIVEN
246289

247-
argv = ["pystack", "remote", "31", "--native"]
290+
argv = ["pystack", "remote", "31", "--native-last"]
248291

249292
threads = [Mock(), Mock(), Mock()]
250293

@@ -265,11 +308,13 @@ def test_process_remote_native():
265308
get_process_threads_mock.assert_called_with(
266309
31,
267310
stop_process=True,
268-
native_mode=NativeReportingMode.PYTHON,
311+
native_mode=NativeReportingMode.LAST,
269312
locals=False,
270313
method=StackMethod.AUTO,
271314
)
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+
]
273318

274319

275320
def test_process_remote_locals():
@@ -300,7 +345,9 @@ def test_process_remote_locals():
300345
locals=True,
301346
method=StackMethod.AUTO,
302347
)
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+
]
304351

305352

306353
def test_process_remote_native_no_block(capsys):
@@ -357,7 +404,9 @@ def test_process_remote_exhaustive():
357404
locals=False,
358405
method=StackMethod.ALL,
359406
)
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+
]
361410

362411

363412
@pytest.mark.parametrize(
@@ -432,7 +481,9 @@ def test_process_core_default_without_executable():
432481
locals=False,
433482
method=StackMethod.AUTO,
434483
)
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+
]
436487

437488

438489
def test_process_core_default_gzip_without_executable():
@@ -486,7 +537,9 @@ def test_process_core_default_gzip_without_executable():
486537
locals=False,
487538
method=StackMethod.AUTO,
488539
)
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+
]
490543
gzip_open_mock.assert_called_with(Path("corefile.gz"), "rb")
491544

492545

@@ -580,14 +633,17 @@ def test_process_core_default_with_executable():
580633
locals=False,
581634
method=StackMethod.AUTO,
582635
)
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+
]
584639

585640

586641
@pytest.mark.parametrize(
587642
"argument, mode",
588643
[
589644
["--native", NativeReportingMode.PYTHON],
590645
["--native-all", NativeReportingMode.ALL],
646+
["--native-last", NativeReportingMode.LAST],
591647
],
592648
)
593649
def test_process_core_native(argument, mode):
@@ -627,7 +683,49 @@ def test_process_core_native(argument, mode):
627683
locals=False,
628684
method=StackMethod.AUTO,
629685
)
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+
]
631729

632730

633731
def test_process_core_locals():
@@ -667,7 +765,9 @@ def test_process_core_locals():
667765
locals=True,
668766
method=StackMethod.AUTO,
669767
)
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+
]
671771

672772

673773
def test_process_core_with_search_path():
@@ -714,7 +814,9 @@ def test_process_core_with_search_path():
714814
locals=False,
715815
method=StackMethod.AUTO,
716816
)
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+
]
718820

719821

720822
def test_process_core_with_search_root():
@@ -762,7 +864,9 @@ def test_process_core_with_search_root():
762864
locals=False,
763865
method=StackMethod.AUTO,
764866
)
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+
]
766870

767871

768872
def test_process_core_with_not_readable_search_root():
@@ -947,7 +1051,9 @@ def test_process_core_exhaustive():
9471051
locals=False,
9481052
method=StackMethod.ALL,
9491053
)
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+
]
9511057

9521058

9531059
def test_default_colored_output():

0 commit comments

Comments
 (0)