~exarkun/divmod.org/remove-epsilon-1325289

« back to all changes in this revision

Viewing changes to Imaginary/ExampleGame/examplegame/test/test_furniture.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-07 13:26:27 UTC
  • mfrom: (2741.2.2 1320678-remove-imaginary)
  • Revision ID: exarkun@twistedmatrix.com-20140607132627-jz2zhbk9jajamk43
Remove Imaginary.  Find it at <https://github.com/twisted/imaginary>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
"""
3
 
This module contains tests for the examplegame.furniture module.
4
 
"""
5
 
 
6
 
from twisted.trial.unittest import TestCase
7
 
 
8
 
from imaginary.test.commandutils import CommandTestCaseMixin, E, createLocation
9
 
 
10
 
from imaginary.objects import Thing, Exit
11
 
from examplegame.furniture import Chair
12
 
 
13
 
class SitAndStandTests(CommandTestCaseMixin, TestCase):
14
 
    """
15
 
    Tests for the 'sit' and 'stand' actions.
16
 
    """
17
 
 
18
 
    def setUp(self):
19
 
        """
20
 
        Create a room, with a dude in it, and a chair he can sit in.
21
 
        """
22
 
        CommandTestCaseMixin.setUp(self)
23
 
        self.chairThing = Thing(store=self.store, name=u"chair")
24
 
        self.chairThing.moveTo(self.location)
25
 
        self.chair = Chair.createFor(self.chairThing)
26
 
 
27
 
 
28
 
    def test_sitDown(self):
29
 
        """
30
 
        Sitting in a chair should move your location to that chair.
31
 
        """
32
 
        self.assertCommandOutput(
33
 
            "sit chair",
34
 
            ["You sit in the chair."],
35
 
            ["Test Player sits in the chair."])
36
 
        self.assertEquals(self.player.location, self.chair.thing)
37
 
 
38
 
 
39
 
    def test_standWhenStanding(self):
40
 
        """
41
 
        You can't stand up - you're already standing up.
42
 
        """
43
 
        self.assertCommandOutput(
44
 
            "stand up",
45
 
            ["You're already standing."])
46
 
 
47
 
 
48
 
    def test_standWhenSitting(self):
49
 
        """
50
 
        If a player stands up when sitting in a chair, they should be seen to
51
 
        stand up, and they should be placed back into the room where the chair
52
 
        is located.
53
 
        """
54
 
        self.test_sitDown()
55
 
        self.assertCommandOutput(
56
 
            "stand up",
57
 
            ["You stand up."],
58
 
            ["Test Player stands up."])
59
 
        self.assertEquals(self.player.location, self.location)
60
 
 
61
 
 
62
 
    def test_takeWhenSitting(self):
63
 
        """
64
 
        When a player is seated, they should still be able to take objects on
65
 
        the floor around them.
66
 
        """
67
 
        self.test_sitDown()
68
 
        self.ball = Thing(store=self.store, name=u'ball')
69
 
        self.ball.moveTo(self.location)
70
 
        self.assertCommandOutput(
71
 
            "take ball",
72
 
            ["You take a ball."],
73
 
            ["Test Player takes a ball."])
74
 
 
75
 
 
76
 
    def test_moveWhenSitting(self):
77
 
        """
78
 
        A player who is sitting shouldn't be able to move without standing up
79
 
        first.
80
 
        """
81
 
        self.test_sitDown()
82
 
        otherRoom = createLocation(self.store, u"elsewhere", None).thing
83
 
        Exit.link(self.location, otherRoom, u'north')
84
 
        self.assertCommandOutput(
85
 
            "go north",
86
 
            ["You can't do that while sitting down."])
87
 
        self.assertCommandOutput(
88
 
            "go south",
89
 
            ["You can't go that way."])
90
 
 
91
 
 
92
 
    def test_lookWhenSitting(self):
93
 
        """
94
 
        Looking around when sitting should display the description of the room.
95
 
        """
96
 
        self.test_sitDown()
97
 
        self.assertCommandOutput(
98
 
            "look",
99
 
            # I'd like to add ', in the chair' to this test, but there's
100
 
            # currently no way to modify the name of the object being looked
101
 
            # at.
102
 
            [E("[ Test Location ]"),
103
 
             "Location for testing.",
104
 
             "Here, you see Observer Player and a chair."])