MCPcopy Index your code
hub / github.com/nodejs/node / _MockCommand

Method _MockCommand

deps/v8/tools/unittests/run_perf_test.py:166–213  ·  view source on GitHub ↗
(self, raw_dirs, raw_outputs, *args, **kwargs)

Source from the content-addressed store, hash-verified

164 f.write(json.dumps(json_content))
165
166 def _MockCommand(self, raw_dirs, raw_outputs, *args, **kwargs):
167 on_bots = kwargs.pop('on_bots', False)
168 # Fake output for each test run.
169 test_outputs = [
170 Output(
171 stdout=output,
172 timed_out=kwargs.get('timed_out', False),
173 exit_code=kwargs.get('exit_code', 0),
174 start_time=0,
175 end_time=42) for output in raw_outputs
176 ]
177
178 def create_cmd(*args, **kwargs):
179 cmd = mock.MagicMock()
180 def execute(*args, **kwargs):
181 return test_outputs.pop()
182 cmd.execute = mock.MagicMock(side_effect=execute)
183 return cmd
184
185 mock.patch.object(
186 run_perf.command, 'PosixCommand',
187 mock.MagicMock(side_effect=create_cmd)).start()
188
189 build_dir = 'Release' if on_bots else 'x64.release'
190 out_dirs = ['out', 'out-secondary']
191 return_values = [
192 os.path.join(os.path.dirname(TOOLS_ROOT), out, build_dir)
193 for out in out_dirs
194 ]
195 mock.patch.object(
196 run_perf, 'find_build_directory',
197 mock.MagicMock(side_effect=return_values)).start()
198
199 # Check that d8 is called from the correct cwd for each test run.
200 dirs = [os.path.join(TEST_WORKSPACE, dir) for dir in raw_dirs]
201
202 def chdir(dir, *args, **kwargs):
203 if not dirs:
204 raise Exception("Missing test chdir '%s'" % dir)
205 expected_dir = dirs.pop()
206 self.assertEqual(
207 expected_dir, dir,
208 "Unexpected chdir: expected='%s' got='%s'" % (expected_dir, dir))
209
210 os.chdir = mock.MagicMock(side_effect=chdir)
211
212 subprocess.check_call = mock.MagicMock()
213 platform.system = mock.MagicMock(return_value='Linux')
214
215 def _CallMain(self, *args):
216 self._test_output = os.path.join(TEST_WORKSPACE, 'results.json')

Callers 15

testOneRunMethod · 0.95
testWarmup_OnEmptyMethod · 0.95
testWarmup_NotNeededMethod · 0.95
testWarmup_NeededMethod · 0.95
testOneRunVariantsMethod · 0.95
testTwoRuns_SubRegexpMethod · 0.95
testNestedSuiteMethod · 0.95

Calls 5

OutputClass · 0.90
popMethod · 0.80
getMethod · 0.65
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected