forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flavors.py
40 lines (30 loc) · 988 Bytes
/
test_flavors.py
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
import ast
import os
import mlflow
def read_file(path):
with open(path) as f:
return f.read()
def is_model_flavor(src):
for node in ast.iter_child_nodes(ast.parse(src)):
if (
isinstance(node, ast.Assign)
and isinstance(node.targets[0], ast.Name)
and node.targets[0].id == "FLAVOR_NAME"
):
return True
return False
def iter_flavor_names():
for root, _, files in os.walk("mlflow"):
for f in files:
if f != "__init__.py":
continue
path = os.path.join(root, f)
src = read_file(path)
if is_model_flavor(src):
basename = os.path.basename(root)
yield os.path.splitext(basename)[0]
def test_all_flavors_can_be_accessed_from_mlflow():
flavor_names = list(iter_flavor_names())
assert len(flavor_names) != 0
for flavor_name in flavor_names:
assert hasattr(mlflow, flavor_name)