Skip to content

Commit fd9ddb3

Browse files
Tests: Added new commands to memray attach
Signed-off-by: Ivona Stojanovic <[email protected]>
1 parent 9bfaf86 commit fd9ddb3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/unit/test_attach.py

+64
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,68 @@ def test_memray_attach_aggregated_without_output_file(
1818
main(["attach", "--aggregate", "1234"])
1919

2020
captured = capsys.readouterr()
21+
print("Error", captured.err)
2122
assert "Can't use aggregated mode without an output file." in captured.err
23+
24+
25+
class TestAttachSubCommandOptions:
26+
@pytest.mark.parametrize(
27+
"option",
28+
[
29+
"--native",
30+
"--force",
31+
"-f",
32+
"--aggregate",
33+
"--follow-fork",
34+
"--trace-python-allocators",
35+
"--no-compress",
36+
],
37+
)
38+
def test_memray_attach_stop_tracking_option_with_other_options(
39+
self, option, capsys
40+
):
41+
# WHEN
42+
with pytest.raises(SystemExit):
43+
main(["attach", "1234", "--stop-tracking", option])
44+
45+
captured = capsys.readouterr()
46+
assert (
47+
"Can't use --stop-tracking with" in captured.err and option in captured.err
48+
)
49+
50+
@pytest.mark.parametrize(
51+
"arg1,arg2",
52+
[
53+
("--stop-tracking", "--heap-limit=10"),
54+
("--stop-tracking", "--duration=10"),
55+
("--heap-limit=10", "--duration=10"),
56+
],
57+
)
58+
def test_memray_attach_stop_tracking_option_with_other_mode_options(
59+
self, arg1, arg2, capsys
60+
):
61+
# WHEN
62+
with pytest.raises(SystemExit):
63+
main(["attach", "1234", arg1, arg2])
64+
65+
captured = capsys.readouterr()
66+
arg1_name = arg1.split("=")[0]
67+
arg2_name = arg2.split("=")[0]
68+
assert (
69+
f"argument {arg2_name}: not allowed with argument {arg1_name}"
70+
in captured.err
71+
)
72+
73+
@pytest.mark.parametrize(
74+
"option, argument",
75+
[("--output", "test.bin")],
76+
)
77+
def test_memray_attach_stop_tracking_option_with_output_options(
78+
self, option, argument, capsys
79+
):
80+
# WHEN
81+
with pytest.raises(SystemExit):
82+
main(["attach", "1234", "--stop-tracking", option, argument])
83+
84+
captured = capsys.readouterr()
85+
assert f"Can't use --stop-tracking with {option}" in captured.err

0 commit comments

Comments
 (0)