def test_off(self): self._subject.off(sleep=0) assert_that( self._subject._connector.mock_calls, equal_to([ call.send(_FUJITSU_OFF), call.send(_FUJITSU_OFF), ]))
def test_off(self): self._subject.off(sleep=0) assert_that( self._subject._connector.mock_calls, equal_to([ call.send('1:1,0,37000,1,1,0'), call.send('1:1,0,37000,1,1,0'), ]))
def test(self): message1, message2, message3 = MagicMock(), MagicMock(), MagicMock() self.ws_message_producer._send_queue.append(message1) self.ws_message_producer._send_queue.append(message2) self.ws_message_producer._send_queue.append(message3) self.ws_message_producer._empty_send_queue() self.assertListEqual( [call.send(message1), call.send(message2), call.send(message3)], self.ws_message_producer.ws.mock_calls) self.assertFalse(self.ws_message_producer._send_queue)
def testReceiveInit(self): self._handle_data( '''500 connection info: protocol version: 1234 model: Test HyperDeck ''' ) self.assertEqual('1234', self.deck._state['connection']['protocol version']) self.assertEqual('Test HyperDeck', self.deck._state['connection']['model']) self.assertEqual( [call.send('transport info\r\n'), call.send('slot info\r\n'), call.send('notify: transport: true slot: true\r\n')], self.deck.socket.method_calls )
def test_default_tag(self, record): handler = pyfluent.logging.SafeFluentHandler(tag='pyfluent') handler.fluent = MagicMock(spec=handler.fluent.__class__) handler.emit(record) assert handler.fluent.method_calls == [ call.send('message 1', 'pyfluent.info', record.created) ]
def test_with_formatter(self, handler, record): fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' fmt = logging.Formatter(fmt, '%Y-%m-%d %H:%M:%S') handler.setFormatter(fmt) handler.emit(record) message = '2012-02-22 18:49:40 - root - INFO - message 1' assert handler.fluent.method_calls == [ call.send(message, 'info', record.created) ]
def test_fail(self): message1, message2, message3 = MagicMock(), MagicMock(), MagicMock() self.ws_message_producer._send_queue.append(message1) self.ws_message_producer._send_queue.append(message2) self.ws_message_producer._send_queue.append(message3) self.ws_message_producer.ws.send.side_effect = [ None, MockException(), None ] with self.assertRaises(MockException): self.ws_message_producer._empty_send_queue() self.assertListEqual([ call.send(message1), call.send(message2), ], self.ws_message_producer.ws.mock_calls) self.assertListEqual([ message2, message3, ], list(self.ws_message_producer._send_queue))
def test_call(self): self._subject._sock.recv.return_value = _TEST_SENDIR_RESPONSE assert_that(self._subject.call(_TEST_SENDIR_REQUEST), equal_to(_TEST_SENDIR_RESPONSE.decode())) assert_that( self._subject._sock.mock_calls, equal_to([ call.send(b'sendir,1:1,0,36000,1,1,32,32,64,32,32,64,32,3264'), call.recv(1024) ]))
def test_add_gce(self): env = 'google' creds = dummy_loaded['credentials'][env] with patch('pexpect.spawn', autospec=True) as mock_assess: with patch('assess_add_credentials.end_session', return_value=None): add_gce(mock_assess, env, creds) self.assertEqual([ call.expect('Enter credential name:'), call.sendline('google'), call.expect('Select auth-type:'), call.sendline('oauth2'), call.expect('Enter client-id:'), call.sendline('foo.apps.googleusercontent.com'), call.expect('Enter client-email:'), call.sendline('*****@*****.**'), call.expect('Enter private-key:'), call.send('-----BEGIN PRIVATE KEY-----\n' 'somekeyfoo\n-----END PRIVATE KEY-----\n'), call.sendline(''), call.expect('Enter project-id:'), call.sendline('gothic-list-89514') ], mock_assess.mock_calls)
def test__send__FullMessages(sock_mock): # The test assume that the socket is always correctly connected when # fileno is queried sock_mock().fileno.return_value = 11 message = 'ACommandWithParameters:#P1#P2;' msg_reply = 'ACommandWithParameters:done;' sock_mock().send.return_value = len(message) sock_mock().recv.return_value = msg_reply.encode() sock_conn = SocketConnector(host='127.0.0.3', port=10006) reply = sock_conn.__send__(message) assert reply == msg_reply sock_calls = [ call.connect(('127.0.0.3', 10006)), call.send(message.encode()), # call.shutdown(socket.SHUT_WR), call.recv(1024), call.fileno(), # This from is_connected() call.close() ] sock_mock().assert_has_calls(sock_calls)
def test_send(self, postman, enclosure): r = postman.send(enclosure) assert call.send(enclosure) in postman.session.mock_calls assert r.ok assert not r.rejected
def test_normal(self, handler, record): handler.emit(record) assert handler.fluent.method_calls == [ call.send('message 1', 'info', record.created) ]
def test_startshell_run(self, mock_wait): self.shell._chan = MagicMock() mock_wait.return_value = ["user % "] self.shell.run("ls") self.assertTrue(call.send("echo $?") in self.shell._chan.mock_calls)
def test_fetch_weather_data(self, retrieve_function): p1 = Mock() with patch('weathervane.datasources.BuienradarParser.parse', return_value='') as parser: fetch_weather_data(p1, 0) p1.assert_has_calls([call.send(''), call.close()])
def test_startshell_run(self, mock_wait): self.shell._chan = MagicMock() mock_wait.return_value = ["user % "] self.shell.run('ls') self.assertTrue(call.send('echo $?') in self.shell._chan.mock_calls)
def test_startshell_run(self, mock_wait): self.shell._chan = MagicMock() self.shell.run('ls') self.assertTrue(call.send('echo $?') in self.shell._chan.mock_calls)