Package test_suite :: Package unit_tests :: Module package_checking
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests.package_checking

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2009-2013 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Python module imports. 
23  from os import F_OK, access, listdir, sep 
24  from os.path import isdir 
25  from re import search 
26   
27  # relax module imports. 
28  from status import Status; status = Status() 
29  from test_suite.unit_tests.base_classes import UnitTestCase 
30   
31   
32 -class PackageTestCase(UnitTestCase):
33 """Base class for the unit tests of the relax packages.""" 34
35 - def test___all__(self):
36 """Check if all modules are located within the __all__ list.""" 37 38 # Initial printout. 39 print("The %s.__all__ list: %s" % (self.package_name, self.package.__all__)) 40 41 # Check for modules/packages missing from the __all__ list. 42 print("\nChecking for modules/packages missing from the __all__ list.") 43 files = listdir(self.package_path) 44 skip = ['__init__.py'] 45 for file in files: 46 # The full path. 47 path = status.install_path + sep + self.package_name + sep + file 48 49 # Files and directories to skip. 50 if file in skip: 51 continue 52 53 # Skip hidden files and directories. 54 if search("^\.", file): 55 continue 56 57 # Skip the Python 3 '__pycache__' directories. 58 if file == '__pycache__': 59 continue 60 61 # Only check Python files and directories. 62 if not search("\.py$", file) and not isdir(path): 63 continue 64 65 # Skip blacklisted files. 66 if hasattr(self, 'blacklist') and file in self.blacklist: 67 continue 68 69 # Remove the extension if needed. 70 module = file 71 if search('.py$', module): 72 module = module[:-3] 73 if search('.so$', module): 74 module = module[:-3] 75 76 # Printout. 77 print(" Module/package: %s" % module) 78 79 # Check if the module is in __all__. 80 self.assert_(module in self.package.__all__) 81 82 # Check for modules/packages in the __all__ list which do not exist. 83 print("\nChecking for modules/packages in the __all__ list which do not exist.") 84 for module in self.package.__all__: 85 # Printout. 86 print(" Module/package: %s" % module) 87 88 # Check for the module. 89 if access(self.package_path+sep+module+'.py', F_OK): 90 continue 91 92 # Check for the package. 93 if access(self.package_path+sep+module, F_OK): 94 continue 95 96 # Doesn't exist, so fail. 97 self.fail()
98