bioweb  0.09.92
C++/Python(django)/JavaScript(angularJS) framework
tests.py
Go to the documentation of this file.
1 ## @file calcpy/tests.py
2 # @brief c++ calculation library Python API unit testing
3 
4 import django.test
5 import calc
6 import views
7 import time
8 
9 class CalcPyLibraryTestCase(django.test.TestCase):
10  """integration test, call C++ library interface from Python"""
11 
12  def test01getNumber(self):
13  """test the return number"""
14  self.assertEqual( calc.getNumber(), 1234 )
15 
16  def test02command(self):
17  """start/stop tick command test"""
18  cmdmgr = calc.CommandManager()
19  cmd_id = cmdmgr.start()
20  self.assertNotEqual( cmdmgr.getState(cmd_id), calc.DONE )
21  for i in range(100):
22  time.sleep(0.1)
23  if cmdmgr.getState(cmd_id) == calc.DONE:
24  break
25  self.assertEqual( cmdmgr.getState(cmd_id), calc.DONE )
26  self.assertEqual( len(cmdmgr.getIds()), 1 )
27 
28 
29 class CalcPyViewTestCase(django.test.TestCase):
30  """module view test"""
31 
32  def test01getNumber(self):
33  """check if service return proper dict"""
34  self.assertEqual( views.getNumber({}), {'number': 1234})
35 
36  def test02getCommands(self):
37  """check if service return proper dict"""
38  self.assertEqual( views.getCommands({}),
39  {1: {'progress': 0.995, 'state': 'DONE'}})
40  dict1 = views.getCommands({})
41  views.startCommand({});
42  dict2 = views.getCommands({})
43  self.assertEqual( len(dict1) + 1, len(dict2) )
44 
45 
46 
47 
48 
49 
50