Esempio n. 1
0
 def test_look_short(self):
     expected = ["[Attic]"]
     self.assertEqual(expected, strip_text_styles(self.attic.look(short=True)))
     expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, player, and two rats"]
     self.assertEqual(expected, strip_text_styles(self.hall.look(short=True)))
     expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, and two rats"]
     self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player, short=True)))
Esempio n. 2
0
 def test_look(self):
     expected = ["[Main hall]", "A very large hall.",
                 "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                 "Someone forgot a key. You see two university magazines and an oak table. Player, attractive Julie, and two rats are here. A fly buzzes around your head."]
     self.assertEqual(expected, strip_text_styles(self.hall.look()))
     expected = ["[Main hall]", "A very large hall.",
                 "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                 "Someone forgot a key. You see two university magazines and an oak table. Attractive Julie and two rats are here. A fly buzzes around your head."]
     self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player)))
     expected = ["[Attic]", "A dark attic."]
     self.assertEqual(expected, strip_text_styles(self.attic.look()))
Esempio n. 3
0
 def test_title(self):
     bag = Container("bag", "leather bag", "a small leather bag")
     stone = Item("stone")
     player = Player("julie", "f")
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", bag.title)
     self.assertEqual("a small leather bag", bag.description)
     bag.move(player, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag", strip_text_styles(bag.description))
     stone.move(bag, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag", strip_text_styles(bag.description))
Esempio n. 4
0
 def test_exits(self):
     hall = Location("hall")
     attic = Location("attic")
     exit1 = Exit("ladder1", attic, "The first ladder leads to the attic.")
     exit2 = Exit("up", attic, "Second ladder to attic.")
     exit3 = Exit("ladder3", attic, "Third ladder to attic.")
     exit4 = Exit("window", attic, "A window.",
                  "A window, maybe if you open it you can get out?")
     hall.add_exits([exit1, exit2, exit3, exit4])
     self.assertTrue(hall.exits["up"] is exit2)
     self.assertTrue(hall.exits["ladder3"] is exit3)
     self.assertTrue(hall.exits["window"] is exit4)
     self.assertEqual([
         '[hall]',
         'The first ladder leads to the attic. Third ladder to attic. Second ladder to attic. A window.'
     ], strip_text_styles(hall.look()))
     self.assertEqual("Third ladder to attic.", exit3.description)
     self.assertEqual("A window, maybe if you open it you can get out?",
                      exit4.description)
     with self.assertRaises(ActionRefused):
         exit1.activate(None)
     with self.assertRaises(ActionRefused):
         exit1.deactivate(None)
     with self.assertRaises(ActionRefused):
         exit1.close(None, None)
     with self.assertRaises(ActionRefused):
         exit1.open(None, None)
     with self.assertRaises(ActionRefused):
         exit1.lock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.unlock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.manipulate("frobnitz", None)
     with self.assertRaises(ActionRefused):
         exit1.read(None)
Esempio n. 5
0
 def test_look(self):
     expected = [
         "[Main hall]", "A very large hall.",
         "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
         "Someone forgot a key. You see two university magazines and an oak table. Player, attractive Julie, and two rats are here. A fly buzzes around your head."
     ]
     self.assertEqual(expected, strip_text_styles(self.hall.look()))
     expected = [
         "[Main hall]", "A very large hall.",
         "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
         "Someone forgot a key. You see two university magazines and an oak table. Attractive Julie and two rats are here. A fly buzzes around your head."
     ]
     self.assertEqual(
         expected,
         strip_text_styles(self.hall.look(exclude_living=self.player)))
     expected = ["[Attic]", "A dark attic."]
     self.assertEqual(expected, strip_text_styles(self.attic.look()))
Esempio n. 6
0
 def test_title(self):
     bag = Container("bag", "leather bag", "a small leather bag")
     stone = Item("stone")
     player = Player("julie", "f")
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", bag.title)
     self.assertEqual("a small leather bag", bag.description)
     bag.move(player, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag",
                      strip_text_styles(bag.description))
     stone.move(bag, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag",
                      strip_text_styles(bag.description))
Esempio n. 7
0
 def test_look_short(self):
     expected = ["[Attic]"]
     self.assertEqual(expected,
                      strip_text_styles(self.attic.look(short=True)))
     expected = [
         "[Main hall]", "Exits: door, east, up",
         "You see: key, two magazines, and table",
         "Present: fly, julie, player, and two rats"
     ]
     self.assertEqual(expected,
                      strip_text_styles(self.hall.look(short=True)))
     expected = [
         "[Main hall]", "Exits: door, east, up",
         "You see: key, two magazines, and table",
         "Present: fly, julie, and two rats"
     ]
     self.assertEqual(
         expected,
         strip_text_styles(
             self.hall.look(exclude_living=self.player, short=True)))
Esempio n. 8
0
 def test_wrap(self):
     w = styleaware_wrapper.StyleTagsAwareTextWrapper(width=20)
     wrapped = w.fill("This is some text with or without style tags, to see how the wrapping goes.")
     self.assertEqual("This is some text\n"
                      "with or without\n"
                      "style tags, to see\n"
                      "how the wrapping\n"
                      "goes.", wrapped)
     wrapped = w.fill("This is <bright>some text</> with <bright>or without</> style tags, <bright>to</> see <bright>how the</> wrapping <bright>goes.</>")
     wrapped = iobase.strip_text_styles(wrapped)
     self.assertEqual("This is some text\n"
                      "with or without\n"
                      "style tags, to see \n"
                      "how the wrapping \n"
                      "goes.", wrapped)
Esempio n. 9
0
 def test_wrap(self):
     w = styleaware_wrapper.StyleTagsAwareTextWrapper(width=20)
     wrapped = w.fill(
         "This is some text with or without style tags, to see how the wrapping goes."
     )
     self.assertEqual(
         "This is some text\n"
         "with or without\n"
         "style tags, to see\n"
         "how the wrapping\n"
         "goes.", wrapped)
     wrapped = w.fill(
         "This is <bright>some text</> with <bright>or without</> style tags, <bright>to</> see <bright>how the</> wrapping <bright>goes.</>"
     )
     wrapped = iobase.strip_text_styles(wrapped)
     self.assertEqual(
         "This is some text\n"
         "with or without\n"
         "style tags, to see \n"
         "how the wrapping \n"
         "goes.", wrapped)
Esempio n. 10
0
 def test_exits(self):
     hall = Location("hall")
     attic = Location("attic")
     exit1 = Exit("ladder1", attic, "The first ladder leads to the attic.")
     exit2 = Exit("up", attic, "Second ladder to attic.")
     exit3 = Exit("ladder3", attic, "Third ladder to attic.")
     exit4 = Exit("window", attic, "A window.", "A window, maybe if you open it you can get out?")
     hall.add_exits([exit1, exit2, exit3, exit4])
     self.assertTrue(hall.exits["up"] is exit2)
     self.assertTrue(hall.exits["ladder3"] is exit3)
     self.assertTrue(hall.exits["window"] is exit4)
     self.assertEqual(['[hall]', 'The first ladder leads to the attic. Third ladder to attic. Second ladder to attic. A window.'], strip_text_styles(hall.look()))
     self.assertEqual("Third ladder to attic.", exit3.description)
     self.assertEqual("A window, maybe if you open it you can get out?", exit4.description)
     with self.assertRaises(ActionRefused):
         exit1.activate(None)
     with self.assertRaises(ActionRefused):
         exit1.deactivate(None)
     with self.assertRaises(ActionRefused):
         exit1.close(None, None)
     with self.assertRaises(ActionRefused):
         exit1.open(None, None)
     with self.assertRaises(ActionRefused):
         exit1.lock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.unlock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.manipulate("frobnitz", None)
     with self.assertRaises(ActionRefused):
         exit1.read(None)