def test_netlink_read_timeout(self, m_select, m_socket): """read_netlink_socket should timeout if nothing to read""" m_select.return_value = [], None, None data = read_netlink_socket(m_socket, 1) m_select.assert_called_with([m_socket], [], [], 1) self.assertEqual(m_socket.recv.call_count, 0) self.assertIsNone(data)
def test_netlink_read_timeout(self, m_select, m_socket): '''read_netlink_socket should timeout if nothing to read''' m_select.return_value = [], None, None data = read_netlink_socket(m_socket, 1) m_select.assert_called_with([m_socket], [], [], 1) self.assertEqual(m_socket.recv.call_count, 0) self.assertIsNone(data)
def test_read_netlink_socket(self, m_select, m_socket): """read_netlink_socket able to receive data""" data = "netlinktest" m_select.return_value = [m_socket], None, None m_socket.recv.return_value = data recv_data = read_netlink_socket(m_socket, 2) m_select.assert_called_with([m_socket], [], [], 2) m_socket.recv.assert_called_with(MAX_SIZE) self.assertIsNotNone(recv_data) self.assertEqual(recv_data, data)
def test_read_netlink_socket(self, m_select, m_socket): '''read_netlink_socket able to receive data''' data = 'netlinktest' m_select.return_value = [m_socket], None, None m_socket.recv.return_value = data recv_data = read_netlink_socket(m_socket, 2) m_select.assert_called_with([m_socket], [], [], 2) m_socket.recv.assert_called_with(MAX_SIZE) self.assertIsNotNone(recv_data) self.assertEqual(recv_data, data)
def test_read_invalid_socket(self): """read_netlink_socket raises assert error if socket is invalid""" socket = None with self.assertRaises(AssertionError) as context: read_netlink_socket(socket, 1) self.assertTrue("netlink socket is none" in str(context.exception))
def test_read_invalid_socket(self): '''read_netlink_socket raises assert error if socket is invalid''' socket = None with self.assertRaises(AssertionError) as context: read_netlink_socket(socket, 1) self.assertTrue('netlink socket is none' in str(context.exception))