def test_sync_and_state_dict(self): """ Unit test for sync and state_dict methods of NetworkXML class. Traverse all possible state and call sync using the state. """ # Test sync without state option test_xml = NetworkXML(network_name='unittest', virsh_instance=self.bogus_virsh) test_xml.sync() new_state = test_xml.state_dict() state = {'active': True, 'persistent': True, 'autostart': True} self.assertEqual(state, new_state) for values in itertools.product([True, False], repeat=3): # Change network to all possible states. keys = ['active', 'persistent', 'autostart'] state = dict(zip(keys, values)) test_xml.sync(state=state) # Check result's validity. new_state = test_xml.state_dict() # Transient network can't set autostart if state == { 'active': True, 'persistent': False, 'autostart': True }: state = { 'active': True, 'persistent': False, 'autostart': False } # Non-exist network should return None when retieving state. if not state['active'] and not state['persistent']: assert new_state is None else: self.assertEqual(state, new_state)
def test_sync_and_state_dict(self): """ Unit test for sync and state_dict methods of NetworkXML class. Traverse all possible state and call sync using the state. """ # Test sync without state option test_xml = NetworkXML(network_name='unittest', virsh_instance=self.bogus_virsh) test_xml.sync() new_state = test_xml.state_dict() state = {'active': True, 'persistent': True, 'autostart': True} self.assertEqual(state, new_state) for values in itertools.product([True, False], repeat=3): # Change network to all possible states. keys = ['active', 'persistent', 'autostart'] state = dict(zip(keys, values)) test_xml.sync(state=state) # Check result's validity. new_state = test_xml.state_dict() # Transient network can't set autostart if state == {'active': True, 'persistent': False, 'autostart': True}: state = {'active': True, 'persistent': False, 'autostart': False} # Non-exist network should return None when retieving state. if not state['active'] and not state['persistent']: assert new_state is None else: self.assertEqual(state, new_state)
def multiletters(): """Generator of count-by-letter strings""" for num in itertools.count(1): for prod in itertools.product(ascii_lowercase, repeat=num): yield ''.join(prod)