def test_override(self): g = NumboGraph(Numble([4, 5, 6], 15)) glom = g.add_node(Glom, g.find_all(OfClass(Brick))) noticer = g.add_node(NoticeAllBricksAreAvail, member_of=g.ws) self.assertIn(noticer.id, g.as_nodeids(g.active_nodes())) g.do_timestep(actor=noticer) # Since the NoticeAllBricksAreAvail can't run, it should get tagged # Blocked(NeedArg('focal_point')). tag = g.as_node(g.tag_of(noticer, Blocked)) self.assertTrue( tag, "Failed to create Blocked tag for missing 'focal_point' argument.") reason = g.getattr(tag, 'reason') self.assertTrue(isinstance(reason, NeedArg)) self.assertEqual(reason.name, 'focal_point') self.assertTrue(g.is_blocked(noticer)) # Now we manually override the 'focal_point' argument. g.add_override_node(noticer, 'focal_point', glom) g.remove_tag(noticer, Blocked) g.do_timestep(actor=noticer) bricks = g.find_all(OfClass(Brick)) self.assertTrue( g.has_tag(bricks, AllBricksAvail), "Did not tag the Bricks even when 'focal_point' was overridden.")
def test_noticer(self): g = NumboGraph(Numble([4, 5, 6], 15)) noticer = g.add_node(AdHocAcNode, [ All(OfClass(Brick), focal_point=g.ws), AllAre(CTagged(Avail)), TagWith(AllBricksAvail, taggees='nodes') ], member_of=g.ws) self.assertEqual(noticer.state, Start) self.assertTrue(noticer.can_go()) self.assertIn(noticer.id, g.as_nodeids(g.active_nodes())) g.do_timestep(actor=noticer) tag = g.as_node(first(g.new_nodes)) self.assertEqual(tag.__class__, AllBricksAvail) self.assertEqual(noticer.state, Completed) self.assertFalse(noticer.can_go()) self.assertNotIn(noticer.id, g.as_nodeids(g.active_nodes()))