Lines Matching refs:mock
11 import mock
43 instance = mock.Mock()
45 testsuite = mock.Mock()
46 type(testsuite).source_dir = mock.PropertyMock(return_value='')
51 type(instance).build_dir = mock.PropertyMock(return_value=str(build_dir))
53 platform = mock.Mock()
54 type(platform).binaries = mock.PropertyMock(return_value=[])
57 type(instance.testsuite).timeout = mock.PropertyMock(return_value=60)
58 type(instance.platform).timeout_multiplier = mock.PropertyMock(
116 with mock.patch('os.name', os_name), \
117 mock.patch.dict('sys.modules', modules_mock, clear=True), \
118 mock.patch('sys.meta_path', meta_path_mock), \
128 instance.testcases = [mock.Mock()]
130 handler = Handler(mocked_instance, 'build', mock.Mock())
135 harness.detected_suite_names = mock.Mock()
138 harness.recording = mock.Mock()
140 handler_time = mock.Mock()
153 instance.assert_has_calls([mock.call.record(harness.recording)])
179 handler_time = mock.Mock()
181 with mock.patch.object(Handler, '_missing_suite_name') as _missing_mocked:
182 handler = Handler(instance, 'build', mock.Mock())
197 instance.testcases = [mock.Mock()]
199 handler = Handler(mocked_instance, 'build', mock.Mock())
204 handler_time = mock.Mock()
223 handler = Handler(instance, 'build', mock.Mock())
225 mock_process = mock.Mock()
226 mock_child1 = mock.Mock(pid=1)
227 mock_child2 = mock.Mock(pid=2)
228 mock_process.children = mock.Mock(return_value=[mock_child1, mock_child2])
230 mock_proc = mock.Mock(pid=0)
231 mock_proc.terminate = mock.Mock(return_value=None)
232 mock_proc.kill = mock.Mock(return_value=None)
234 with mock.patch('psutil.Process', return_value=mock_process), \
235 mock.patch(
237 mock.Mock(side_effect=mock_kill_function)
245 [mock.call(1, signal.SIGTERM), mock.call(2, signal.SIGTERM)]
248 mock_child_neg1 = mock.Mock(pid=-1)
249 mock_process.children = mock.Mock(
258 [mock.call(-1, signal.SIGTERM), mock.call(2, signal.SIGTERM)]
269 handler = BinaryHandler(instance, 'build', mock.Mock())
272 with mock.patch(
274 mock.Mock(side_effect=mock_kill_function)
276 mock.patch('os.unlink', mock.Mock()) as mock_unlink:
277 with mock.patch('builtins.open', mock.mock_open(read_data='1')):
289 with mock.patch('builtins.open', mock.mock_open(read_data='-1')):
301 mock.Mock(status=TwisterStatus.NONE, capture_coverage=False),
303 mock.call('This\\r\\n\n'),
304 mock.call('is\r'),
305 mock.call('some ANSI in\n'),
306 mock.call('a short\n'),
307 mock.call('file.')
310 mock.call('This'),
311 mock.call('is'),
312 mock.call('some \x1B[31mANSI\x1B[39m in'),
313 mock.call('a short'),
314 mock.call('file.')
321 mock.Mock(status=TwisterStatus.PASS, capture_coverage=False),
329 mock.Mock(status=TwisterStatus.PASS, capture_coverage=False),
337 mock.Mock(status=TwisterStatus.PASS, capture_coverage=True),
366 class MockStdout(mock.Mock):
381 class MockProc(mock.Mock):
384 self.pid = mock.PropertyMock(return_value=pid)
391 handler = BinaryHandler(mocked_instance, 'build', mock.Mock(timeout_multiplier=1))
392 handler.terminate = mock.Mock()
396 with mock.patch(
398 mock.mock_open(read_data='')
400 mock.patch('time.time', side_effect=faux_timer.time):
481 handler = BinaryHandler(mocked_instance, 'build', mock.Mock(
493 with mock.patch('os.environ', env):
535 handler = BinaryHandler(mocked_instance, 'build', mock.Mock(
541 missing_mock = mock.Mock()
543 mocked_harness = mock.Mock(status=harness_status, reason="foobar")
574 thread_mock_obj = mock.Mock()
577 return mock.Mock(
578 __enter__=mock.Mock(return_value=mock.Mock(pid=0, returncode=0)),
579 __exit__=mock.Mock(return_value=None)
585 handler = BinaryHandler(mocked_instance, 'build', mock.Mock(coverage=coverage))
589 handler._create_command = mock.Mock(return_value=['dummy' , 'command'])
590 handler._create_env = mock.Mock(return_value=[])
591 handler._update_instance_info = mock.Mock()
592 handler._final_handle_actions = mock.Mock()
593 handler.terminate = mock.Mock()
594 handler.try_kill_process_by_pid = mock.Mock()
596 robot_mock = mock.Mock()
597 harness = mock.Mock(is_robot_test=is_robot_test, run_robot_test=robot_mock)
599 popen_mock = mock.Mock(side_effect=mock_popen)
600 thread_mock = mock.Mock(side_effect=mock_thread)
601 call_mock = mock.Mock()
603 with mock.patch('subprocess.call', call_mock), \
604 mock.patch('subprocess.Popen', popen_mock), \
605 mock.patch('threading.Thread', thread_mock), \
606 mock.patch('sys.stdout.isatty', return_value=isatty):
610 robot_mock.assert_called_once_with(['dummy', 'command'], mock.ANY)
620 call_mock.assert_any_call(['stty', 'sane'], stdin=mock.ANY)
642 handler = SimulationHandler(mocked_instance, type_str, mock.Mock())
706 halt_event = mock.Mock(is_set=mock.Mock(side_effect=is_set_iter))
707 ser = mock.Mock(
708 isOpen=mock.Mock(side_effect=is_open_iter),
709 readline=mock.Mock(side_effect=line_iter)
711 type(ser).in_waiting = mock.PropertyMock(
715 harness = mock.Mock(capture_coverage=False)
716 type(harness).status=mock.PropertyMock(side_effect=status_iter)
718 handler = DeviceHandler(mocked_instance, 'build', mock.Mock(enable_coverage=not end_by_status))
720 with mock.patch('builtins.open', mock.mock_open(read_data='')):
729 [mock.call(f'line no {idx}') for idx in range(expected_line_count)]
734 halt_event = mock.Mock(is_set=mock.Mock(return_value=False))
735 ser = mock.Mock(
736 isOpen=mock.Mock(side_effect=[True, True, False]),
737 in_waiting=mock.Mock(return_value=False),
738 readline=mock.Mock(return_value='\nline1\nline2\n'.encode('utf-8'))
740 harness = mock.Mock(status=TwisterStatus.PASS)
742 handler = DeviceHandler(mocked_instance, 'build', mock.Mock(enable_coverage=False))
744 with mock.patch('builtins.open', mock.mock_open(read_data='')):
755 mock.Mock(
760 counter_increment=mock.Mock(),
763 mock.Mock(
768 counter_increment=mock.Mock(),
771 mock.Mock(
778 counter_increment=mock.Mock(),
781 mock.Mock(
784 serial_pty=mock.Mock(),
787 counter_increment=mock.Mock(),
790 mock.Mock(
793 serial_pty=mock.Mock(),
796 counter_increment=mock.Mock(),
806 mock.Mock(
811 counter_increment=mock.Mock(),
814 mock.Mock(
819 counter_increment=mock.Mock(),
822 mock.Mock(
829 counter_increment=mock.Mock(),
832 mock.Mock(
835 serial_pty=mock.Mock(),
838 counter_increment=mock.Mock(),
841 mock.Mock(
844 serial_pty=mock.Mock(),
847 counter_increment=mock.Mock(),
863 mock.Mock(
866 serial_pty=mock.Mock(),
867 counter_increment=mock.Mock(),
871 mock.Mock(
874 serial_pty=mock.Mock(),
875 counter_increment=mock.Mock(),
879 mock.Mock(
882 serial=mock.Mock(),
883 counter_increment=mock.Mock(),
887 mock.Mock(
890 serial=mock.Mock(),
891 counter_increment=mock.Mock(),
917 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
938 serial = mock.Mock(name='dummy_serial')
940 mock.Mock(available=0, serial=serial, serial_pty=None),
941 mock.Mock(available=0, serial=None, serial_pty=serial),
942 mock.Mock(
944 serial=mock.Mock('another_serial'),
949 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
965 (mock.Mock(pid=0, returncode=0), False),
966 (mock.Mock(pid=0, returncode=1), False),
967 (mock.Mock(pid=0, returncode=1), True)
980 return mock.Mock(), mock.Mock()
983 return mock.Mock(
984 __enter__=mock.Mock(return_value=mock_process),
985 __exit__=mock.Mock(return_value=None)
988 mock_process.communicate = mock.Mock(side_effect=raise_timeout_fn)
993 with mock.patch('subprocess.Popen', side_effect=assert_popen):
1002 mock.call.communicate(timeout=timeout),
1003 mock.call.kill(),
1004 mock.call.communicate()
1031 expected_hardware = mock.Mock()
1041 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
1044 with mock.patch.object(
1172 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
1173 handler.options = mock.Mock(west_flash=self_west_flash)
1179 hardware = mock.Mock(
1213 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
1215 missing_mock = mock.Mock()
1217 mocked_harness = mock.Mock(status=harness_status, reason="foobar")
1235 mock.Mock(communicate=mock.Mock(return_value=('', ''))),
1273 handler = DeviceHandler(mocked_instance, 'build', mock.Mock(timeout_multiplier=1))
1274 missing_mock = mock.Mock()
1276 twisterlib.handlers.terminate_process = mock.Mock()
1285 serial_mock = mock.Mock(side_effect=mock_serial)
1287 with mock.patch('serial.Serial', serial_mock), \
1331 return mock.Mock()
1333 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
1336 popen_mock = mock.Mock(side_effect=mock_popen)
1337 openpty_mock = mock.Mock(return_value=('master', 'slave'))
1338 ttyname_mock = mock.Mock(side_effect=lambda x: x + ' name')
1340 with mock.patch('subprocess.Popen', popen_mock), \
1341 mock.patch('pty.openpty', openpty_mock), \
1342 mock.patch('os.ttyname', ttyname_mock):
1392 serial_pty_process = mock.Mock(
1394 communicate=mock.Mock(
1404 return mock.Mock(name='dummy serial')
1407 is_alive_mock = mock.Mock(return_value=bool(do_timeout_thread))
1409 return mock.Mock(is_alive=is_alive_mock)
1412 proc.communicate = mock.Mock(return_value=(mock.Mock(), mock.Mock()))
1417 return mock.Mock(), mock.Mock()
1423 mock_process = mock.Mock(
1426 communicate=mock.Mock(side_effect=mock_communicate)
1429 return mock.Mock(
1430 __enter__=mock.Mock(return_value=mock_process),
1431 __exit__=mock.Mock(return_value=None)
1434 hardware = None if not has_hardware else mock.Mock(
1446 handler = DeviceHandler(mocked_instance, 'build', mock.Mock())
1447 handler.get_hardware = mock.Mock(return_value=hardware)
1448 handler.options = mock.Mock(
1453 handler._get_serial_device = mock.Mock(side_effect=mock_get_serial)
1454 handler._create_command = mock.Mock(return_value=['dummy', 'command'])
1455 handler.run_custom_script = mock.Mock()
1456 handler._create_serial_connection = mock.Mock(
1459 handler.monitor_serial = mock.Mock()
1460 handler.terminate = mock.Mock(side_effect=mock_terminate)
1461 handler._update_instance_info = mock.Mock()
1462 handler._final_handle_actions = mock.Mock()
1463 handler.make_dut_available = mock.Mock()
1464 twisterlib.handlers.terminate_process = mock.Mock()
1467 harness = mock.Mock()
1469 with mock.patch('builtins.open', mock.mock_open(read_data='')), \
1470 mock.patch('subprocess.Popen', side_effect=mock_popen), \
1471 mock.patch('threading.Event', mock.Mock()), \
1472 mock.patch('threading.Thread', side_effect=mock_thread):
1484 mock.call('dummy pre script', mock.ANY)
1491 mock.call('dummy pre script', mock.ANY),
1492 mock.call('dummy post flash script', mock.ANY),
1493 mock.call('dummy post script', mock.ANY)
1522 handler = QEMUHandler(mocked_instance, 'build', mock.Mock())
1530 return mock.Mock(
1531 cpu_times=mock.Mock(
1532 return_value=mock.Mock(
1539 with mock.patch('psutil.Process', mock_process):
1549 mock.PropertyMock(return_value=os.path.join('dummy_dir', '1')),
1555 mock.PropertyMock(return_value=os.path.join('dummy_dir', '2')),
1572 get_default_domain_mock = mock.Mock()
1574 domains_mock = mock.Mock(get_default_domain=get_default_domain_mock)
1575 from_file_mock = mock.Mock(return_value=domains_mock)
1577 handler = QEMUHandler(mocked_instance, 'build', mock.Mock())
1581 with mock.patch('domains.Domains.from_file', from_file_mock):
1614 unlink_mock = mock.Mock()
1615 exists_mock = mock.Mock(return_value=exists_pid_fn)
1617 handler = QEMUHandler(mocked_instance, 'build', mock.Mock())
1621 with mock.patch('os.unlink', unlink_mock), \
1622 mock.patch('os.path.exists', exists_mock):
1640 handler = QEMUHandler(mocked_instance, 'build', mock.Mock(), 'dummy_cmd', False)
1719 mocked_instance.add_missing_case_status = mock.Mock()
1721 mocked_harness = mock.Mock(status=harness_status, reason="foobar")
1723 handler = QEMUHandler(mocked_instance, 'build', mock.Mock())
1767 handler = QEMUHandler(mocked_instance, 'build', mock.Mock())
1788 [mock.call('1\n'), mock.call('1\n')]
1799 [mock.call('1\n'), mock.call('1\n')]
1832 [mock.call('1\n'), mock.call('2\n'), mock.call('3\n'), mock.call('4\n')]
1843 [mock.call('1\n'), mock.call('2\n')]
1854 [mock.call('1\n'), mock.call('2\n'), mock.call('3\n'), mock.call('4\n')]
1891 type(mocked_instance.testsuite).timeout = mock.PropertyMock(return_value=timeout)
1892 handler = QEMUHandler(mocked_instance, 'build', mock.Mock(timeout_multiplier=1))
1907 file_object = mock.mock_open(read_data=contents).return_value
1914 harness = mock.Mock(capture_coverage=capture_coverage, handle=print)
1915 type(harness).status = mock.PropertyMock(side_effect=harness_statuses)
1917 p = mock.Mock()
1918 p.poll = mock.Mock(
1922 mock_thread_get_fifo_names = mock.Mock(
1925 mock_thread_update_instance_info = mock.Mock()
1927 with mock.patch('time.time', side_effect=faux_timer.time), \
1928 mock.patch('builtins.open', new=mocked_open), \
1929 mock.patch('select.poll', return_value=p), \
1930 mock.patch('os.path.exists', return_value=True), \
1931 mock.patch('os.unlink', mock.Mock()), \
1932 mock.patch('os.mkfifo', mock.Mock()), \
1933 mock.patch('os.kill', mock.Mock()), \
1934 mock.patch('twisterlib.handlers.QEMUHandler._get_cpu_time',
1936 mock.patch('twisterlib.handlers.QEMUHandler._thread_get_fifo_names',
1938 mock.patch('twisterlib.handlers.QEMUHandler.' \
1954 mock.ANY,
1956 mock.ANY
1989 mock_process = mock.Mock(pid=0, returncode=1)
1990 mock_process.communicate = mock.Mock(
1991 return_value=(mock.Mock(), mock.Mock())
1993 mock_process.wait = mock.Mock(side_effect=mock_wait)
1995 handler = QEMUHandler(mocked_instance, 'build', mock.Mock(timeout_multiplier=1))
2001 return mock.Mock(
2002 __enter__=mock.Mock(return_value=mock_process),
2003 __exit__=mock.Mock(return_value=None),
2004 communicate=mock.Mock(return_value=(mock.Mock(), mock.Mock()))
2008 return mock.Mock()
2015 harness = mock.Mock(status=harness_status)
2021 handler.options = mock.Mock(
2026 handler.run_custom_script = mock.Mock(return_value=None)
2027 handler.make_device_available = mock.Mock(return_value=None)
2028 handler._final_handle_actions = mock.Mock(return_value=None)
2029 handler._create_command = mock.Mock(return_value=command)
2030 handler._set_qemu_filenames = mock.Mock(side_effect=mock_filenames)
2031 handler.get_default_domain_build_dir = mock.Mock(return_value=domain_build_dir)
2032 handler.terminate = mock.Mock()
2034 unlink_mock = mock.Mock()
2036 with mock.patch('subprocess.Popen', side_effect=mock_popen), \
2037 mock.patch('builtins.open', mock.mock_open(read_data='1')), \
2038 mock.patch('threading.Thread', side_effect=mock_thread), \
2039 mock.patch('os.path.exists', side_effect=mock_path_exists), \
2040 mock.patch('os.unlink', unlink_mock), \
2041 mock.patch('sys.stdout.isatty', return_value=isatty):
2048 handler = QEMUHandler(mocked_instance, 'build', mock.Mock(timeout_multiplier=1))