Example #1
0
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False)
        door_two_one = door_one_two.reverse_door("one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close",
                                                 this_open_msg="door two open", this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
Example #2
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Key("key", "door key")
     key.key_for(code=12345)
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     door2 = Door("south", hall, "another locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.key_code = 12345
     door2.key_code = 9999
     key.key_for(door)
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     with self.assertRaises(ActionRefused):
         door2.unlock(key)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
     door.unlock(player)
     player.remove(key, player)
     with self.assertRaises(ActionRefused):
         door.lock(player)
     door.key_code = None
     with self.assertRaises(LocationIntegrityError):
         key.key_for(door)
Example #3
0
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two",
                            loc2,
                            "door to room two",
                            locked=True,
                            opened=False)
        door_two_one = door_one_two.reverse_door(
            "one",
            loc1,
            "door to room one",
            reverse_open_msg="door one open",
            reverse_close_msg="door one close",
            this_open_msg="door two open",
            this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
Example #4
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Item("key", "door key")
     key.door_code = 12345
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.door_code = 12345
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
Example #5
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Key("key", "door key")
     key.key_for(code=12345)
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     door2 = Door("south",
                  hall,
                  "another locked door",
                  locked=True,
                  opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.key_code = 12345
     door2.key_code = 9999
     key.key_for(door)
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     with self.assertRaises(ActionRefused):
         door2.unlock(key)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
     door.unlock(player)
     player.remove(key, player)
     with self.assertRaises(ActionRefused):
         door.lock(player)
     door.key_code = None
     with self.assertRaises(LocationIntegrityError):
         key.key_for(door)
Example #6
0
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(
                player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north",
                    hall,
                    "open unlocked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north",
                    hall,
                    "open locked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.",
                         str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north",
                    hall,
                    "closed unlocked door",
                    locked=False,
                    opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north",
                    hall,
                    "closed locked door",
                    locked=True,
                    opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.",
                         door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.",
                    "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual(
            "This is a peculiar door leading north. It is open and unlocked.",
            door.description)
Example #7
0
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north", hall, "open unlocked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north", hall, "open locked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.", str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north", hall, "closed unlocked door", locked=False, opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "closed locked door", locked=True, opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.", door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.", "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("This is a peculiar door leading north. It is open and unlocked.", door.description)