Coverage for manila/tests/scheduler/weighers/test_base.py: 93%

26 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2011-2012 OpenStack Foundation. 

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""" 

17Tests For Scheduler weighers. 

18""" 

19 

20from manila.scheduler.weighers import base 

21from manila import test 

22from manila.tests.scheduler import fakes 

23 

24 

25class TestWeightHandler(test.TestCase): 

26 def test_get_all_classes(self): 

27 namespace = "manila.tests.scheduler.fakes" 

28 handler = base.BaseWeightHandler( 

29 base.BaseWeigher, namespace) 

30 classes = handler.get_all_classes() 

31 self.assertIn(fakes.FakeWeigher1, classes) 

32 self.assertIn(fakes.FakeWeigher2, classes) 

33 self.assertNotIn(fakes.FakeClass, classes) 

34 

35 def test_no_multiplier(self): 

36 class FakeWeigher(base.BaseWeigher): 

37 def _weigh_object(self, *args, **kwargs): 

38 pass 

39 

40 self.assertEqual(1.0, 

41 FakeWeigher().weight_multiplier()) 

42 

43 def test_no_weight_object(self): 

44 class FakeWeigher(base.BaseWeigher): 

45 def weight_multiplier(self, *args, **kwargs): 

46 pass 

47 self.assertRaises(TypeError, 

48 FakeWeigher) 

49 

50 def test_normalization(self): 

51 # weight_list, expected_result, minval, maxval 

52 map_ = ( 

53 ((), (), None, None), 

54 ((0.0, 0.0), (0.0, 0.0), None, None), 

55 ((1.0, 1.0), (0.0, 0.0), None, None), 

56 

57 ((20.0, 50.0), (0.0, 1.0), None, None), 

58 ((20.0, 50.0), (0.0, 0.375), None, 100.0), 

59 ((20.0, 50.0), (0.4, 1.0), 0.0, None), 

60 ((20.0, 50.0), (0.2, 0.5), 0.0, 100.0), 

61 ) 

62 for seq, result, minval, maxval in map_: 

63 ret = base.normalize(seq, minval=minval, maxval=maxval) 

64 self.assertEqual(result, tuple(ret))