def test_single(self): """ A L{Path} of one L{Link} has one subpath that is equal to itself. """ source = Idea("source") target = Idea("target") path = Path(links=[Link(source=source, target=target)]) self.assertEqual([path], list(path.eachSubPath()))
def test_repr(self): """ A L{Path} instance can be rendered into a string by C{repr}. """ key = Idea(AlsoKnownAs("key")) table = Idea(AlsoKnownAs("table")) hall = Idea(AlsoKnownAs("hall")) path = Path(links=[ Link(source=hall, target=table), Link(source=table, target=key) ]) self.assertEquals( repr(path), "Path(\n" "\t'hall' => 'table' []\n" "\t'table' => 'key' [])")
def test_unnamedDelegate(self): """ The I{repr} of a L{Path} containing delegates without names includes the I{repr} of the delegates. """ key = Idea(Reprable("key")) table = Idea(Reprable("table")) hall = Idea(Reprable("hall")) path = Path(links=[ Link(source=hall, target=table), Link(source=table, target=key) ]) self.assertEquals( repr(path), "Path(\n" "\thall => table []\n" "\ttable => key [])")
def idea(self): """ An L{Idea} which represents this L{Thing}. """ idea = Idea(self) idea.linkers.append(self) idea.annotators.append(self) return idea
def exitIdea(self): """ This property is the L{Idea} representing this L{Exit}; this is a fairly simple L{Idea} that will link only to the L{Exit.toLocation} pointed to by this L{Exit}, with a distance annotation indicating the distance traversed to go through this L{Exit}. """ x = Idea(self) x.linkers.append(self) return x
def test_many(self): """ A L{Path} of N L{Link}s has N - 1 subpaths, in order from shortest to longest, consisting of each L{Path} which is a prefix of it. """ beginning = Idea("beginning") earlyMiddle = Idea("early middle") lateMiddle = Idea("late middle") end = Idea("end") one = Link(source=beginning, target=earlyMiddle) two = Link(source=earlyMiddle, target=lateMiddle) three = Link(source=lateMiddle, target=end) path = Path(links=[one, two, three]) self.assertEqual([ Path(links=[one]), Path(links=[one, two]), Path(links=[one, two, three]) ], list(path.eachSubPath()))
def setUp(self): garden = Idea(AlsoKnownAs("garden")) door = Idea(AlsoKnownAs("door")) hall = Idea(AlsoKnownAs("hall")) alice = Idea(AlsoKnownAs("alice")) key = Idea(AlsoKnownAs("key")) table = Idea(AlsoKnownAs("table")) alice.linkers.append(OneLink(Link(alice, hall))) hall.linkers.append(OneLink(Link(hall, door))) hall.linkers.append(OneLink(Link(hall, table))) table.linkers.append(OneLink(Link(table, key))) door.linkers.append(OneLink(Link(door, garden))) self.alice = alice self.hall = hall self.door = door self.garden = garden self.table = table self.key = key
def _exitIdea(self): """ Return an L{Idea} that reflects the implicit exit from this container to its location. """ return Idea(delegate=_ContainerExit(self))
def _entranceIdea(self): """ Return an L{Idea} that reflects the implicit entrance from this container's location to the interior of the container. """ return Idea(delegate=_ContainerEntrance(self))