MCPcopy Create free account
hub / github.com/KratosMultiphysics/Kratos / _RunTest

Method _RunTest

kratos/python_scripts/testing/utilities.py:132–170  ·  view source on GitHub ↗
(self, test_suit_name, command, timer, working_dir=os.getcwd())

Source from the content-addressed store, hash-verified

130 return application.replace("MPI","")[6:-8] + "Application"
131
132 def _RunTest(self, test_suit_name, command, timer, working_dir=os.getcwd()):
133 # Print test header
134 PrintTestHeader(test_suit_name)
135
136 try:
137 self.process = subprocess.Popen(command, cwd=working_dir, stdout=subprocess.PIPE)
138 except OSError:
139 print(f'[Error]: Unable to execute "{command}"', file=sys.stderr)
140 self.exitCodes[test_suit_name] = 1
141 except ValueError:
142 # Command does exist, but the arguments are invalid (It sohuld never enter here. Just to be safe)
143 print(f'[Error]: Invalid arguments when calling "{command}"', file=sys.stderr)
144 self.exitCodes[test_suit_name] = 1
145 else:
146 # Used instead of wait to "soft-block" the process and prevent deadlocks
147 # and capture the first exit code different from OK
148 try:
149 # Pipe the output of the process until the timer is reached
150 process_stdout, process_stderr = self.process.communicate(timeout=timer)
151
152 # Capture the result of the process
153 self.exitCodes[test_suit_name] = int(self.process.returncode != 0)
154 except subprocess.TimeoutExpired:
155 # Timeout reached
156 self.process.kill()
157 print(f'[Error]: Tests for {test_suit_name} took too long. Process Killed.', file=sys.stderr)
158 self.exitCodes[test_suit_name] = 1
159 except Exception as e:
160 # Unknown error
161 print(f"[Error]: Unhandled exception while running {test_suit_name} tests: {e}", file=sys.stderr)
162 self.exitCodes[test_suit_name] = 1
163 finally:
164 if process_stdout:
165 self.PrintOutput(process_stdout, sys.stderr)
166 if process_stderr:
167 self.PrintOutput(process_stderr, sys.stderr)
168
169 # Exit message
170 PrintTestFooter(test_suit_name, self.process.returncode)
171
172 def RunPythonTests(self, applications, level, verbose, command, timer):
173 ''' Calls the script that will run the tests.

Callers 4

RunPythonTestsMethod · 0.95
RunCppTestsMethod · 0.95
RunMPIPythonTestsMethod · 0.95
RunMPICppTestsMethod · 0.95

Calls 5

PrintOutputMethod · 0.95
PrintTestHeaderFunction · 0.85
PrintTestFooterFunction · 0.85
killMethod · 0.80
printFunction · 0.50

Tested by

no test coverage detected