2 """Regression test script for the mudpy engine."""
4 # Copyright (c) 2004-2016 Jeremy Stanley <fungi@yuggoth.org>. Permission
5 # to use, copy, modify, and distribute this software is granted under
6 # terms provided in the LICENSE file distributed with this software.
12 test_account0_setup = (
13 (0, "Identify yourself:", "luser0"),
14 (0, "Enter your choice:", "n"),
15 (0, "Enter a new password for \"luser0\":", "Test123"),
16 (0, "Enter the same new password again:", "Test123"),
17 (0, "What would you like to do\?", "c"),
18 (0, "Pick a birth gender for your new avatar:", "f"),
19 (0, "Choose a name for her:", "1"),
20 (0, "What would you like to do?", "a"),
21 (0, "Whom would you like to awaken?", ""),
24 test_account1_setup = (
25 (1, "Identify yourself:", "luser1"),
26 (1, "Enter your choice:", "n"),
27 (1, "Enter a new password for \"luser1\":", "Test456"),
28 (1, "Enter the same new password again:", "Test456"),
29 (1, "What would you like to do\?", "c"),
30 (1, "Pick a birth gender for your new avatar:", "m"),
31 (1, "Choose a name for him:", "1"),
32 (1, "What would you like to do?", "a"),
33 (1, "Whom would you like to awaken?", ""),
36 test_actor_appears = (
37 (0, "You suddenly realize that .* is here\.", ""),
40 test_explicit_punctuation = (
41 (0, "> ", "say Hello there!"),
42 (0, 'You exclaim, "Hello there\!"', ""),
43 (1, 'exclaims, "Hello there\!"', "say And you are?"),
44 (1, 'You ask, "And you are\?"', ""),
45 (0, 'asks, "And you are\?"', "say I'm me, of course."),
46 (0, 'You say, "I\'m me, of course\."', ""),
47 (1, 'says, "I\'m me, of course\."', "say I wouldn't be so sure..."),
48 (1, 'You muse, "I wouldn\'t be so sure\.\.\."', ""),
49 (0, 'muses, "I wouldn\'t be so sure\.\.\."', "say You mean,"),
50 (0, 'You begin, "You mean,"', ""),
51 (1, 'begins, "You mean,"', "say I know-"),
52 (1, 'You begin, "I know-"', ""),
53 (0, 'begins, "I know-"', "say Don't interrupt:"),
54 (0, 'You begin, "Don\'t interrupt:"', ""),
55 (1, 'begins, "Don\'t interrupt:"', "say I wasn't interrupting;"),
56 (1, 'You begin, "I wasn\'t interrupting;"', ""),
57 (0, 'begins, "I wasn\'t interrupting;"', ""),
60 test_implicit_punctuation = (
61 (0, '> ', "say Whatever"),
62 (0, 'You say, "Whatever\."', ""),
63 (1, 'says, "Whatever\."', ""),
66 test_typo_replacement = (
67 (1, '> ', "say That's what i think."),
68 (1, 'You say, "That\'s what I think\."', ""),
69 (0, 'says, "That\'s what I think\."', "say You know what i'd like."),
70 (0, 'You say, "You know what I\'d like\."', ""),
71 (1, 'says, "You know what I\'d like\."', "say Then i'll tell you."),
72 (1, 'You say, "Then I\'ll tell you\."', ""),
73 (0, 'says, "Then I\'ll tell you\."', "say Now i'm ready."),
74 (0, 'You say, "Now I\'m ready\."', ""),
75 (1, 'says, "Now I\'m ready\."', "say That's teh idea."),
76 (1, 'You say, "That\'s the idea\."', ""),
77 (0, 'says, "That\'s the idea\."', "say It's what theyre saying."),
78 (0, 'You say, "It\'s what they\'re saying\."', ""),
79 (1, 'says, "It\'s what they\'re saying\."', "say Well, youre right."),
80 (1, 'You say, "Well, you\'re right\."', ""),
81 (0, 'says, "Well, you\'re right\."', ""),
84 test_sentence_capitalization = (
85 (0, "> ", "say this sentence should start with a capital T."),
86 (0, 'You say, "This sentence', ""),
87 (1, 'says, "This sentence', ""),
92 (1, '(?s)Entering chat mode .*> \(chat\) ', "Feeling chatty."),
93 (1, 'You say, "Feeling chatty\."', "!chat"),
94 (0, 'says, "Feeling chatty\."', ""),
95 (1, '> ', "say Now less chatty."),
96 (1, 'You say, "Now less chatty\."', ""),
97 (0, 'says, "Now less chatty\."', ""),
101 (0, "> ", "move north"),
102 (0, "You exit to the north\.", ""),
103 (1, "exits to the north\.", "move north"),
104 (0, "arrives from the south\.", "move south"),
105 (0, "You exit to the south\.", ""),
106 (1, "exits to the south\.", "move south"),
107 (0, "arrives from the north\.", "move east"),
108 (0, "You exit to the east\.", ""),
109 (1, "exits to the east\.", "move east"),
110 (0, "arrives from the west\.", "move west"),
111 (0, "You exit to the west\.", ""),
112 (1, "exits to the west\.", "move west"),
113 (0, "arrives from the east\.", "move up"),
114 (0, "You exit upward\.", ""),
115 (1, "exits upward\.", "move up"),
116 (0, "arrives from below\.", "move down"),
117 (0, "You exit downward\.", ""),
118 (1, "exits downward\.", "move down"),
119 (0, "arrives from above\.", ""),
122 test_actor_disappears = (
124 (0, "You suddenly wonder where .* went\.", ""),
127 test_account1_teardown = (
128 (1, "What would you like to do?", "d"),
129 (1, "Whom would you like to delete?", ""),
130 (1, "What would you like to do?", "p"),
131 (1, "permanently delete your account?", "y"),
132 (1, "Disconnecting...", ""),
136 (2, "Identify yourself:", "testadmin"),
137 (2, "Enter your choice:", "n"),
138 (2, "Enter a new password for \"testadmin\":", "Test789"),
139 (2, "Enter the same new password again:", "Test789"),
140 (2, "What would you like to do\?", "c"),
141 (2, "Pick a birth gender for your new avatar:", "m"),
142 (2, "Choose a name for him:", "1"),
143 (2, "What would you like to do?", "a"),
144 (2, "Whom would you like to awaken?", ""),
147 test_admin_restriction = (
148 (0, "> ", "help halt"),
149 (0, "That is not an available command\.", "halt"),
150 (0, '(not sure what "halt" means|Arglebargle, glop-glyf)', ""),
155 (2, "halt.*Shut down the world\.", "help halt"),
156 (2, "This will save all active accounts", ""),
160 (2, "> ", "show log"),
161 (2, "There are [0-9]+ log lines in memory and [0-9]+ at or above level "
162 "[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
165 test_log_no_errors = (
166 (2, "> ", "show log 7"),
167 (2, "None of the [0-9]+ lines in memory matches your request\.", ""),
171 (test_account0_setup, "first account setup"),
172 (test_account1_setup, "second account setup"),
173 (test_actor_appears, "actor spontaneous appearance"),
174 (test_explicit_punctuation, " explicit punctuation"),
175 (test_implicit_punctuation, "implicit punctuation"),
176 (test_typo_replacement, "typo replacement"),
177 (test_sentence_capitalization, "sentence capitalization"),
178 (test_chat_mode, "chat mode"),
179 (test_movement, "movement"),
180 (test_actor_disappears, "actor spontaneous disappearance"),
181 (test_account1_teardown, "second account teardown"),
182 (test_admin_setup, "admin account setup"),
183 (test_admin_restriction, "restricted admin commands"),
184 (test_admin_help, "admin help"),
185 (test_show_log, "show log"),
186 (test_log_no_errors, "no errors logged"),
189 captures = ["", "", ""]
190 lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()]
194 luser.open("::1", 6669)
195 for test, description in dialogue:
196 print("\nTesting %s..." % description)
197 test_start = time.time()
198 for conversant, question, answer in test:
199 print("luser%s waiting for: %s" % (conversant, question))
200 index, match, received = lusers[conversant].expect(
201 [question.encode("utf-8")], 5)
202 captures[conversant] += received.decode("utf-8")
204 captures[conversant] += lusers[
205 conversant].read_very_eager().decode("utf-8")
209 print("ERROR: luser%s did not receive expected string:\n\n%s\n\n"
210 "Check the end of capture_%s.log for received data."
211 % (conversant, question, conversant))
214 print("luser%s sending: %s" % (conversant, answer))
215 lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
216 captures[conversant] += "%s\r\n" % answer
219 print("Completed in %.3f seconds." % (time.time() - test_start))
220 duration = time.time() - start
222 for conversant in range(len(captures)):
224 captures[conversant] += lusers[
225 conversant].read_very_eager().decode("utf-8")
228 lusers[conversant].close()
229 logfile = "capture_%s.log" % conversant
230 print("Recording session %s as %s." % (conversant, logfile))
231 log = open(logfile, "w")
232 log.write(captures[conversant])
234 print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration))