Debian Codegraph @

os_resource_classes/tests/test_os_resource_classes.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_os_resource_classes
15 ----------------------------------
16
17 Tests for `os_resource_classes` module.
18 """
19
20 import os_resource_classes as rc
21 from os_resource_classes.tests import base
22
23
24 class TestOs_resource_classes(base.TestCase):
25
26 def test_id_mapping_strings(self):
27 self.assertEqual('VCPU', rc.STANDARDS[0])
28 self.assertEqual('DISK_GB', rc.STANDARDS[2])
29
30 def test_id_mapping_symbols(self):
31 self.assertEqual(rc.VCPU, rc.STANDARDS[0])
32 self.assertEqual(rc.DISK_GB, rc.STANDARDS[2])
33
34 def test_standards_tail(self):
35 """A sanity check that developers are paying attention.
36
37 When one or more standard classes are added, change the expected
38 last class to the last one added and the length to the new length
39 of rc.STANDARDS.
40
41 If you arrive here because you've run the tests and they've failed
42 it's possible you've added some standard classes and not thought
43 about their order. You _must_ add new standard classs at the end
44 of the STANDARDS list, otherwise database ids will get confused
45 in the placement service.
46 """
47 expected_last_class = rc.NET_PACKET_RATE_IGR_KILOPACKET_PER_SEC
48 expected_length = 21
49 self.assertEqual(expected_last_class, rc.STANDARDS[-1])
50 self.assertEqual(expected_length, len(rc.STANDARDS))
51
52 def test_normalize_name(self):
53 values = [
54 ("foo", "CUSTOM_FOO"),
55 ("VCPU", "CUSTOM_VCPU"),
56 ("CUSTOM_BOB", "CUSTOM_CUSTOM_BOB"),
57 ("CUSTM_BOB", "CUSTOM_CUSTM_BOB"),
58 # Bug #1762789: The upper() builtin treats sharp S (\xdf)
59 # differently in py2 vs py3. Make sure normalize_name handles it
60 # properly.
61 (u"Fu\xdfball", u"CUSTOM_FU_BALL"),
62 ("abc-123", "CUSTOM_ABC_123"),
63 ("Hello, world! This is a test ^_^",
64 "CUSTOM_HELLO_WORLD_THIS_IS_A_TEST_"),
65 (" leading and trailing spaces ",
66 "CUSTOM__LEADING_AND_TRAILING_SPACES_"),
67 ]
68 for test_value, expected in values:
69 result = rc.normalize_name(test_value)
70 self.assertEqual(expected, result)