-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·130 lines (112 loc) · 3.8 KB
/
tests.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
#!/usr/bin/env python3
import os
import kcl
import pytest
# Get the path to this script's parent directory.
kcl_dir_file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "files"
)
@pytest.mark.asyncio
async def test_kcl_execute():
# Read from a file.
await kcl.execute(os.path.join(kcl_dir_file_path, "lego.kcl"))
@pytest.mark.asyncio
async def test_kcl_execute_code():
# Read from a file.
with open(os.path.join(kcl_dir_file_path, "lego.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
await kcl.execute_code(code)
@pytest.mark.asyncio
async def test_kcl_execute_code_and_snapshot():
# Read from a file.
with open(os.path.join(kcl_dir_file_path, "lego.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
image_bytes = await kcl.execute_code_and_snapshot(
code, kcl.ImageFormat.Jpeg
)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_code_and_export():
# Read from a file.
with open(os.path.join(kcl_dir_file_path, "lego.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
files = await kcl.execute_code_and_export(
code, kcl.FileExportFormat.Step
)
assert files is not None
assert len(files) > 0
assert files[0] is not None
name = files[0].name
contents = files[0].contents
assert name is not None
assert len(name) > 0
assert contents is not None
assert len(contents) > 0
@pytest.mark.asyncio
async def test_kcl_execute_dir_assembly():
# Read from a file.
await kcl.execute(os.path.join(kcl_dir_file_path, "walkie-talkie"))
@pytest.mark.asyncio
async def test_kcl_execute_and_snapshot():
# Read from a file.
image_bytes = await kcl.execute_and_snapshot(
os.path.join(kcl_dir_file_path, "lego.kcl"), kcl.ImageFormat.Jpeg
)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_and_snapshot_dir():
# Read from a file.
image_bytes = await kcl.execute_and_snapshot(
os.path.join(kcl_dir_file_path, "walkie-talkie"), kcl.ImageFormat.Jpeg
)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_and_export():
# Read from a file.
files = await kcl.execute_and_export(
os.path.join(kcl_dir_file_path, "lego.kcl"), kcl.FileExportFormat.Step
)
assert files is not None
assert len(files) > 0
assert files[0] is not None
name = files[0].name
contents = files[0].contents
assert name is not None
assert len(name) > 0
assert contents is not None
assert len(contents) > 0
def test_kcl_format():
# Read from a file.
with open(os.path.join(kcl_dir_file_path, "lego.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
formatted_code = kcl.format(code)
assert formatted_code is not None
assert len(formatted_code) > 0
def test_kcl_lint():
# Read from a file.
with open(os.path.join(kcl_dir_file_path, "box_with_linter_errors.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
lints = kcl.lint(code)
assert lints is not None
assert len(lints) > 0
description = lints[0].description
assert description is not None
assert len(description) > 0
finding = lints[0].finding
assert finding is not None
finding_title = finding.title
assert finding_title is not None
assert len(finding_title) > 0