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-2012 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax 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 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax 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 relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Python module imports. 
24  from os import F_OK, access, listdir, sep 
25  from re import search 
26   
27  # relax module imports. 
28  from test_suite.unit_tests.base_classes import UnitTestCase 
29   
30   
31 -class PackageTestCase(UnitTestCase):
32 """Base class for the unit tests of the relax packages.""" 33
34 - def test___all__(self):
35 """Check if all modules are located within the __all__ list.""" 36 37 print(("The %s.__all__ list: %s" % (self.package_name, self.package.__all__))) 38 39 # Loop over all files. 40 files = listdir(self.package_path) 41 for file in files: 42 # Only look at the '*.py' files. 43 if not search('.py$', file): 44 continue 45 46 # Skip the __init__.py file. 47 if file == '__init__.py': 48 continue 49 50 # Skip blacklisted files. 51 if hasattr(self, 'blacklist') and file in self.blacklist: 52 continue 53 54 # Remove the '.py' part. 55 module = file[:-3] 56 57 # Print out. 58 print(("\nFile: %s" % file)) 59 print(("Checking module: %s" % module)) 60 61 # Check if the module is in __all__. 62 self.assert_(module in self.package.__all__) 63 64 # Loop over all modules. 65 for module in self.package.__all__: 66 # The file name. 67 file = module + '.py' 68 69 # Print out. 70 print(("\nModule: %s" % module)) 71 print(("Checking file: %s" % file)) 72 73 # Check for the file. 74 if access(self.package_path + sep + file, F_OK): 75 continue 76 77 # Check for the package. 78 if access(self.package_path + sep + module, F_OK): 79 continue 80 81 # Doesn't exist, so fail. 82 self.fail()
83