|
1 | | -import ast |
2 | 1 | import os |
3 | | -from pathlib import Path |
4 | 2 | 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 |
26 | 4 |
|
27 | 5 |
|
28 | 6 | def test_env_mxcc_options_are_shell_split(): |
29 | | - get_options = _load_env_options_helper() |
30 | 7 | 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"] |
32 | 9 |
|
33 | 10 |
|
34 | 11 | def test_env_mxcc_options_default_empty(): |
35 | | - get_options = _load_env_options_helper() |
36 | 12 | with patch.dict(os.environ, {}, clear=True): |
37 | | - assert get_options() == [] |
| 13 | + assert _get_env_mxcc_options() == [] |
38 | 14 |
|
39 | 15 |
|
40 | 16 | if __name__ == "__main__": |
|
0 commit comments