예제 #1
0
 def test_many_exits_one_command(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_h1 = db.Exit("h1", self.lobby, self.lobby)
         self.exit_h2 = db.Exit("h2", self.lobby, self.lobby)
     db.store(self.exit_h1)
     db.store(self.exit_h2)
     self.assert_response("h", startswith="Available commands:")
예제 #2
0
 def test_many_exits_one_nospace(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_zzza = db.Exit("zzza", self.lobby, self.lobby)
         self.exit_zzzb = db.Exit("zzzb", self.lobby, self.lobby)
     db.store(self.exit_zzza)
     db.store(self.exit_zzzb)
     self.assert_response("zzz foo", "Spaaaaaaaaaaaaaace. (foo).")
예제 #3
0
 def test_many_exits_and_commands(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_s1 = db.Exit("s1", self.lobby, self.lobby)
         self.exit_s2 = db.Exit("s2", self.lobby, self.lobby)
     db.store(self.exit_s1)
     db.store(self.exit_s2)
     self.assert_response("s", startswith="Which command do you mean")
예제 #4
0
 def test_ambiguous_exit(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.exit_ju = db.Exit("jump", self.lobby, self.foyer)
         self.exit_jo = db.Exit("joust", self.lobby, self.foyer)
     for obj in self.foyer, self.exit_ju, self.exit_jo:
         db.store(obj)
     self.assert_response("j", "Which exit do you mean? (joust, jump)")
예제 #5
0
 def finish(room_name, to_exit_name, from_exit_name):
     room = db.Room(room_name)
     db.store(room)
     if to_exit_name != "":
         exit_to = db.Exit(to_exit_name, player.location, room)
         db.store(exit_to)
     if from_exit_name != "":
         exit_from = db.Exit(from_exit_name, room, player.location)
         db.store(exit_from)
     player.send("Dug room #{}, {}.".format(room.uid, room.name))
예제 #6
0
 def test_exit_nospace(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.zzzfoo = db.Exit("zzzfoo", self.lobby, self.foyer)
     db.store(self.foyer)
     db.store(self.zzzfoo)
     self.assert_response("zzzfoo", "Spaaaaaaaaaaaaaace. (foo).")
예제 #7
0
    def test_exit(self):
        with locks.authority_of(locks.SYSTEM):
            owner = db.Object("owner")
        db.store(owner)
        with locks.authority_of(owner):
            source = db.Room("Source")
            dest = db.Room("Dest")
            db.store(source)
            db.store(dest)
            player = db.Object("Player", location=source)
            player.send = mock.MagicMock()
            db.store(player)
            exit = db.Exit("Exit", source, dest)
            exit.go_message = ("You, {player}, go from {source} to "
                               "{destination} via {exit}.")
            db.store(exit)
            sourceBystander = db.Object("source bystander", location=source)
            sourceBystander.send = mock.MagicMock()
            db.store(sourceBystander)
            destBystander = db.Object("dest bystander", location=dest)
            destBystander.send = mock.MagicMock()
            db.store(destBystander)

            self.assertIs(player.location, source)
            exit.go(player)
            self.assertIs(player.location, dest)
            self.assertEqual(sourceBystander.send.call_count, 1)
            self.assertEqual(destBystander.send.call_count, 1)

            sourceBystander.send.assert_called_once_with(
                "Player leaves through Exit.")
            destBystander.send.assert_called_once_with("Player arrives.")
            player.send.assert_called_with("You, Player, go from Source to "
                                           "Dest via Exit.")
예제 #8
0
 def test_exit_permissions(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.exit = db.Exit("exit", self.lobby, self.foyer)
         self.exit.locks.go = locks.Fail()
     db.store(self.foyer)
     db.store(self.exit)
     self.assert_response("exit", "You can't go through exit.")
예제 #9
0
 def test_exit_invocation(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         db.store(self.foyer)
         self.exit = db.Exit("exit", self.lobby, self.foyer)
     db.store(self.exit)
     self.assertEqual(self.player.location, self.lobby)
     self.player.send_line("exit")
     self.assertEqual(self.player.location, self.foyer)
예제 #10
0
 def execute(self, player, args):
     name_words = args["name"]
     destination = args["destination"]
     to = name_words.pop()
     name = " ".join(name_words)
     if to != "to":
         # this is me compensating for pyparsing's failings
         raise pyp.ParseException(name, len(name) - len(to), None, None)
     exit = db.Exit(name, player.location, destination)
     db.store(exit)
     player.send("Opened {} to {}.".format(exit, destination))