forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
77 lines (58 loc) · 1.98 KB
/
utils.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
from unittest import TestCase
from CAD_Sketcher.solver import solve_system
class BgsTestCase(TestCase):
interactive = False
log_level = "INFO"
@classmethod
def setUpClass(cls):
from CAD_Sketcher.utilities.preferences import get_prefs
prefs = get_prefs()
prefs.logging_level = cls.log_level
import bpy
# Create new scene for tests
cls.scene = bpy.data.scenes.new(cls.__name__)
bpy.context.window.scene = cls.scene
cls.ops = bpy.ops
cls.data = bpy.data
cls.context = bpy.context
cls.sketcher = cls.context.scene.sketcher
cls.entities = cls.sketcher.entities
cls.constraints = cls.sketcher.constraints
@classmethod
def tearDownClass(cls):
if cls.interactive:
return
# Delete scene
context = cls.context
data = cls.data
data.scenes.remove(cls.scene)
@staticmethod
def force_entity_update(scene):
for entity in scene.sketcher.entities.all:
entity.update()
def solve(self):
self.assertTrue(solve_system(self.context))
class Sketch2dTestCase(BgsTestCase):
def new_sketch(self):
self.entities.ensure_origin_elements(self.context)
wp = self.entities.origin_plane_XY
return self.entities.add_sketch(wp)
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.entities.ensure_origin_elements(cls.context)
@classmethod
def tearDownClass(cls):
super().tearDownClass()
if cls.interactive:
return
def setUp(self) -> None:
self.sketch = self.new_sketch()
self.sketch.name = self._testMethodName
self.context.scene.sketcher.active_sketch = self.sketch
return super().setUp()
def tearDown(self) -> None:
self.context.scene.sketcher.active_sketch = None
return super().tearDown()
def solve(self):
self.assertTrue(self.sketch.solve(self.context))