This function should be called to initialize the testing module. The first important thing it does is to store the options for later, since the startTestThread function will need them. Then it checks the arguments that were passed into the server to see if a test was actually requ
(opts, reactor=None, cleanupMethod=None)
| 113 | # Checks whether test script supplied, if so, safely imports needed modules |
| 114 | # ============================================================================= |
| 115 | def initialize(opts, reactor=None, cleanupMethod=None): |
| 116 | """ |
| 117 | This function should be called to initialize the testing module. The first |
| 118 | important thing it does is to store the options for later, since the |
| 119 | startTestThread function will need them. Then it checks the arguments that |
| 120 | were passed into the server to see if a test was actually requested, making |
| 121 | a note of this fact. Then, if a test was required, this function then |
| 122 | checks if all the necessary testing modules were safely imported, printing |
| 123 | a warning if not. If tests were requested and all modules were present, |
| 124 | then this function sets "test_module_do_testing" to True and sets up the |
| 125 | startTestThread function to be called after the reactor is running. |
| 126 | |
| 127 | opts: Parsed arguments from the server |
| 128 | |
| 129 | reactor: This argument is optional, but is used by server.py to |
| 130 | cause the test thread to be started only after the server itself |
| 131 | has started. If it is not provided, the test thread is launched |
| 132 | immediately. |
| 133 | |
| 134 | cleanupMethod: A callback method you would like the test thread |
| 135 | to execute when the test has finished. This is used by server.py |
| 136 | as a way to have the server terminated after the test has finished, |
| 137 | but could be used for other cleanup purposes. This argument is |
| 138 | also optional. |
| 139 | """ |
| 140 | |
| 141 | global import_warning_info |
| 142 | |
| 143 | global testModuleOptions |
| 144 | testModuleOptions = Dictionary() |
| 145 | |
| 146 | # Copy the testing options into something we can easily extend |
| 147 | for arg in vars(opts): |
| 148 | optValue = getattr(opts, arg) |
| 149 | testModuleOptions[arg] = optValue |
| 150 | |
| 151 | # If we got one, add the cleanup method to the testing options |
| 152 | if cleanupMethod: |
| 153 | testModuleOptions["cleanupMethod"] = cleanupMethod |
| 154 | |
| 155 | # Check if a test was actually requested |
| 156 | if ( |
| 157 | testModuleOptions.testScriptPath != "" |
| 158 | and testModuleOptions.testScriptPath is not None |
| 159 | ): |
| 160 | # Check if we ran into trouble with any of the testing imports |
| 161 | if import_warning_info != "": |
| 162 | print("WARNING: Some tests may have unmet dependencies") |
| 163 | print(import_warning_info) |
| 164 | |
| 165 | if reactor is not None: |
| 166 | # Add startTest callback to the reactor callback queue, so that |
| 167 | # the test thread gets started after the reactor is running. Of |
| 168 | # course this should only happen if everything is good for tests. |
| 169 | reactor.callWhenRunning(_start_test_thread) |
| 170 | else: |
| 171 | # Otherwise, our aim is to start the thread from another process |
| 172 | # so just call the start method. |
no test coverage detected