forked from los-cocos/cocos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_p_ba_cocosnode_actions.py
More file actions
147 lines (123 loc) · 4.06 KB
/
test_p_ba_cocosnode_actions.py
File metadata and controls
147 lines (123 loc) · 4.06 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from __future__ import division, print_function, unicode_literals
# important: set cocos_utest=1 in the environment before run.
# that simplifies the pyglet mockup needed
# remember to erase or set to zero for normal runs
import os
assert os.environ['cocos_utest']
# set the desired pyglet mockup
import sys
sys.path.insert(0,'pyglet_mockup1')
import pyglet
assert pyglet.mock_level == 1
from cocos.director import director
from cocos.cocosnode import CocosNode
import cocos.actions as ac
import sys
director.init()
rec = []
next_done=0 #bitflags
class UAction(ac.Action):
##use actions names 1, 2 or '1', '2' ; then you instruct the .step method
##to set ._done using the global next_done
def init(self, name):
rec.append((name, 'init'))
self.name = name
def start(self):
rec.append((self.name, 'start'))
def step(self, dt):
global rec, next_done
rec.append((self.name, 'step', dt))
if int(self.name) & next_done:
print('setting %s _done to True'%self.name)
self._done = True
def stop(self):
rec.append((self.name, 'stop'))
## def done(self):
## rec.append((self.name, 'done',
class Test_cocosnode_actions_functionality:
def test_initial_actions_container_empty(self):
node = CocosNode()
assert len(node.actions)==0
def test_do_inmediate_effects1(self):
# do called without an explicit target
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action = UAction(name1)
rec = []
a_copy = node.do(action)
assert a_copy.target == node
assert a_copy in node.actions
assert len(node.actions)==1
assert rec[0]==(name1, 'start')
assert len(rec)==1
def test_do_inmediate_effects2(self):
# do called with an explicit target
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action = UAction(name1)
my_target = 'zptx'
rec = []
a_copy = node.do(action, target=my_target)
assert a_copy.target == my_target
assert a_copy in node.actions
assert len(node.actions)==1
assert rec[0]==(name1, 'start')
assert len(rec)==1
def test_actions_stepping_without_completion(self):
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action1 = UAction(name1)
name2 = '2'
action2 = UAction(name2)
a1_copy = node.do(action1)
a2_copy = node.do(action2)
rec = []
dt = 0.1
node._step(dt)
recx = [e for e in rec if e[0]==name1]
assert recx[0]==(name1, 'step', dt)
assert len(recx)==1
recx = [e for e in rec if e[0]==name2]
assert recx[0]==(name2, 'step', dt)
assert len(recx)==1
# the alternate do call, with an explicit target needs some thinking.
def test_remove_action(self):
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action1 = UAction(name1)
name2 = '2'
action2 = UAction(name2)
a1_copy = node.do(action1)
a2_copy = node.do(action2)
assert len(node.actions)==2
rec = []
node.remove_action(a1_copy)
recx = [ e for e in rec if e[0]==name1]
assert recx[0]==(name1, 'stop')
assert len(recx)==1
rec =[]
dt = 0.1
node._step(dt)# needed to complete delete, will traceback if remove failed
assert len(node.actions)==1
assert a2_copy in node.actions
recx = [ e for e in rec if e[0]==name1]
assert len(recx)==0
def test_node_stop_calls_remove_and_not_anything_in_action(self):
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action1 = UAction(name1)
name2 = '2'
action2 = UAction(name2)
a1_copy = node.do(action1)
a2_copy = node.do(action2)
# def test_stepping_and_one_action_reach_normal_termination(self):