Package test_suite :: Module relax_test_loader
[hide private]
[frames] | no frames]

Source Code for Module test_suite.relax_test_loader

 1  ################################################################################ 
 2  #                                                                              # 
 3  # Copyright (C) 2011,2019 Edward d'Auvergne                                    # 
 4  #                                                                              # 
 5  # This file is part of the program relax.                                      # 
 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 relax; if not, write to the Free Software                         # 
19  #                                                                              # 
20  ################################################################################ 
21   
22  # Module docstring. 
23  """Replacement unittest.TestLoader class. 
24   
25  This is to handle skipping of tests when Python modules are not installed. 
26  """ 
27   
28  # Python module imports 
29  from unittest import TestLoader, TestSuite 
30   
31  # relax module imports. 
32  from status import Status; status = Status() 
33   
34   
35 -class RelaxTestLoader(TestLoader):
36 """Replacement TestLoader class.""" 37
38 - def loadTestsFromNames(self, names, module=None):
39 """Replacement method for handling skipped tests.""" 40 41 # Get the test names. 42 testCaseNames = self.getTestCaseNames(module) 43 44 # Generate a list of test cases. 45 case_list = [] 46 for name in names: 47 # Initialise the test case. 48 test_case = module(name) 49 50 # Skip. 51 if status.skip_blacklisted_tests and status.skipped_tests and name in list(zip(*status.skipped_tests))[0]: 52 continue 53 54 # Append the test case. 55 case_list.append(test_case) 56 57 # Return the test suite. 58 return self.suiteClass(case_list)
59 60
61 - def loadTestsFromTestCase(self, testCaseClass):
62 """Replacement method for skipping tests.""" 63 64 # A check from the original function. 65 if issubclass(testCaseClass, TestSuite): 66 raise TypeError("Test cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?") 67 68 # Get the test names. 69 testCaseNames = self.getTestCaseNames(testCaseClass) 70 71 # Again from the original function. 72 if not testCaseNames and hasattr(testCaseClass, 'runTest'): 73 testCaseNames = ['runTest'] 74 75 # Generate a list of test cases. 76 case_list = [] 77 for i in range(len(testCaseNames)): 78 # Initialise the test case. 79 test_case = testCaseClass(testCaseNames[i]) 80 81 # Skip. 82 if status.skip_blacklisted_tests and status.skipped_tests and testCaseNames[i] in list(zip(*status.skipped_tests))[0]: 83 continue 84 85 # Append the test case. 86 case_list.append(test_case) 87 88 # Return the test suite. 89 return self.suiteClass(case_list)
90