~divmod-dev/divmod.org/compressed-resources-2747

« back to all changes in this revision

Viewing changes to Imaginary/imagination/test/test_simu.py

  • Committer: exarkun
  • Date: 2006-02-26 02:37:39 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:4991
Merge move-pottery-to-trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from twisted.trial import unittest
 
3
 
 
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
 
10
 
 
11
from zope.interface import Interface
 
12
 
 
13
class IRoach(Interface):
 
14
    pass
 
15
class Roachable(Facet):
 
16
    pass
 
17
 
 
18
class IKey(Interface):
 
19
    pass
 
20
class Keyable(Facet):
 
21
    pass
 
22
 
 
23
Roach = basic.Thing[
 
24
    IRoach: Roachable,
 
25
    ]
 
26
 
 
27
Key = basic.Thing[
 
28
    IKey: Keyable,
 
29
    ]
 
30
 
 
31
from imagination.text.english import INoun
 
32
 
 
33
class CockroachTesta1(unittest.TestCase):
 
34
    """
 
35
    A demonstration of the infamous brass cockroach, reprising its role as the
 
36
    world's most obscure and infuriating containment test.
 
37
    """
 
38
 
 
39
    def setUp(self):
 
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()
 
43
 
 
44
        key = Key.fill(INoun, name='gold key').new()
 
45
        roach = Roach.new()
 
46
        roach2 = Roach.new()
 
47
        room1 = basic.Room.new()
 
48
        room2 = basic.Room.new()
 
49
        room3 = basic.Room.new()
 
50
 
 
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()
 
56
 
 
57
        ICollector(me).grab(key)
 
58
        ICollector(me).link(0, room1)
 
59
        ICollector(room1).grab(ball)
 
60
 
 
61
        IExit(door1).between(room1, room2)
 
62
        IExit(door2).between(room2, room3)
 
63
 
 
64
        ICollector(room3).grab(roach2)
 
65
 
 
66
        ICollector(table).link(0, book)
 
67
        # ICollector(book).grab(roach)
 
68
        ILocatable(roach).location = ILocatable(book)
 
69
        ICollector(room2).link(0, table)
 
70
 
 
71
        O = room1
 
72
        for x in range(100):
 
73
            N = basic.Room.new()
 
74
            ICollector(O).link(1, N)
 
75
            O = N
 
76
 
 
77
        self.me = me
 
78
        self.roach = roach
 
79
        self.key = key
 
80
        self.ball = ball
 
81
        self.book = book
 
82
 
 
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))])
 
88
 
 
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])
 
92
 
 
93
    def testContents(self):
 
94
        self.assertEquals(list(ILocatable(self.book).contents), [self.roach])
 
95