Skip to content

Instantly share code, notes, and snippets.

@skamithi
Created July 17, 2014 18:19
Show Gist options
  • Save skamithi/0495439cb375b03e9789 to your computer and use it in GitHub Desktop.
Save skamithi/0495439cb375b03e9789 to your computer and use it in GitHub Desktop.
Python - Mock some of the functions in a class while keep the rest the same
@mock.patch('clshow.cliface.CumulusIface.print_name')
@mock.patch('clshow.cliface.CumulusIface.print_ip_details')
@mock.patch('clshow.cliface.CumulusIface.print_counters')
@mock.patch('clshow.cliface.CumulusIface.print_lldp_info')
@mock.patch('clshow.cliface.CumulusIface.print_arp')
def test_print_l3_access(self,
mock_arp,
mock_lldp,
mock_counters,
mock_ip,
mock_name):
"""
cliface test printint out l3 access ports details
"""
manager = mock.Mock()
manager.attach_mock(mock_name, 'print_name')
manager.attach_mock(mock_ip, 'print_ip_details')
manager.attach_mock(mock_counters, 'print_counters')
manager.attach_mock(mock_lldp, 'print_lldp_info')
manager.attach_mock(mock_arp, 'print_arp')
self.iface.print_l3_access_details()
expected_calls = [mock.call.print_name(),
mock.call.print_ip_details(),
mock.call.print_counters(),
mock.call.print_lldp_info(),
mock.call.print_arp()]
assert_equals(manager.method_calls, expected_calls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment