1 # Copyright (c) 2004-2017 Jeremy Stanley <fungi@yuggoth.org>. Permission
2 # to use, copy, modify, and distribute this software is granted under
3 # terms provided in the LICENSE file distributed with this software.
10 test_account0_setup = (
11 (0, "Identify yourself:", "luser0"),
12 (0, "Enter your choice:", "n"),
13 (0, 'Enter a new password for "luser0":', "Test123"),
14 (0, "Enter the same new password again:", "Test123"),
15 (0, r"What would you like to do\?", "c"),
16 (0, "Pick a birth gender for your new avatar:", "f"),
17 (0, "Choose a name for her:", "1"),
18 (0, "What would you like to do?", "a"),
19 (0, "Whom would you like to awaken?", ""),
22 test_account1_setup = (
23 (1, "Identify yourself:", "luser1"),
24 (1, "Enter your choice:", "n"),
25 (1, 'Enter a new password for "luser1":', "Test456"),
26 (1, "Enter the same new password again:", "Test456"),
27 (1, r"What would you like to do\?", "c"),
28 (1, "Pick a birth gender for your new avatar:", "m"),
29 (1, "Choose a name for him:", "1"),
30 (1, "What would you like to do?", "a"),
31 (1, "Whom would you like to awaken?", ""),
34 test_actor_appears = (
35 (0, r"You suddenly realize that .* is here\.", ""),
38 test_explicit_punctuation = (
39 (0, "> ", "say Hello there!"),
40 (0, r'You exclaim, "Hello there\!"', ""),
41 (1, r'exclaims, "Hello there\!"', "say And you are?"),
42 (1, r'You ask, "And you are\?"', ""),
43 (0, r'asks, "And you are\?"', "say I'm me, of course."),
44 (0, r'''You say, "I'm me, of course\."''', ""),
45 (1, r'''says, "I'm me, of course\."''', "say I wouldn't be so sure..."),
46 (1, r'''You muse, "I wouldn't be so sure\.\.\."''', ""),
47 (0, r'''muses, "I wouldn't be so sure\.\.\."''', "say You mean,"),
48 (0, 'You begin, "You mean,"', ""),
49 (1, 'begins, "You mean,"', "say I know-"),
50 (1, 'You begin, "I know-"', ""),
51 (0, 'begins, "I know-"', "say Don't interrupt:"),
52 (0, r'''You begin, "Don't interrupt:"''', ""),
53 (1, r'''begins, "Don't interrupt:"''', "say I wasn't interrupting;"),
54 (1, r'''You begin, "I wasn't interrupting;"''', ""),
55 (0, r'''begins, "I wasn't interrupting;"''', ""),
58 test_implicit_punctuation = (
59 (0, '> ', "say Whatever"),
60 (0, r'You say, "Whatever\."', ""),
61 (1, r'says, "Whatever\."', ""),
64 test_typo_replacement = (
65 (1, '> ', "say That's what i think."),
66 (1, r'''You say, "That's what I think\."''', ""),
67 (0, r'''says, "That's what I think\."''', "say You know what i'd like."),
68 (0, r'''You say, "You know what I'd like\."''', ""),
69 (1, r'''says, "You know what I'd like\."''', "say Then i'll tell you."),
70 (1, r'''You say, "Then I'll tell you\."''', ""),
71 (0, r'''says, "Then I'll tell you\."''', "say Now i'm ready."),
72 (0, r'''You say, "Now I'm ready\."''', ""),
73 (1, r'''says, "Now I'm ready\."''', "say That's teh idea."),
74 (1, r'''You say, "That's the idea\."''', ""),
75 (0, r'''says, "That's the idea\."''', "say It's what theyre saying."),
76 (0, r'''You say, "It's what they're saying\."''', ""),
77 (1, r'''says, "It's what they're saying\."''', "say Well, youre right."),
78 (1, r'''You say, "Well, you're right\."''', ""),
79 (0, r'''says, "Well, you're right\."''', ""),
82 test_sentence_capitalization = (
83 (0, "> ", "say this sentence should start with a capital T."),
84 (0, 'You say, "This sentence', ""),
85 (1, 'says, "This sentence', ""),
90 (1, r'(?s)Entering chat mode .*> \(chat\) ', "Feeling chatty."),
91 (1, r'You say, "Feeling chatty\."', "!chat"),
92 (0, r'says, "Feeling chatty\."', ""),
93 (1, '> ', "say Now less chatty."),
94 (1, r'You say, "Now less chatty\."', ""),
95 (0, r'says, "Now less chatty\."', ""),
99 (0, "> ", "move north"),
100 (0, r"You exit to the north\.", ""),
101 (1, r"exits to the north\.", "move north"),
102 (0, r"arrives from the south\.", "move south"),
103 (0, r"You exit to the south\.", ""),
104 (1, r"exits to the south\.", "move south"),
105 (0, r"arrives from the north\.", "move east"),
106 (0, r"You exit to the east\.", ""),
107 (1, r"exits to the east\.", "move east"),
108 (0, r"arrives from the west\.", "move west"),
109 (0, r"You exit to the west\.", ""),
110 (1, r"exits to the west\.", "move west"),
111 (0, r"arrives from the east\.", "move up"),
112 (0, r"You exit upward\.", ""),
113 (1, r"exits upward\.", "move up"),
114 (0, r"arrives from below\.", "move down"),
115 (0, r"You exit downward\.", ""),
116 (1, r"exits downward\.", "move down"),
117 (0, r"arrives from above\.", ""),
120 test_actor_disappears = (
122 (0, r"You suddenly wonder where .* went\.", ""),
125 test_account1_teardown = (
126 (1, "What would you like to do?", "d"),
127 (1, "Whom would you like to delete?", ""),
128 (1, "What would you like to do?", "p"),
129 (1, "permanently delete your account?", "y"),
130 (1, "Disconnecting...", ""),
134 (2, "Identify yourself:", "admin"),
135 (2, "Enter your choice:", "n"),
136 (2, 'Enter a new password for "admin":', "Test789"),
137 (2, "Enter the same new password again:", "Test789"),
138 (2, r"What would you like to do\?", "c"),
139 (2, "Pick a birth gender for your new avatar:", "m"),
140 (2, "Choose a name for him:", "1"),
141 (2, "What would you like to do?", "a"),
142 (2, "Whom would you like to awaken?", ""),
145 test_admin_restriction = (
146 (0, "> ", "help halt"),
147 (0, r"That is not an available command\.", "halt"),
148 (0, '(not sure what "halt" means|Arglebargle, glop-glyf)', ""),
153 (2, r"halt.*Shut down the world\.", "help halt"),
154 (2, "This will save all active accounts", ""),
159 (2, r"Reloading all code modules, configs and data\."
160 r".* User admin reloaded the world\.", ""),
163 test_show_element = (
164 (2, "> ", "show element mudpy.limit"),
165 (2, r'These are the properties of the "mudpy\.limit" element.*'
166 r' \x1b\[32mpassword_tries: \x1b\[31m[0-9]+.*> ',
167 "show element actor:avatar:admin:0"),
168 (2, r'These are the properties of the "actor:avatar:admin:0" element.*'
169 r' \x1b\[32mgender: \x1b\[31mmale.*> ', ""),
173 (2, "> ", "show log"),
174 (2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
175 r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
178 test_custom_loglevel = (
179 (2, "> ", "set account:admin loglevel 2"),
180 (2, "You have successfully .*> ", "show log"),
181 (2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
182 r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
185 test_invalid_loglevel = (
186 (2, "> ", "set account:admin loglevel two"),
187 (2, r'''Value "two" of type "<class 'str'>" cannot be coerced .*> ''', ""),
190 test_log_no_errors = (
191 (2, "> ", "show log 7"),
192 (2, r"None of the [0-9]+ lines in memory matches your request\.", ""),
196 (test_account0_setup, "first account setup"),
197 (test_account1_setup, "second account setup"),
198 (test_actor_appears, "actor spontaneous appearance"),
199 (test_explicit_punctuation, " explicit punctuation"),
200 (test_implicit_punctuation, "implicit punctuation"),
201 (test_typo_replacement, "typo replacement"),
202 (test_sentence_capitalization, "sentence capitalization"),
203 (test_chat_mode, "chat mode"),
204 (test_movement, "movement"),
205 (test_actor_disappears, "actor spontaneous disappearance"),
206 (test_account1_teardown, "second account teardown"),
207 (test_admin_setup, "admin account setup"),
208 (test_admin_restriction, "restricted admin commands"),
209 (test_admin_help, "admin help"),
210 (test_reload, "reload"),
211 (test_show_element, "show element"),
212 (test_show_log, "show log"),
213 (test_custom_loglevel, "custom loglevel"),
214 (test_invalid_loglevel, "invalid loglevel"),
215 (test_log_no_errors, "no errors logged"),
220 captures = ["", "", ""]
221 lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()]
225 luser.open("::1", 4000)
226 for test, description in dialogue:
227 print("\nTesting %s..." % description)
228 test_start = time.time()
229 for conversant, question, answer in test:
230 print("luser%s waiting for: %s" % (conversant, question))
231 index, match, received = lusers[conversant].expect(
232 [re.compile(question.encode("utf-8"), flags=re.DOTALL)], 5)
233 captures[conversant] += received.decode("utf-8")
235 captures[conversant] += lusers[
236 conversant].read_very_eager().decode("utf-8")
240 print("ERROR: luser%s did not receive expected string:\n\n"
242 "Check the end of capture_%s.log for received data."
243 % (conversant, question, conversant))
246 print("luser%s sending: %s" % (conversant, answer))
247 lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
248 captures[conversant] += "%s\r\n" % answer
251 print("Completed in %.3f seconds." % (time.time() - test_start))
252 duration = time.time() - start
254 for conversant in range(len(captures)):
256 captures[conversant] += lusers[
257 conversant].read_very_eager().decode("utf-8")
260 lusers[conversant].close()
261 logfile = "capture_%s.log" % conversant
262 print("Recording session %s as %s." % (conversant, logfile))
263 log = open(logfile, "w")
264 log.write(captures[conversant])
266 print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration))
274 if __name__ == '__main__':