Skip to content

Commit 4bf30cd

Browse files
Add CLI test
1 parent 42eb5d4 commit 4bf30cd

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

test/data/script.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Print["Hello"];

test/test_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
import subprocess
3+
4+
import os.path as osp
5+
import re
6+
import pytest
7+
import sys
8+
9+
10+
def get_testdir():
11+
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
12+
return osp.realpath(filename)
13+
14+
15+
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7 or higher")
16+
def test_cli():
17+
script_file = osp.join(get_testdir(), "data", "script.m")
18+
19+
# asserts output contains 'Hello' and '2'
20+
assert re.match(
21+
r"Hello\s+2",
22+
subprocess.run(
23+
["mathics", "-e", "Print[1+1];", "-script", script_file],
24+
capture_output=True,
25+
).stdout.decode("utf-8"),
26+
)
27+
28+
29+
if __name__ == "__main__":
30+
test_cli()

0 commit comments

Comments
 (0)