test_Singleton.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 # @file test_Singleton.py
5 # @brief test for Singleton class
6 # @date $Date$
7 # @author Shinji Kurihara
8 #
9 # Copyright (C) 2003-2005
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id$
17 #
18 
19 #
20 # $Log$
21 #
22 #
23 
24 import sys
25 sys.path.insert(1,"../")
26 
27 import unittest
28 
29 from Singleton import *
30 
32  _cnt = 0
33  def __init__(self):
34  print "SingletonMock"
35  #self._cnt = 0
36  pass
37 
38  def up(self):
39  self._cnt += 1
40 
41  def get(self):
42  return self._cnt
43 
44 
45 class TestSingleton(unittest.TestCase):
46  def setUp(self):
47  return
48 
49  def tearDown(self):
50  return
51 
52 
53  def test_SingletonCase(self):
54  mock = SingletonMock()
55  print "Singleton 0"
56  mock0 = SingletonMock()
57  print "mock0 ", mock0
58  print "Singleton 1"
59  mock1 = SingletonMock()
60  print "mock1 ", mock1
61  self.assertEqual(mock0.get(), 0)
62  self.assertEqual(mock1.get(), 0)
63  mock0.up()
64  self.assertEqual(mock0.get(), 1)
65  self.assertEqual(mock1.get(), 1)
66  mock1.up()
67  self.assertEqual(mock0.get(), 2)
68  self.assertEqual(mock1.get(), 2)
69  mock2 = SingletonMock.instance()
70  print "mock2 ", mock2
71  self.assertEqual(mock0.get(), 2)
72  self.assertEqual(mock1.get(), 2)
73  self.assertEqual(mock2.get(), 2)
74  return
75 
76 if __name__ == "__main__":
77  unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:35