-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathtest_main.py
More file actions
58 lines (45 loc) · 1.32 KB
/
test_main.py
File metadata and controls
58 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
import os.path as osp
import re
import subprocess
import sys
import pytest
from mathics import version_string
def get_testdir():
filename = osp.normcase(osp.dirname(osp.abspath(__file__)))
return osp.realpath(filename)
@pytest.mark.skipif(
sys.platform in ("emscripten",),
reason="Pyodide does not support processes",
)
def test_cli():
script_file = osp.join(get_testdir(), "data", "script.m")
# asserts output contains 'Hello' and '2'
result = subprocess.run(
["mathics", "-c", "Print[1+1];", "-f", script_file],
capture_output=True,
)
assert re.match(r"Hello\s+2", result.stdout.decode("utf-8"))
assert result.returncode == 0
result = subprocess.run(
["mathics", "-ecode", "2+3", "---trace-builtins"],
capture_output=False,
)
assert result.returncode == 0
@pytest.mark.skipif(
sys.platform in ("emscripten",),
reason="Pyodide does not support processes",
)
def test_version_option():
"""
Check that --version works and returns
software version information.
"""
result = subprocess.run(
["mathics", "--version"],
capture_output=True,
)
assert result.stdout.decode("utf-8").index(version_string) == 0
assert result.returncode == 0
if __name__ == "__main__":
test_cli()