blob: aee9805a561ed0b0c7e3e77b53df8a13b3b9580f [file] [log] [blame]
Masayuki Igawa4f468052014-03-15 12:18:23 +09001# Copyright 2014 NEC Corporation.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16
17from tempest.common.utils import misc
18from tempest.tests import base
19
20
21@misc.singleton
22class TestFoo(object):
23
24 count = 0
25
26 def increment(self):
27 self.count += 1
28 return self.count
29
30
31@misc.singleton
32class TestBar(object):
33
34 count = 0
35
36 def increment(self):
37 self.count += 1
38 return self.count
39
40
41class TestMisc(base.TestCase):
42
43 def test_singleton(self):
44 test = TestFoo()
45 self.assertEqual(0, test.count)
46 self.assertEqual(1, test.increment())
47 test2 = TestFoo()
48 self.assertEqual(1, test.count)
49 self.assertEqual(1, test2.count)
50 self.assertEqual(test, test2)
51 test3 = TestBar()
52 self.assertNotEqual(test, test3)
Matt Riedemann7efa5c32014-05-02 13:35:44 -070053
54 def test_find_test_caller_test_case(self):
55 # Calling it from here should give us the method we're in.
56 self.assertEqual('TestMisc:test_find_test_caller_test_case',
57 misc.find_test_caller())
58
59 def test_find_test_caller_setup_self(self):
60 def setUp(self):
61 return misc.find_test_caller()
62 self.assertEqual('TestMisc:setUp', setUp(self))
63
64 def test_find_test_caller_setup_no_self(self):
65 def setUp():
66 return misc.find_test_caller()
67 self.assertEqual(':setUp', setUp())
68
69 def test_find_test_caller_setupclass_cls(self):
70 def setUpClass(cls): # noqa
71 return misc.find_test_caller()
72 self.assertEqual('TestMisc:setUpClass', setUpClass(self.__class__))
73
74 def test_find_test_caller_teardown_self(self):
75 def tearDown(self):
76 return misc.find_test_caller()
77 self.assertEqual('TestMisc:tearDown', tearDown(self))
78
79 def test_find_test_caller_teardown_no_self(self):
80 def tearDown():
81 return misc.find_test_caller()
82 self.assertEqual(':tearDown', tearDown())
83
84 def test_find_test_caller_teardown_class(self):
85 def tearDownClass(cls):
86 return misc.find_test_caller()
87 self.assertEqual('TestMisc:tearDownClass',
88 tearDownClass(self.__class__))