test_pipeline.py 2.5 KB
Newer Older
1
import subprocess
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
2
from pathlib import Path
3
from typing import NamedTuple
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
4

5
6
import pytest

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
7
# class DatasetSpec:
8

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
9
dataset_spec = {"cora": {"timeout": 30}}
10
11
12
13
14
15
16
17
18


class ExperimentSpec(NamedTuple):
    pipeline: str
    dataset: str
    model: str
    timeout: int
    extra_cfg: dict = {}

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
19
20
21
22
23
24
25

exps = [
    ExperimentSpec(
        pipeline="nodepred", dataset="cora", model="sage", timeout=0.5
    )
]

26
27
28
29

@pytest.mark.parametrize("spec", exps)
def test_train(spec):
    cfg_path = "/tmp/test.yaml"
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    run = subprocess.run(
        [
            "dgl",
            "config",
            spec.pipeline,
            "--data",
            spec.dataset,
            "--model",
            spec.model,
            "--cfg",
            cfg_path,
        ],
        timeout=spec.timeout,
        capture_output=True,
    )
    assert (
        run.stderr is None or len(run.stderr) == 0
    ), "Found error message: {}".format(run.stderr)
48
49
50
    output = run.stdout.decode("utf-8")
    print(output)

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
51
52
53
54
55
56
57
58
    run = subprocess.run(
        ["dgl", "train", "--cfg", cfg_path],
        timeout=spec.timeout,
        capture_output=True,
    )
    assert (
        run.stderr is None or len(run.stderr) == 0
    ), "Found error message: {}".format(run.stderr)
59
60
61
    output = run.stdout.decode("utf-8")
    print(output)

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
62

63
64
TEST_RECIPE_FOLDER = "my_recipes"

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
65

66
67
@pytest.fixture
def setup_recipe_folder():
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
68
69
70
71
72
    run = subprocess.run(
        ["dgl", "recipe", "copy", "--dir", TEST_RECIPE_FOLDER],
        timeout=15,
        capture_output=True,
    )
73

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
74
75
76
77

@pytest.mark.parametrize(
    "file", [str(f) for f in Path(TEST_RECIPE_FOLDER).glob("*.yaml")]
)
78
79
def test_recipe(file, setup_recipe_folder):
    print("DGL enter train {}".format(file))
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
80
81
82
83
    try:
        run = subprocess.run(
            ["dgl", "train", "--cfg", file], timeout=5, capture_output=True
        )
84
85
86
87
88
89
90
91
92
        sh_stdout, sh_stderr = run.stdout, run.stderr
    except subprocess.TimeoutExpired as e:
        sh_stdout = e.stdout
        sh_stderr = e.stderr
    if sh_stderr is not None and len(sh_stderr) != 0:
        error_str = sh_stderr.decode("utf-8")
        lines = error_str.split("\n")
        for line in lines:
            line = line.strip()
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
93
94
95
96
97
            if (
                line.startswith("WARNING")
                or line.startswith("Aborted")
                or line.startswith("0%")
            ):
98
99
100
101
102
103
                continue
            else:
                assert len(line) == 0, error_str
    print("{} stdout: {}".format(file, sh_stdout))
    print("{} stderr: {}".format(file, sh_stderr))

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
104
105

# test_recipe( , None)