-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtest_v01.py
95 lines (71 loc) · 2.63 KB
/
test_v01.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
import pytest
from codeboxapi import CodeBox
def test_sync(codebox: CodeBox) -> None:
try:
assert codebox.start() == "started"
print("Started")
assert codebox.status() == "running"
print("Running")
codebox.run("x = 'Hello World!'")
assert codebox.run("print(x)") == "Hello World!\n"
print("Printed")
file_name = "test_file.txt"
assert file_name in str(codebox.upload(file_name, b"Hello World!"))
print("Uploaded")
assert file_name in str(
codebox.run("import os;\nprint(os.listdir(os.getcwd())); ")
)
assert file_name in str(codebox.list_files())
assert codebox.download(file_name).get_content() == b"Hello World!"
print("Downloaded")
assert "matplotlib" in str(codebox.install("matplotlib"))
assert (
"error"
!= codebox.run("import matplotlib; print(matplotlib.__version__)").type
)
print("Installed")
o = codebox.run(
"import matplotlib.pyplot as plt;"
"plt.plot([1, 2, 3, 4], [1, 4, 2, 3]); plt.show()"
)
assert o.type == "image/png"
print("Plotted")
finally:
assert codebox.stop() == "stopped"
print("Stopped")
@pytest.mark.asyncio
async def test_async(codebox: CodeBox) -> None:
try:
assert await codebox.astart() == "started"
print("Started")
assert await codebox.astatus() == "running"
print("Running")
await codebox.arun("x = 'Hello World!'")
assert (await codebox.arun("print(x)")) == "Hello World!\n"
print("Printed")
file_name = "test_file.txt"
assert file_name in str(await codebox.aupload(file_name, b"Hello World!"))
print("Uploaded")
assert file_name in str(
await codebox.arun("import os;\nprint(os.listdir(os.getcwd())); ")
)
assert file_name in str(await codebox.alist_files())
assert (await codebox.adownload(file_name)).get_content() == b"Hello World!"
print("Downloaded")
assert "matplotlib" in str(await codebox.ainstall("matplotlib"))
assert (
"error"
!= (
await codebox.arun("import matplotlib; print(matplotlib.__version__)")
).type
)
print("Installed")
o = await codebox.arun(
"import matplotlib.pyplot as plt;"
"plt.plot([1, 2, 3, 4], [1, 4, 2, 3]); plt.show()"
)
assert o.type == "image/png"
print("Plotted")
finally:
assert await codebox.astop() == "stopped"
print("Stopped")