Skip to content

Commit 576cb05

Browse files
committed
Add tests for run_file_cmd
1 parent 27582ca commit 576cb05

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/sage/cli/run_file_cmd_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from sage.cli.run_file_cmd import RunFileCmd
2+
from sage.cli.options import CliOptions
3+
from unittest.mock import patch
4+
import sys
5+
6+
def test_run_file_cmd(capsys, tmp_path):
7+
file = tmp_path / "test.sage"
8+
file.write_text("print(3^33)")
9+
options = CliOptions(file = [str(file)])
10+
run_file_cmd = RunFileCmd(options)
11+
12+
result = run_file_cmd.run()
13+
captured = capsys.readouterr()
14+
assert captured.out == "5559060566555523\n"
15+
16+
17+
def test_run_file_cmd_with_args(capsys, tmp_path):
18+
with patch.object(sys, 'argv', ["python3", "test.sage", "1", "1"]):
19+
file = tmp_path / "test.sage"
20+
file.write_text("import sys; print(int(sys.argv[1]) + int(sys.argv[2]))")
21+
options = CliOptions(file = [str(file), "1", "1"])
22+
run_file_cmd = RunFileCmd(options)
23+
24+
result = run_file_cmd.run()
25+
captured = capsys.readouterr()
26+
assert captured.out == "2\n"

0 commit comments

Comments
 (0)