def test_get_context(self, get_context): self.port = PORT return_value = {"test_successful":"Yep"} get_context.return_value = return_value get_context.__name__ = "get_context" self.server = server_x11.setup_server(HOST, self.port) test_thread = threading.Thread(target=self.get_context, args=[return_value]) test_thread.start() self.server.serve_forever() test_thread.join() get_context.assert_called_with()
def test_get_context(self, get_context): self.port = PORT return_value = {'test_successful': 'Yep'} get_context.return_value = return_value get_context.__name__ = 'get_context' self.server = server_x11.setup_server(HOST, self.port) test_thread = threading.Thread( target=self.get_context, args=[return_value] ) test_thread.start() self.server.serve_forever() test_thread.join() get_context.assert_called_with()
def test_multiple_actions(self, run_command, flush, write_command): calls = [] def mock_flush(actions): '''Mock has issues with the del [:].''' if actions: calls.append(actions[:]) del actions[:] flush.side_effect = mock_flush self.port = PORT + 7 self.server = server_x11.setup_server(HOST, self.port) test_thread = threading.Thread(target=self.multiple_actions) test_thread.start() self.server.serve_forever() test_thread.join() # No easy way to test interleaving, so we rely on shape of flushes # to check proper happens-before. self.assertEqual( write_command.mock_calls, [mock.call( 'Hello world!', arguments='type --file - --delay 0' )] * 2 ) step1 = [ 'key a', 'keydown Shift_L', 'key a', 'keyup Shift_L', 'keydown Shift_L', 'key b', 'key b', 'key b', 'keyup Shift_L' ] step2 = [ 'click --repeat 2 1', 'click --repeat 2 4', 'click 3', 'click --delay 70 --repeat 5 3', 'click 2', 'sleep 0.500000' ] self.assertEqual(calls, [step1, step2, step1 + step2])
def run_request_thread(self, client): self.server = server_x11.setup_server(HOST, self.port) test_thread = threading.Thread(target=client) test_thread.start() self.server.serve_forever() test_thread.join()