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()))
def test_sleep_and_wake(self): g = NumboGraph(Numble([4, 5, 6], 15)) assert g.t == 0, f't == {g.t}, should == 0' node = g.as_node(g.look_for(NoticeSolved)) assert node, "We need an ActiveNode for this unit test." self.assertTrue(node.id in g.active_nodes()) node.state = Sleeping(Start, until=4) self.assertFalse(node.id in g.active_nodes()) g.do_timestep() assert g.t == 1 self.assertFalse(node.id in g.active_nodes()) g.do_timestep() assert g.t == 2 self.assertFalse(node.id in g.active_nodes()) g.do_timestep() assert g.t == 3 self.assertTrue(node.id in g.active_nodes())