2
from twisted.trial import unittest
4
from imagination import simulacrum
5
from imagination.simulacrum import ICollector, collect, always
6
from imagination.containment import Container, ILocatable, ILinkable
7
from imagination.architecture import IExit
8
from imagination.templates import basic
9
from imagination.facets import Facet
11
from zope.interface import Interface
13
class IRoach(Interface):
15
class Roachable(Facet):
18
class IKey(Interface):
31
from imagination.text.english import INoun
33
class CockroachTesta1(unittest.TestCase):
35
A demonstration of the infamous brass cockroach, reprising its role as the
36
world's most obscure and infuriating containment test.
40
me = basic.Actor.fill(INoun, name="bob").new()
41
me = basic.Actor.fill(INoun, name='bob').new()
42
ball = basic.Thing.fill(INoun, name='bouncy ball').new()
44
key = Key.fill(INoun, name='gold key').new()
47
room1 = basic.Room.new()
48
room2 = basic.Room.new()
49
room3 = basic.Room.new()
51
door1 = basic.Door.fill(IExit, closed=False).new()
52
door2 = basic.Door.fill(IExit, closed=False).new()
53
# print door1.closed, door2.closed
54
table = basic.Thing.new()
55
book = basic.Book.new()
57
ICollector(me).grab(key)
58
ICollector(me).link(0, room1)
59
ICollector(room1).grab(ball)
61
IExit(door1).between(room1, room2)
62
IExit(door2).between(room2, room3)
64
ICollector(room3).grab(roach2)
66
ICollector(table).link(0, book)
67
# ICollector(book).grab(roach)
68
ILocatable(roach).location = ILocatable(book)
69
ICollector(room2).link(0, table)
74
ICollector(O).link(1, N)
83
def testRightRoach(self):
84
roaches = list(collect(ICollector(self.me), IRoach, always, 2))
85
keys = list(collect(ICollector(self.me), IKey, always))
86
self.assertEquals(roaches, [(2, IRoach(self.roach))])
87
self.assertEquals(keys, [(0, IKey(self.key))])
89
def testFindSibling(self):
90
balls = simulacrum.lookFor(ICollector(self.me), 'ball', ICollector)
91
self.assertIn(ICollector(self.ball), [x[1] for x in balls])
93
def testContents(self):
94
self.assertEquals(list(ILocatable(self.book).contents), [self.roach])