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 (test_account0_setup, "first account setup"),
161 (test_account1_setup, "second account setup"),
162 (test_actor_appears, "actor spontaneous appearance"),
163 (test_explicit_punctuation, " explicit punctuation"),
164 (test_implicit_punctuation, "implicit punctuation"),
165 (test_typo_replacement, "typo replacement"),
166 (test_sentence_capitalization, "sentence capitalization"),
167 (test_chat_mode, "chat mode"),
168 (test_movement, "movement"),
169 (test_actor_disappears, "actor spontaneous disappearance"),
170 (test_account1_teardown, "second account teardown"),
171 (test_admin_setup, "admin account setup"),
172 (test_admin_restriction, "restricted admin commands"),
173 (test_admin_help, "admin help"),
176 captures = ["", "", ""]
177 lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()]
181 luser.open("::1", 6669)
182 for test, description in dialogue:
183 print("\nTesting %s..." % description)
184 test_start = time.time()
185 for conversant, question, answer in test:
186 print("luser%s waiting for: %s" % (conversant, question))
187 index, match, received = lusers[conversant].expect(
188 [question.encode("utf-8")], 5)
189 captures[conversant] += received.decode("utf-8")
191 captures[conversant] += lusers[
192 conversant].read_very_eager().decode("utf-8")
196 print("ERROR: luser%s did not receive expected string:\n\n%s\n\n"
197 "Check the end of capture_%s.log for received data."
198 % (conversant, question, conversant))
201 print("luser%s sending: %s" % (conversant, answer))
202 lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
203 captures[conversant] += "%s\r\n" % answer
206 print("Completed in %.3f seconds." % (time.time() - test_start))
207 duration = time.time() - start
209 for conversant in range(len(captures)):
211 captures[conversant] += lusers[
212 conversant].read_very_eager().decode("utf-8")
215 lusers[conversant].close()
216 logfile = "capture_%s.log" % conversant
217 print("Recording session %s as %s." % (conversant, logfile))
218 log = open(logfile, "w")
219 log.write(captures[conversant])
221 print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration))