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 files.sort() 45 skip = ['__init__.py'] 46 for file in files: 47 # The full path. 48 path = status.install_path + sep + self.package_name + sep + file 49 50 # Files and directories to skip. 51 if file in skip: 52 continue 53 54 # Skip hidden files and directories. 55 if search("^\.", file): 56 continue 57 58 # Skip the Python 3 '__pycache__' directories. 59 if file == '__pycache__': 60 continue 61 62 # Only check Python files and directories. 63 if not search("\.py$", file) and not isdir(path): 64 continue 65 66 # Skip blacklisted files. 67 if hasattr(self, 'blacklist') and file in self.blacklist: 68 continue 69 70 # Remove the extension if needed. 71 module = file 72 if search('.py$', module): 73 module = module[:-3] 74 if search('.so$', module): 75 module = module[:-3] 76 if search('.pyd$', module): 77 module = module[:-4] 78 79 # Printout. 80 print(" Module/package: %s" % module) 81 82 # Check if the module is in __all__. 83 self.assert_(module in self.package.__all__) 84 85 # Check for modules/packages in the __all__ list which do not exist. 86 print("\nChecking for modules/packages in the __all__ list which do not exist.") 87 for module in self.package.__all__: 88 # Printout. 89 print(" Module/package: %s" % module) 90 91 # Check for the module. 92 if access(self.package_path+sep+module+'.py', F_OK): 93 continue 94 95 # Check for the C module. 96 if access(self.package_path+sep+module+'.so', F_OK): 97 continue 98 if access(self.package_path+sep+module+'.pyd', F_OK): 99 continue 100 101 # Check for the package. 102 if access(self.package_path+sep+module, F_OK): 103 continue 104 105 # Blacklisted files. 106 if hasattr(self, 'blacklist') and (module+'.py' in self.blacklist or module+'.so' in self.blacklist): 107 continue 108 109 # Doesn't exist, so fail. 110 self.fail()
111