Skip to content

Commit 60a38cd

Browse files
committed
Simplify mxcc env option tests
1 parent c9094c0 commit 60a38cd

1 file changed

Lines changed: 3 additions & 27 deletions

File tree

tests/python/contrib/test_mxcc_env_options.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
1-
import ast
21
import os
3-
from pathlib import Path
42
from unittest.mock import patch
5-
6-
7-
def _load_env_options_helper():
8-
source_path = (
9-
Path(__file__).resolve().parents[3] / "python" / "tvm" / "contrib" / "mxcc.py"
10-
)
11-
tree = ast.parse(source_path.read_text(encoding="utf-8"))
12-
nodes = [
13-
node
14-
for node in tree.body
15-
if (
16-
isinstance(node, ast.Import)
17-
and all(alias.name in {"os", "shlex"} for alias in node.names)
18-
)
19-
or (isinstance(node, ast.FunctionDef) and node.name == "_get_env_mxcc_options")
20-
]
21-
module = ast.Module(body=nodes, type_ignores=[])
22-
ast.fix_missing_locations(module)
23-
namespace = {}
24-
exec(compile(module, str(source_path), "exec"), namespace)
25-
return namespace["_get_env_mxcc_options"]
3+
from tvm.contrib.mxcc import _get_env_mxcc_options
264

275

286
def test_env_mxcc_options_are_shell_split():
29-
get_options = _load_env_options_helper()
307
with patch.dict(os.environ, {"TVM_MXCC_OPTIONS": "--flag 'two words'"}, clear=True):
31-
assert get_options() == ["--flag", "two words"]
8+
assert _get_env_mxcc_options() == ["--flag", "two words"]
329

3310

3411
def test_env_mxcc_options_default_empty():
35-
get_options = _load_env_options_helper()
3612
with patch.dict(os.environ, {}, clear=True):
37-
assert get_options() == []
13+
assert _get_env_mxcc_options() == []
3814

3915

4016
if __name__ == "__main__":

0 commit comments

Comments
 (0)