-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_test.go
83 lines (68 loc) · 2.13 KB
/
file_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
83
package mlflow
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFileStoreExperiments(t *testing.T) {
fs, err := NewFileStore(t.TempDir())
require.NoError(t, err)
expsByName, err := fs.ExperimentsByName()
require.NoError(t, err)
assert.Equal(t, len(expsByName), 1, "expected only the default experiment", len(expsByName))
require.NoError(t, os.RemoveAll(fs.rootDir))
expsByName, err = fs.ExperimentsByName()
assert.NoError(t, err)
assert.Equal(t, len(expsByName), 0)
for i := 0; i < 2; i++ {
name := fmt.Sprintf("test%d", i)
exp, err := fs.GetOrCreateExperimentWithName(name)
require.NoError(t, err)
expsByName, err = fs.ExperimentsByName()
require.NoError(t, err)
assert.Equal(t, len(expsByName), i+1)
assert.Equal(t, expsByName[name].(*fileExperiment).ExperimentID, exp.(*fileExperiment).ExperimentID)
}
}
func TestRun(t *testing.T) {
fs, err := NewFileStore(t.TempDir())
require.NoError(t, err)
exp, err := fs.GetOrCreateExperimentWithName("exp0")
require.NoError(t, err)
_, err = exp.GetRun("run0")
require.Error(t, err)
created, err := exp.CreateRun("run0")
require.NoError(t, err)
got, err := exp.GetRun(created.ID())
require.NoError(t, err)
assert.Equal(t, got.ID(), created.ID())
assert.NoError(t, got.SetName("new name"))
assert.Equal(t, "new name", got.Name())
const tagKey = "tag0"
const tagVal = "val0"
require.NoError(t, created.SetTag(tagKey, tagVal))
gotTag, err := created.GetTag(tagKey)
require.NoError(t, err)
assert.Equal(t, gotTag, tagVal)
metrics := []Metric{
{Key: "metric0", Val: 0.0},
{Key: "metric0", Val: 1.0},
{Key: "metric1", Val: 0.1},
}
require.NoError(t, created.LogMetrics(metrics, 0))
require.NoError(t, created.LogMetrics(metrics, 1))
params := []Param{
{Key: "param0", Val: "val0"},
{Key: "param1", Val: "val1"},
}
require.NoError(t, created.LogParams(params))
_, err = created.GetParam("param2")
require.Error(t, err)
paramVal, err := created.GetParam("param1")
require.NoError(t, err)
assert.Equal(t, paramVal, "val1")
assert.NoError(t, created.End())
assert.NoError(t, created.Fail())
}