Module ResourceTest
[hide private]
[frames] | no frames]

Source Code for Module ResourceTest

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import unittest 
24  import time 
25   
26  from Engine import Engine 
27  from Resource import Resource 
28   
29 -def loader():
30 return 0xdada
31
32 -class ResourceTest(unittest.TestCase):
33 - def testAsynchLoad(self):
34 self.r = Resource() 35 self.e.addTask(self.r, synchronized = False) 36 37 self.r.load(self, "result", lambda: loader()) 38 39 while not self.result: 40 self.e.run() 41 42 assert self.result == 0xdada
43
44 - def testSynchLoad(self):
45 self.r = Resource() 46 self.e.addTask(self.r, synchronized = False) 47 48 assert self.r.load(self, "result2", loader, synch = True) == 0xdada 49 assert self.result2 == 0xdada
50
51 - def testAsynchLoadSeries(self):
52 self.r = Resource() 53 self.e.addTask(self.r, synchronized = False) 54 55 for i in range(10): 56 self.r.load(self, "result%d" % i, loader) 57 58 while not self.result9: 59 self.e.run() 60 61 assert self.result9 == 0xdada
62
63 - def testCallback(self):
64 self.r = Resource() 65 self.e.addTask(self.r, synchronized = False) 66 67 self.quux = None 68 def loaded(r): 69 self.quux = r
70 71 self.r.load(self, "fuuba", loader, onLoad = loaded).join() 72 73 while not self.fuuba: 74 self.e.run() 75 76 assert self.fuuba == self.quux
77
78 - def setUp(self):
79 self.e = Engine()
80
81 - def tearDown(self):
82 self.e.quit()
83 84 if __name__ == "__main__": 85 unittest.main() 86