def test_socialize(self): player = Player("fritz", "m") attic = Location("Attic", "A dark attic.") julie = NPC("julie", "f") julie.move(attic) player.move(attic) parsed = player.parse("wave all") self.assertEqual("wave", parsed.verb) self.assertEqual([julie], parsed.who_order) 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.soul.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([julie, player], parsed.who_order) 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)
def test_look_brief(self): player = Player("fritz", "m") attic = Location("Attic", "A dark attic.") cellar = Location("Cellar", "A gloomy cellar.") julie = NPC("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: julie\n"], player.test_get_output_paragraphs()) player.brief = 1 # short for known, long for new locations player.look() self.assertEqual(["[Attic]\n", "Present: 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: julie\n"], player.test_get_output_paragraphs()) player.look(short=True) # override self.assertEqual(["[Attic]\n", "Present: 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())
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 = NPC("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())
def test_socialize(self): player = Player("fritz", "m") attic = Location("Attic", "A dark attic.") julie = NPC("julie", "f") julie.move(attic) player.move(attic) parsed = player.parse("wave all") self.assertEqual("wave", parsed.verb) self.assertEqual([julie], parsed.who_order) 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.soul.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([julie, player], parsed.who_order) 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)
def test_move_notify(self): class LocationNotify(Location): def notify_npc_left(self, npc, target_location): self.npc_left = npc self.npc_left_target = target_location def notify_npc_arrived(self, npc, previous_location): self.npc_arrived = npc self.npc_arrived_from = previous_location def notify_player_left(self, player, target_location): self.player_left = player self.player_left_target = target_location def notify_player_arrived(self, player, previous_location): self.player_arrived = player self.player_arrived_from = previous_location npc = NPC("rat", "m", race="rodent") room1 = LocationNotify("room1") room2 = LocationNotify("room2") room1.insert(npc, None) npc.move(room2) pubsub.sync() self.assertEqual(room2, npc.location) self.assertEqual(npc, room1.npc_left) self.assertEqual(room2, room1.npc_left_target) self.assertEqual(npc, room2.npc_arrived) self.assertEqual(room1, room2.npc_arrived_from)
def test_move_notify(self): class LocationNotify(Location): def notify_npc_left(self, npc, target_location): self.npc_left = npc self.npc_left_target = target_location def notify_npc_arrived(self, npc, previous_location): self.npc_arrived = npc self.npc_arrived_from = previous_location def notify_player_left(self, player, target_location): self.player_left = player self.player_left_target = target_location def notify_player_arrived(self, player, previous_location): self.player_arrived = player self.player_arrived_from = previous_location npc = NPC("rat", "m", race="rodent") room1 = LocationNotify("room1") room2 = LocationNotify("room2") room1.insert(npc, None) npc.move(room2) mud_context.driver.execute_after_player_actions() self.assertEqual(room2, npc.location) self.assertEqual(npc, room1.npc_left) self.assertEqual(room2, room1.npc_left_target) self.assertEqual(npc, room2.npc_arrived) self.assertEqual(room1, room2.npc_arrived_from)
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.\nLiving 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 = NPC("julie", "f") julie.move(attic, silent=True) player.look(short=True) self.assertEqual(["[Attic]\n", "Present: julie\n"], player.test_get_output_paragraphs())
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.\nLiving 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 = NPC("julie", "f") julie.move(attic, silent=True) player.look(short=True) self.assertEqual(["[Attic]\n", "Present: julie\n"], player.test_get_output_paragraphs())
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 = NPC("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())