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()
test_Singleton.SingletonMock.__init__
def __init__(self)
Definition: test_Singleton.py:33
test_Singleton.TestSingleton.test_SingletonCase
def test_SingletonCase(self)
Definition: test_Singleton.py:53
test_Singleton.SingletonMock.get
def get(self)
Definition: test_Singleton.py:41
test_Singleton.SingletonMock.up
def up(self)
Definition: test_Singleton.py:38
test_Singleton.SingletonMock
Definition: test_Singleton.py:31
test_Singleton.TestSingleton
Definition: test_Singleton.py:45
test_Singleton.SingletonMock._cnt
int _cnt
Definition: test_Singleton.py:32
Singleton
test_Singleton.TestSingleton.tearDown
def tearDown(self)
Definition: test_Singleton.py:49
test_Singleton.TestSingleton.setUp
def setUp(self)
Definition: test_Singleton.py:46


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Apr 21 2025 02:45:07