コード例 #1
0
ファイル: test_basicitems.py プロジェクト: zaghaghi/Tale
 def test_takability(self):
     p = base.Living("living", "m")
     item = base.Item("item")
     self.assertTrue(item.takeable)
     item.move(p, p)
     brd = board.BulletinBoard("board")
     self.assertFalse(brd.takeable)
     with self.assertRaises(ActionRefused) as x:
         brd.move(p, p, verb="frob")
     self.assertEqual("You can't frob board.", str(x.exception))
     bx = basic.Boxlike("box")
     self.assertTrue(bx.takeable)
     bx.move(p, p)
     bnk = bank.Bank("bank")
     self.assertFalse(bnk.takeable)
     with self.assertRaises(ActionRefused) as x:
         bnk.move(p, p, verb="frob")
     self.assertEqual("The bank won't budge.", str(x.exception))
     with self.assertRaises(ActionRefused) as x:
         bnk.allow_item_move(p, verb="frob")
     self.assertEqual("The bank won't budge.", str(x.exception))
     # now flip the flags around
     bnk.takeable = True
     bnk.allow_item_move(p)
     bnk.move(p, p)
     bx.takeable = False
     with self.assertRaises(ActionRefused) as x:
         bx.move(p, p, verb="frob")
     self.assertEqual("You can't frob box.", str(x.exception))
     brd.takeable = True
     brd.move(p, p)
     item.takeable = False
     with self.assertRaises(ActionRefused) as x:
         item.move(p, p, verb="frob")
     self.assertEqual("You can't frob item.", str(x.exception))
コード例 #2
0
ファイル: test_serialize.py プロジェクト: totalgit/Tale
 def test_living_player(self):
     thing = base.Item("thing")
     p = player.Player("playername", "n", descr="description")
     p.insert(thing, None)
     p.title = "title"
     p.money = 42
     p.brief = True
     p.story_data = {"data": 42}
     p.privileges.add("wizard")
     o = base.Living("name",
                     "f",
                     title="title",
                     descr="description",
                     race="dragon")
     o.aggressive = True
     o.following = p
     o.is_pet = True
     o.stats.attack_dice = "2d8"
     o.stats.level = 12
     o.stats.hp = 100
     x = serializecycle(o)
     assert x["__class__"] == "tale.base.Living"
     assert x["aggressive"] == True
     assert len(x["following"]) == 4
     assert x["following"][1] == "playername"
     assert x["is_pet"] == True
     assert x["location"][1] == "Limbo"
     assert x["race"] == "dragon"
     assert len(x["privileges"]) == 0
     assert "soul" not in x
     assert "teleported_from" not in x
     s = x["stats"]
     assert s["gender"] == "f"
     assert s["race"] == "dragon"
     assert s["attack_dice"] == "2d8"
     assert s["level"] == 12
     assert s["hp"] == 100
     x = serializecycle(p)
     assert x["__class__"] == x["__base_class__"] == "tale.player.Player"
     assert x["brief"] == True
     assert x["location"][1] == "Limbo"
     assert x["money"] == 42
     assert x["name"] == "playername"
     assert x["story_data"]["data"] == 42
     assert x["turns"] == 0
     assert x["screen_width"] == p.screen_width
     assert x["hints"]["__class__"] == "tale.hints.HintSystem"
     assert x["hints"]["checkpoints"] == [None]
     assert x["stats"]["race"] == x["race"] == "human"
     assert x["stats"]["xp"] == 0
     assert len(x["inventory"]) == 1
     inv = x["inventory"].pop()
     assert inv[1] == "thing"
コード例 #3
0
 def test_living_npc_monster(self):
     o = base.Living("name",
                     "n",
                     title="title",
                     description="description",
                     race="dragon")
     x = serializecycle(o)
     self.assert_base_attrs(x)
     o = npc.NPC("name",
                 "n",
                 title="title",
                 description="description",
                 race="dragon")
     x = serializecycle(o)
     self.assert_base_attrs(x)
     self.assertFalse(x.aggressive)
コード例 #4
0
ファイル: test_serialize.py プロジェクト: totalgit/Tale
 def test_location(self):
     room = base.Location("room", "description")
     thing = base.Item("thing")
     room.insert(thing, None)
     npc = base.Living("dog", "m")
     room.insert(npc, None)
     x = serializecycle(room)
     assert x["__class__"] == "tale.base.Location"
     assert x["name"] == "room"
     assert x["descr"] == "description"
     assert x["exits"] == ()
     assert len(x["items"]) == 1
     assert len(x["livings"]) == 1
     assert isinstance(x["items"], set)
     assert isinstance(x["livings"], set)
     x_item = x["items"].pop()
     x_living = x["livings"].pop()
     assert len(x_item) == 4
     assert x_item[0] > 0
     assert x_item[1] == "thing"
     assert len(x_living) == 4
     assert x_living[0] > 0
     assert x_living[1] == "dog"
     # now add some exits and a second location, and try again
     room2 = base.Location("room2", "description")
     exit1 = base.Exit("room2", room2, "to room2")
     exit2 = base.Exit("room", room, "back to room")
     room.add_exits([exit1])
     room2.add_exits([exit2])
     x1, x2 = serializecycle([room, room2])
     assert len(x1["exits"]) == 1
     assert isinstance(x1["exits"], set)
     assert len(x2["exits"]) == 1
     assert isinstance(x2["exits"], set)
     x_exit = x1["exits"].pop()
     assert len(x_exit) == 4
     assert x_exit[0] > 0
     assert x_exit[1] == "room2"
     assert x_exit[2] == x_exit[3] == "tale.base.Exit"
     assert x2["name"] == "room2"
     x_exit = x2["exits"].pop()
     assert len(x_exit) == 4
     assert x_exit[0] > 0
     assert x_exit[1] == "room"