-
Notifications
You must be signed in to change notification settings - Fork 24
/
cm_tests.py
114 lines (91 loc) · 4.01 KB
/
cm_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
# Copyright 2017 CrowdMaster Developer Team
#
# ##### BEGIN GPL LICENSE BLOCK ######
# This file is part of CrowdMaster.
#
# CrowdMaster is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CrowdMaster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CrowdMaster. If not, see <http://www.gnu.org/licenses/>.
# ##### END GPL LICENSE BLOCK #####
import unittest
import bpy
from bpy.types import Operator
from .cm_syncManager import SyncManagerTestCase
class AddonRegisterTestCase(unittest.TestCase):
def setUp(self):
self.play_animation = bpy.context.user_preferences.addons[
__package__].preferences.play_animation
bpy.ops.wm.read_homefile()
bpy.context.user_preferences.addons[__package__].preferences.play_animation = False
def tearDown(self):
bpy.context.user_preferences.addons[__package__].preferences.play_animation = self.play_animation
def testStartStopSim(self):
pa = bpy.context.user_preferences.addons[__package__].preferences.play_animation
bpy.ops.scene.cm_start()
bpy.ops.scene.cm_stop()
def testRegistered(self):
sceneProps = ["cm_actions", "cm_events", "cm_groups",
"cm_groups_index", "cm_manual",
"cm_paths", "cm_view_details", "cm_view_details_index"]
for sp in sceneProps:
self.assertIn(sp, dir(bpy.context.scene))
opsProps = ["cm_actions_populate", "cm_actions_remove", "cm_agent_add",
"cm_agent_add_selected", "cm_agent_nodes_generate",
"cm_agents_move", "cm_events_move",
"cm_events_populate", "cm_events_remove",
"cm_groups_reset",
"cm_paths_populate", "cm_paths_remove",
"cm_place_deferred_geo", "cm_run_long_tests",
"cm_run_short_tests", "cm_save_prefs",
"cm_start", "cm_stop"]
for op in opsProps:
self.assertIn(op, dir(bpy.ops.scene))
def createShortTestSuite():
"""Gather all the short tests from this module in a test suite"""
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(AddonRegisterTestCase))
test_suite.addTest(unittest.makeSuite(SyncManagerTestCase))
return test_suite
def createLongTestSuite():
"""Gather all the long tests from this module in a test suite"""
test_suite = unittest.TestSuite()
return test_suite
class CrowdMaster_run_short_tests(Operator):
"""For tests cases that will run quickly.
ie. that don't involve running simulations"""
bl_idname = "scene.cm_run_short_tests"
bl_label = "Run Short Tests"
def execute(self, context):
testSuite = createShortTestSuite()
test = unittest.TextTestRunner()
result = test.run(testSuite)
if not result.wasSuccessful():
return {'CANCELLED'}
return {'FINISHED'}
class CrowdMaster_run_long_tests(Operator):
"""For tests cases that will take a long time.
ie. that involve simulation"""
bl_idname = "scene.cm_run_long_tests"
bl_label = "Run Long Tests"
def execute(self, context):
testSuite = createLongTestSuite()
test = unittest.TextTestRunner()
result = test.run(testSuite)
if not result.wasSuccessful():
return {'CANCELLED'}
return {'FINISHED'}
def register():
bpy.utils.register_class(CrowdMaster_run_short_tests)
bpy.utils.register_class(CrowdMaster_run_long_tests)
def unregister():
bpy.utils.unregister_class(CrowdMaster_run_short_tests)
bpy.utils.unregister_class(CrowdMaster_run_long_tests)