def test_should_return_list_of_lists(self): """ Should return list of lists if components registered """ subject = Component() subject.register_component(Component()) self.assertEqual(req.components_of_list(subject.components), [[]])
def test_should_return_components_of_component(self): """ Should return components of component passed in """ subject = Component() subject.register_component('doo') subject.register_component('pee') self.assertEqual(req.components_of(subject)[0],'doo')
def test_get_remote_hosts_sets_hosts(self): subject = Component() nic = Component() the_object = Component() the_object.state.set_flag("IS_NETWORK_HOST") subject.register_component(nic) nic.establish_duplex(the_object) subject.execute_behavior(network.GetNetworkHosts) self.assertEqual(len(subject.state.available_hosts), 1) self.assertIn(subject.state.available_hosts, the_object)
def test_test_component_inputs_pass(self): """test_component_inputs should return True if all input requirements are met""" requirement = lambda component : 'IS_FOO' in component.state.flags subject = Component() the_input = Component() the_input.state.set_flag('IS_FOO') subject.register_component(the_input) the_input.plug_into(subject) self.assertEqual(len(subject.item_inputs()), 1) self.assertEqual(req.test_component_inputs(subject, requirement), True)
def test_test_component_inputs_failure(self): "test_component_inputs should return false if an unmet input requirement exists" the_input = Component() the_input.state.set_flag('BAR') requirement = lambda x: 'FOO' in x.state.flags subject = Component() self.assertIsInstance(the_input, Component) subject.plug_out_from(the_input) subject.register_component(the_input) self.assertFalse(req.test_component_inputs(the_input, requirement))
def test_should_return_list_of_lists_containing_components(self): """ Should return list of lists with components in them if components registered """ subject = Component() sub_subject = Component() returned_component = Component() sub_subject.register_component(returned_component) subject.register_component(sub_subject) self.assertEqual(req.components_of_list(subject.components), [[returned_component]])
def test_it_filters(self): """ It should filter out all components which do not have the specified flag """ subject = Component() subject.register_component(Component()) subject.register_component(Component()) sub_subject = Component() sub_subject.state.set_flag('HEY') subject.register_component(sub_subject) self.assertEqual(len(req.components_filtered_for_flag(subject, 'HEY')), 1)