Debian Codegraph @

adventure/tests/test_data.py

raw
1 """Test suite.
2
3 Copyright 2010-2015 Brandon Rhodes. Licensed as free software under the
4 Apache License, Version 2.0 as detailed in the accompanying README.txt.
5
6 """
7 import unittest
8
9 class DataTest(unittest.TestCase):
10
11 def setUp(self):
12 from adventure.data import Data
13 from adventure import load_advent_dat
14 self.data = Data()
15 load_advent_dat(self.data)
16
17 def test_long_description(self):
18 self.assertEqual(self.data.rooms[4].long_description, """\
19 YOU ARE IN A VALLEY IN THE FOREST BESIDE A STREAM TUMBLING ALONG A
20 ROCKY BED.
21 """)
22
23 def test_long_description_expands_tabs(self):
24 self.assertIn("ALMOST AS IF ALIVE. A COLD WIND BLOWS",
25 self.data.rooms[15].long_description)
26
27 def test_short_description(self):
28 self.assertEqual(self.data.rooms[4].short_description,
29 "YOU'RE IN VALLEY.\n")
30
31 def test_object_message_expands_tabs(self):
32 self.assertEqual(self.data.objects[24].messages[5], """\
33 YOU'VE OVER-WATERED THE PLANT! IT'S SHRIVELING UP! IT'S, IT'S...
34 """)
35
36 def test_hint(self):
37 hint = self.data.hints[4]
38 self.assertEqual(hint.turns_needed, 4)
39 self.assertEqual(hint.penalty, 2)
40 self.assertEqual(hint.question.text,
41 "ARE YOU TRYING TO GET INTO THE CAVE?\n")
42 self.assertEqual(hint.message.text, """\
43 THE GRATE IS VERY SOLID AND HAS A HARDENED STEEL LOCK. YOU CANNOT
44 ENTER WITHOUT A KEY, AND THERE ARE NO KEYS NEARBY. I WOULD RECOMMEND
45 LOOKING ELSEWHERE FOR THE KEYS.
46 """)
47
48 class ReprTest(unittest.TestCase):
49
50 def setUp(self):
51 from adventure.data import Data
52 from adventure import load_advent_dat
53 self.data = Data()
54 load_advent_dat(self.data)
55
56 def assertMove(self, room_i, entry_i, s):
57 r = repr(self.data.rooms[room_i].travel_table[entry_i]).strip()
58 self.assertEqual(r, s)
59
60 def test_move_repr_look_good(self):
61 m = self.assertMove
62 m(1, 0, '<road|west|upward moves to "YOU\'RE AT HILL IN ROAD.">')
63 m(108, 0, '<east|north|south|ne|se|sw|nw|upward|d 95% of the time'
64 ' prints \'YOU HAVE CRAWLED AROUND IN SOME LITTLE HOLES AND WOUND'
65 ' UP BACK IN THE\\nMAIN PASSAGE.\\n\'>')
66 m(61, 2, '<south if not a dwarf moves to \'YOU ARE IN A MAZE OF\'>')
67 m(15, 3, '<upward|pit|steps|dome|passage|east if carrying 50 moves'
68 ' to \'THE DOME IS UNCLIMBA\'>')
69 m(19, 6, '<sw if carrying or in room with 11 moves to '
70 '"YOU CAN\'T GET BY THE">')
71 m(17, 2, '<forward if prop 12 != 1 moves to "YOU DIDN\'T MAKE IT.">')
72
73 def test_move_repr_works_on_all_moves(self):
74 for room in self.data.rooms.values():
75 for i, move in enumerate(room.travel_table):
76 try:
77 repr(move)
78 except: # pragma: no cover
79 print(room, i)
80 raise
81
82 def test_room_repr(self):
83 self.assertRegex(repr(self.data.rooms[64]), '<room 64 at .*>')
84
85 def test_object_repr(self):
86 self.assertRegex(repr(self.data.objects['chest']),
87 r'<Object 55 chest/box/treasure .*>')
88
89 def test_word_repr(self):
90 self.assertEqual(repr(self.data.vocabulary['eat']), '<Word eat>')