-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest_client.py
138 lines (111 loc) · 3.62 KB
/
test_client.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import copy
import unittest
import warnings
from datetime import datetime
from mltrace import (
set_db_uri,
create_component,
log_component_run,
register,
load,
save,
)
from mltrace.entities import ComponentRun, IOPointer
class TestClient(unittest.TestCase):
def setUp(self):
set_db_uri("test")
def testLogEmptyComponentRun(self):
# Create component then log a run of it
create_component("test_component", "test_description", "shreya")
# Create a ComponentRun
cr = ComponentRun("test_component")
with self.assertRaises(RuntimeError):
log_component_run(cr)
def testLogBasicComponentRun(self):
# Create component then log a run of it
create_component("test_component", "test_description", "shreya")
# Create a ComponentRun
cr = ComponentRun(component_name="test_component")
cr.set_start_timestamp()
cr.code_snapshot = b"def main(): return"
cr.add_inputs(["duplicate_input", "duplicate_input"])
cr.add_outputs(["duplicate_output", "duplicate_output"])
cr.set_end_timestamp()
# Log component run
log_component_run(cr)
def testLogKVComponentRun(self):
# Tests implementation of values in iopointer
create_component(
name="valtest",
description="Tests implementation of values in iopointer.",
owner="me",
)
iop1 = ["this", "is", "the", "first"]
iop2 = ["this", "is", "the", "second"]
# Create iopointers and CR
iop1 = IOPointer(name="iop1", value=iop1)
iop2 = IOPointer(name="iop2", value=iop2)
cr = ComponentRun("valtest")
cr.set_start_timestamp()
cr.set_end_timestamp()
cr.add_input(iop1)
cr.add_output(iop2)
log_component_run(cr)
def testRegister(self):
# Create component then log a run of it
create_component("test_component", "test_description", "shreya")
@register(
component_name="test_component",
input_vars=["foo"],
output_vars=["bar"],
)
def test_func():
foo = "foo"
bar = "bar"
return
test_func()
def testRegisterNoReturn(self):
# Create component then log a run of it
create_component("test_component", "test_description", "shreya")
@register(
component_name="test_component",
input_vars=["foo"],
output_vars=["bar"],
)
def test_func():
x = 0
foo = x + 1
bar = x + 2
test_func()
def testRegisterWrongVar(self):
# Have a var not exist in the function and assert there is
# an error
create_component("test_component", "test_description", "shreya")
@register(
component_name="test_component",
input_vars=["foory"], # Not valid
output_vars=["bar"],
)
def test_func():
x = 0
foo = x + 1
bar = x + 2
@register(
component_name="test_component",
input_vars=["foo"],
output_vars=["barry"], # Not valid
)
def test_func2():
x = 0
foo = x + 1
bar = x + 2
with self.assertRaises(ValueError):
test_func()
with self.assertRaises(ValueError):
test_func2()
def testSaveAndLoad(self):
obj = {"foo": "bar"}
pathname = save(obj)
self.assertEqual(obj, load(pathname))
if __name__ == "__main__":
unittest.main()