Debian Codegraph @

os_service_types/tests/test_warn.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 """
14 test_warn
15 ---------
16
17 Tests for warnings
18 """
19
20 import warnings
21
22 import os_service_types
23 from os_service_types import exc
24 from os_service_types.tests import base
25
26
27 class TestWarnOn(base.TestCase):
28 def setUp(self):
29 super().setUp()
30 # Cause all warnings to always be triggered.
31 warnings.simplefilter("always")
32 self.service_types = os_service_types.ServiceTypes(warn=True)
33
34 def test_warning_emitted_on_alias(self):
35 with warnings.catch_warnings(record=True) as w:
36 self.service_types.get_service_type('volumev2')
37 self.assertEqual(1, len(w))
38 self.assertTrue(issubclass(w[-1].category, exc.AliasUsageWarning))
39
40 def test_warning_not_emitted_on_official(self):
41 with warnings.catch_warnings(record=True) as w:
42 self.service_types.get_service_type('block-storage')
43 self.assertEqual(0, len(w))
44
45
46 class TestWarnOff(base.TestCase):
47 def setUp(self):
48 super().setUp()
49 # Cause all warnings to always be triggered.
50 warnings.simplefilter("always")
51 self.service_types = os_service_types.ServiceTypes()
52
53 def test_warning_not_emitted_on_alias(self):
54 with warnings.catch_warnings(record=True) as w:
55 self.service_types.get_service_type('volumev2')
56 self.assertEqual(0, len(w))
57
58 def test_warning_not_emitted_on_official(self):
59 with warnings.catch_warnings(record=True) as w:
60 self.service_types.get_service_type('block-storage')
61 self.assertEqual(0, len(w))