Coverage for manila/tests/test_misc.py: 57%

33 statements  

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

1# Copyright 2010 OpenStack LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15import glob 

16import os 

17 

18 

19from manila import exception 

20from manila import test 

21 

22 

23class ExceptionTestCase(test.TestCase): 

24 @staticmethod 

25 def _raise_exc(exc): 

26 raise exc() 

27 

28 def test_exceptions_raise(self): 

29 # NOTE(dprince): disable format errors since we are not passing kwargs 

30 self.flags(fatal_exception_format_errors=False) 

31 for name in dir(exception): 

32 exc = getattr(exception, name) 

33 if isinstance(exc, type): 

34 self.assertRaises(exc, self._raise_exc, exc) 

35 

36 

37class ProjectTestCase(test.TestCase): 

38 def test_all_migrations_have_downgrade(self): 

39 topdir = os.path.normpath(os.path.dirname(__file__) + '/../../') 

40 py_glob = os.path.join(topdir, "manila", "db", "sqlalchemy", 

41 "migrate_repo", "versions", "*.py") 

42 missing_downgrade = [] 

43 for path in glob.iglob(py_glob): 43 ↛ 44line 43 didn't jump to line 44 because the loop on line 43 never started

44 has_upgrade = False 

45 has_downgrade = False 

46 with open(path, "r") as f: 

47 for line in f: 

48 if 'def upgrade(' in line: 

49 has_upgrade = True 

50 if 'def downgrade(' in line: 

51 has_downgrade = True 

52 

53 if has_upgrade and not has_downgrade: 

54 fname = os.path.basename(path) 

55 missing_downgrade.append(fname) 

56 

57 helpful_msg = ("The following migrations are missing a downgrade:" 

58 "\n\t%s") % '\n\t'.join(sorted(missing_downgrade)) 

59 self.assertTrue(not missing_downgrade, helpful_msg)