-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_test.go
82 lines (73 loc) · 1.65 KB
/
model_test.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mxnet
import (
"errors"
"os"
"path/filepath"
"testing"
rice "github.com/GeertJohan/go.rice"
"github.com/k0kubun/pp"
"github.com/rai-project/dlframework"
"github.com/stretchr/testify/assert"
yaml "gopkg.in/yaml.v2"
)
var (
builtinModelsBox = rice.MustFindBox("builtin_models")
)
func TestUnmarshalModel(t *testing.T) {
builtinModelsBox.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
var model dlframework.ModelManifest
data := builtinModelsBox.MustBytes(path)
err = yaml.Unmarshal(data, &model)
assert.NoError(t, err)
assert.NotEmpty(t, model)
assert.NoError(t, model.Validate())
if false {
pp.Println(model)
}
return err
})
}
func TestModelRegistration(t *testing.T) {
builtinModelsBox.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if ext := filepath.Ext(path); ext != ".yml" && ext != ".yaml" {
return nil
}
var model dlframework.ModelManifest
data := builtinModelsBox.MustBytes(path)
err = yaml.Unmarshal(data, &model)
if assert.NoError(t, err) {
return err
}
if assert.NotEmpty(t, model) {
return errors.New("empty model")
}
name, err := model.CanonicalName()
assert.NoError(t, err)
assert.NotEmpty(t, name)
m, err := dlframework.FindModel(name)
assert.NoError(t, err)
assert.NotEmpty(t, m)
// assert.EqualValues(t, model, m)
// pp.Println(m)
// pp.Println(model)
if false {
pp.Println(model)
}
return err
})
models, err := dlframework.Models()
assert.NoError(t, err)
assert.NotEmpty(t, models)
}