/
test_objects.py
96 lines (78 loc) · 2.33 KB
/
test_objects.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
import unittest
from traitlets import TraitError
import numpy as np
from ..objects import Drawable
from ..k3d import text
class TestDrawable(unittest.TestCase):
def setUp(self):
self.obj = Drawable()
def test_iteration_returns_object(self):
for obj in self.obj:
self.assertTrue(isinstance(obj, Drawable))
def test_can_add_another_object(self):
self.obj += Drawable()
for obj in self.obj:
self.assertTrue(isinstance(obj, Drawable))
def test_can_add_many_objects(self):
obj = Drawable()
self.obj += obj + obj
for obj in self.obj:
self.assertTrue(isinstance(obj, Drawable))
class TestText(unittest.TestCase):
def test_position_accepts_numpy(self):
text_ = text('test', [0, 0, 0])
text_.position = np.arange(3)
class TestSTL(unittest.TestCase):
def test_creation(self):
from ..objects import STL
s = STL(text='''
solid
facet normal 0 0 0
outer loop
vertex -1.000000 1.000000 -1.000000
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
endsolid
'''.strip())
def test_creation_named(self):
from ..objects import STL
STL(text='''
solid named_solid
facet normal 0 0 0
outer loop
vertex -1.000000 1.000000 -1.000000
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
endsolid named_solid
'''.strip())
def test_invalid(self):
from ..objects import STL
s = STL(text='''
solid
facet normal 0 0 0
outer loop
vertex -1.000000 1.000000 -1.000000
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
endsolid
'''.strip())
def assign_bad():
# missing endsolid, gibberish after facet normal:
s.text = '''solid
facet normal 0 0 0 bebebe
outer loop
vertex -1.000000 1.000000 -1.000000
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
'''
self.assertRaises(TraitError, assign_bad)
if __name__ == '__main__':
unittest.main()