Beispiel #1
0
 def test_move(self):
     hall = Location("hall")
     attic = Location("attic")
     rat = Living("rat", "n", race="rodent")
     hall.init_inventory([rat])
     wiretap_hall = Wiretap(hall)
     wiretap_attic = Wiretap(attic)
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     rat.move(attic)
     self.assertTrue(rat in attic.livings)
     self.assertFalse(rat in hall.livings)
     self.assertEqual(attic, rat.location)
     pubsub.sync()
     self.assertEqual([("hall", "Rat leaves.")], wiretap_hall.msgs)
     self.assertEqual([("attic", "Rat arrives.")], wiretap_attic.msgs)
     # now try silent
     wiretap_hall.clear()
     wiretap_attic.clear()
     rat.move(hall, silent=True)
     pubsub.sync()
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     self.assertEqual([], wiretap_hall.msgs)
     self.assertEqual([], wiretap_attic.msgs)
Beispiel #2
0
 def test_move(self):
     hall = Location("hall")
     attic = Location("attic")
     rat = Living("rat", "n", race="rodent")
     hall.init_inventory([rat])
     wiretap_hall = Wiretap(hall)
     wiretap_attic = Wiretap(attic)
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     rat.move(attic)
     self.assertTrue(rat in attic.livings)
     self.assertFalse(rat in hall.livings)
     self.assertEqual(attic, rat.location)
     self.assertEqual([("hall", "Rat leaves.")], wiretap_hall.msgs)
     self.assertEqual([("attic", "Rat arrives.")], wiretap_attic.msgs)
     # now try silent
     wiretap_hall.clear()
     wiretap_attic.clear()
     rat.move(hall, silent=True)
     self.assertTrue(rat in hall.livings)
     self.assertFalse(rat in attic.livings)
     self.assertEqual(hall, rat.location)
     self.assertEqual([], wiretap_hall.msgs)
     self.assertEqual([], wiretap_attic.msgs)
Beispiel #3
0
 def test_look(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     player.look()
     self.assertEqual([
         "[Limbo]\n",
         "The intermediate or transitional place or state. There's only nothingness. "
         "Living beings end up here if they're not in a proper location yet.\n"
     ], player.test_get_output_paragraphs())
     player.move(attic, silent=True)
     player.look(short=True)
     self.assertEqual(["[Attic]\n"], player.test_get_output_paragraphs())
     julie = Living("julie", "f")
     julie.move(attic, silent=True)
     player.look(short=True)
     self.assertEqual(["[Attic]\n", "Present here: julie\n"],
                      player.test_get_output_paragraphs())
Beispiel #4
0
 def test_socialize(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     julie = Living("julie", "f")
     julie.move(attic)
     player.move(attic)
     parsed = player.parse("wave all")
     self.assertEqual("wave", parsed.verb)
     self.assertEqual(1, parsed.who_count)
     self.assertEqual(julie, parsed.who_1)
     self.assertEqual((julie, None, None), parsed.who_123)
     self.assertEqual(julie, parsed.who_last)
     self.assertEqual([julie], list(parsed.who_info))
     who, playermsg, roommsg, targetmsg = player.soul.process_verb_parsed(
         player, parsed)
     self.assertEqual({julie}, who)
     self.assertEqual("You wave happily at julie.", playermsg)
     with self.assertRaises(tale.errors.UnknownVerbException):
         player.parse("befrotzificate all and me")
     with self.assertRaises(NonSoulVerb) as x:
         player.parse("befrotzificate all and me",
                      external_verbs={"befrotzificate"})
     parsed = x.exception.parsed
     self.assertEqual("befrotzificate", parsed.verb)
     self.assertEqual(2, parsed.who_count)
     self.assertEqual(julie, parsed.who_1)
     self.assertEqual((julie, player, None), parsed.who_123)
     self.assertEqual([julie, player], list(parsed.who_info))
     self.assertEqual(player, parsed.who_last)
     attic.add_exits([Exit("south", "target", "door")])
     try:
         player.parse("push south")
         self.fail(
             "push south should throw a parse error because of the exit that is used"
         )
     except ParseError:
         pass
     with self.assertRaises(NonSoulVerb):
         player.parse("fart south")
     parsed = player.parse("hug julie")
     player.validate_socialize_targets(parsed)
Beispiel #5
0
 def test_look_brief(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     cellar = Location("Cellar", "A gloomy cellar.")
     julie = Living("julie", "f")
     julie.move(attic, silent=True)
     player.move(attic, silent=True)
     player.brief = 0  # default setting: always long descriptions
     player.look()
     self.assertEqual(["[Attic]\n", "A dark attic.\n", "Julie is here.\n"],
                      player.test_get_output_paragraphs())
     player.look()
     self.assertEqual(["[Attic]\n", "A dark attic.\n", "Julie is here.\n"],
                      player.test_get_output_paragraphs())
     player.look(short=True)  # override
     self.assertEqual(["[Attic]\n", "Present here: julie\n"],
                      player.test_get_output_paragraphs())
     player.brief = 1  # short for known, long for new locations
     player.look()
     self.assertEqual(["[Attic]\n", "Present here: julie\n"],
                      player.test_get_output_paragraphs())
     player.move(cellar, silent=True)
     player.look()
     self.assertEqual(["[Cellar]\n", "A gloomy cellar.\n"],
                      player.test_get_output_paragraphs())
     player.look()
     self.assertEqual(["[Cellar]\n"], player.test_get_output_paragraphs())
     player.brief = 2  # short always
     player.known_locations.clear()
     player.look()
     self.assertEqual(["[Cellar]\n"], player.test_get_output_paragraphs())
     player.move(attic, silent=True)
     player.look()
     self.assertEqual(["[Attic]\n", "Present here: julie\n"],
                      player.test_get_output_paragraphs())
     player.look(short=True)  # override
     self.assertEqual(["[Attic]\n", "Present here: julie\n"],
                      player.test_get_output_paragraphs())
     player.look(short=False)  # override
     self.assertEqual(["[Attic]\n", "A dark attic.\n", "Julie is here.\n"],
                      player.test_get_output_paragraphs())
Beispiel #6
0
 def test_wiretap(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("fritz", "m")
     io = ConsoleIo(None)
     io.supports_smartquotes = False
     pc = PlayerConnection(player, io)
     player.set_screen_sizes(0, 100)
     julie = Living("julie", "f")
     julie.move(attic)
     player.move(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())
     with self.assertRaises(ActionRefused):
         player.create_wiretap(julie)
     player.privileges = {"wizard"}
     player.create_wiretap(julie)
     player.create_wiretap(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     pubsub.sync()
     output = pc.get_output()
     self.assertTrue(
         "[wiretapped from `Attic': message for room]" in output)
     self.assertTrue(
         "[wiretapped from `julie': message for julie]" in output)
     self.assertTrue(
         "[wiretapped from `julie': message for room]" in output)
     self.assertTrue("message for room " in output)
     # test removing the wiretaps
     player.clear_wiretaps()
     import gc
     gc.collect()
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())