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.
11 test_account0_setup = (
12 (0, "Identify yourself:", "luser0"),
13 (0, "Enter your choice:", "n"),
14 (0, 'Enter a new password for "luser0":', "Test123"),
15 (0, "Enter the same new password again:", "Test123"),
16 (0, r"What would you like to do\?", "c"),
17 (0, "Pick a birth gender for your new avatar:", "f"),
18 (0, "Choose a name for her:", "1"),
19 (0, "What would you like to do?", "a"),
20 (0, "Whom would you like to awaken?", ""),
23 test_account1_setup = (
24 (1, "Identify yourself:", "luser1"),
25 (1, "Enter your choice:", "n"),
26 (1, 'Enter a new password for "luser1":', "Test456"),
27 (1, "Enter the same new password again:", "Test456"),
28 (1, r"What would you like to do\?", "c"),
29 (1, "Pick a birth gender for your new avatar:", "m"),
30 (1, "Choose a name for him:", "1"),
31 (1, "What would you like to do?", "a"),
32 (1, "Whom would you like to awaken?", ""),
35 test_actor_appears = (
36 (0, r"You suddenly realize that .* is here\.", ""),
39 test_explicit_punctuation = (
40 (0, "> ", "say Hello there!"),
41 (0, r'You exclaim, "Hello there\!"', ""),
42 (1, r'exclaims, "Hello there\!"', "say And you are?"),
43 (1, r'You ask, "And you are\?"', ""),
44 (0, r'asks, "And you are\?"', "say I'm me, of course."),
45 (0, r'''You say, "I'm me, of course\."''', ""),
46 (1, r'''says, "I'm me, of course\."''', "say I wouldn't be so sure..."),
47 (1, r'''You muse, "I wouldn't be so sure\.\.\."''', ""),
48 (0, r'''muses, "I wouldn't be so sure\.\.\."''', "say You mean,"),
49 (0, 'You begin, "You mean,"', ""),
50 (1, 'begins, "You mean,"', "say I know-"),
51 (1, 'You begin, "I know-"', ""),
52 (0, 'begins, "I know-"', "say Don't interrupt:"),
53 (0, r'''You begin, "Don't interrupt:"''', ""),
54 (1, r'''begins, "Don't interrupt:"''', "say I wasn't interrupting;"),
55 (1, r'''You begin, "I wasn't interrupting;"''', ""),
56 (0, r'''begins, "I wasn't interrupting;"''', ""),
59 test_implicit_punctuation = (
60 (0, '> ', "say Whatever"),
61 (0, r'You say, "Whatever\."', ""),
62 (1, r'says, "Whatever\."', ""),
65 test_typo_replacement = (
66 (1, '> ', "say That's what i think."),
67 (1, r'''You say, "That's what I think\."''', ""),
68 (0, r'''says, "That's what I think\."''', "say You know what i'd like."),
69 (0, r'''You say, "You know what I'd like\."''', ""),
70 (1, r'''says, "You know what I'd like\."''', "say Then i'll tell you."),
71 (1, r'''You say, "Then I'll tell you\."''', ""),
72 (0, r'''says, "Then I'll tell you\."''', "say Now i'm ready."),
73 (0, r'''You say, "Now I'm ready\."''', ""),
74 (1, r'''says, "Now I'm ready\."''', "say That's teh idea."),
75 (1, r'''You say, "That's the idea\."''', ""),
76 (0, r'''says, "That's the idea\."''', "say It's what theyre saying."),
77 (0, r'''You say, "It's what they're saying\."''', ""),
78 (1, r'''says, "It's what they're saying\."''', "say Well, youre right."),
79 (1, r'''You say, "Well, you're right\."''', ""),
80 (0, r'''says, "Well, you're right\."''', ""),
83 test_sentence_capitalization = (
84 (0, "> ", "say this sentence should start with a capital T."),
85 (0, 'You say, "This sentence', ""),
86 (1, 'says, "This sentence', ""),
91 (1, r'(?s)Entering chat mode .*> \(chat\) ', "Feeling chatty."),
92 (1, r'You say, "Feeling chatty\."', "!chat"),
93 (0, r'says, "Feeling chatty\."', ""),
94 (1, '> ', "say Now less chatty."),
95 (1, r'You say, "Now less chatty\."', ""),
96 (0, r'says, "Now less chatty\."', ""),
100 (0, "> ", "move north"),
101 (0, r"You exit to the north\.", ""),
102 (1, r"exits to the north\.", "move north"),
103 (0, r"arrives from the south\.", "move south"),
104 (0, r"You exit to the south\.", ""),
105 (1, r"exits to the south\.", "move south"),
106 (0, r"arrives from the north\.", "move east"),
107 (0, r"You exit to the east\.", ""),
108 (1, r"exits to the east\.", "move east"),
109 (0, r"arrives from the west\.", "move west"),
110 (0, r"You exit to the west\.", ""),
111 (1, r"exits to the west\.", "move west"),
112 (0, r"arrives from the east\.", "move up"),
113 (0, r"You exit upward\.", ""),
114 (1, r"exits upward\.", "move up"),
115 (0, r"arrives from below\.", "move down"),
116 (0, r"You exit downward\.", ""),
117 (1, r"exits downward\.", "move down"),
118 (0, r"arrives from above\.", ""),
121 test_actor_disappears = (
123 (0, r"You suddenly wonder where .* went\.", ""),
126 test_account1_teardown = (
127 (1, "What would you like to do?", "d"),
128 (1, "Whom would you like to delete?", ""),
129 (1, "What would you like to do?", "p"),
130 (1, "permanently delete your account?", "y"),
131 (1, "Disconnecting...", ""),
135 (2, "Identify yourself:", "admin"),
136 (2, "Enter your choice:", "n"),
137 (2, 'Enter a new password for "admin":', "Test789"),
138 (2, "Enter the same new password again:", "Test789"),
139 (2, r"What would you like to do\?", "c"),
140 (2, "Pick a birth gender for your new avatar:", "m"),
141 (2, "Choose a name for him:", "1"),
142 (2, "What would you like to do?", "a"),
143 (2, "Whom would you like to awaken?", ""),
146 test_admin_restriction = (
147 (0, "> ", "help halt"),
148 (0, r"That is not an available command\.", "halt"),
149 (0, '(not sure what "halt" means|Arglebargle, glop-glyf)', ""),
154 (2, r"halt.*Shut down the world\.", "help halt"),
155 (2, "This will save all active accounts", ""),
160 (2, r"Reloading all code modules, configs and data\."
161 r".* User admin reloaded the world\.", ""),
165 (2, "> ", "set actor.avatar_admin_0 gender female"),
166 (2, r'You have successfully \(re\)set the "gender" facet of element', ""),
170 (2, "> ", "set mudpy.limit password_tries 10"),
171 (2, r'The "mudpy\.limit" element is kept in read-only file', ""),
175 (2, "> ", "show files"),
176 (2, r'These are the current files containing the universe:.*'
177 r' \x1b\[31m\(rw\) \x1b\[32m/.*/account.yaml\x1b\[0m'
178 r' \x1b\[33m\[private\]\x1b\[0m.*> ', ""),
182 (2, "> ", "show file %s" %
183 os.path.join(os.getcwd(), "data/internal.yaml")),
184 (2, r'These are the nodes in the.*file:.*internal\.counters.*> ', ""),
188 (2, "> ", "show groups"),
189 (2, r'These are the element groups:.*'
190 r' \x1b\[32maccount\x1b\[0m.*> ', ""),
194 (2, "> ", "show group account"),
195 (2, r'These are the elements in the "account" group:.*'
196 r' \x1b\[32maccount\.admin\x1b\[0m.*> ', ""),
199 test_show_element = (
200 (2, "> ", "show element mudpy.limit"),
201 (2, r'These are the properties of the "mudpy\.limit" element.*'
202 r' \x1b\[32mpassword_tries: \x1b\[31m3.*> ',
203 "show element actor.avatar_admin_0"),
204 (2, r'These are the properties of the "actor.avatar_admin_0" element.*'
205 r' \x1b\[32mgender: \x1b\[31mfemale.*> ', ""),
209 (2, "> ", "show log"),
210 (2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
211 r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
214 test_custom_loglevel = (
215 (2, "> ", "set account.admin loglevel 2"),
216 (2, "You have successfully .*> ", "show log"),
217 (2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
218 r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
221 test_invalid_loglevel = (
222 (2, "> ", "set account.admin loglevel two"),
223 (2, r'''Value "two" of type "<class 'str'>" cannot be coerced .*> ''', ""),
226 test_log_no_errors = (
227 (2, "> ", "show log 7"),
228 (2, r"None of the [0-9]+ lines in memory matches your request\.", ""),
232 (test_account0_setup, "first account setup"),
233 (test_account1_setup, "second account setup"),
234 (test_actor_appears, "actor spontaneous appearance"),
235 (test_explicit_punctuation, " explicit punctuation"),
236 (test_implicit_punctuation, "implicit punctuation"),
237 (test_typo_replacement, "typo replacement"),
238 (test_sentence_capitalization, "sentence capitalization"),
239 (test_chat_mode, "chat mode"),
240 (test_movement, "movement"),
241 (test_actor_disappears, "actor spontaneous disappearance"),
242 (test_account1_teardown, "second account teardown"),
243 (test_admin_setup, "admin account setup"),
244 (test_admin_restriction, "restricted admin commands"),
245 (test_admin_help, "admin help"),
246 (test_reload, "reload"),
247 (test_set_facet, "set facet"),
248 (test_set_refused, "refuse altering read-only element"),
249 (test_show_files, "show a list of loaded files"),
250 (test_show_file, "show nodes from a specific file"),
251 (test_show_groups, "show groups"),
252 (test_show_group, "show group"),
253 (test_show_element, "show element"),
254 (test_show_log, "show log"),
255 (test_custom_loglevel, "custom loglevel"),
256 (test_invalid_loglevel, "invalid loglevel"),
257 (test_log_no_errors, "no errors logged"),
262 captures = ["", "", ""]
263 lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()]
267 luser.open("::1", 4000)
268 for test, description in dialogue:
269 print("\nTesting %s..." % description)
270 test_start = time.time()
271 for conversant, question, answer in test:
272 print("luser%s waiting for: %s" % (conversant, question))
274 index, match, received = lusers[conversant].expect(
275 [re.compile(question.encode("utf-8"), flags=re.DOTALL)], 5)
276 captures[conversant] += received.decode("utf-8")
277 except ConnectionResetError:
278 print("ERROR: Unable to connect to server.")
282 print("ERROR: luser%s premature disconnection expecting:\n\n"
284 "Check the end of capture_%s.log for received data."
285 % (conversant, question, conversant))
289 captures[conversant] += lusers[
290 conversant].read_very_eager().decode("utf-8")
294 print("ERROR: luser%s did not receive expected string:\n\n"
296 "Check the end of capture_%s.log for received data."
297 % (conversant, question, conversant))
300 print("luser%s sending: %s" % (conversant, answer))
301 lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
302 captures[conversant] += "%s\r\n" % answer
305 print("Completed in %.3f seconds." % (time.time() - test_start))
306 duration = time.time() - start
308 for conversant in range(len(captures)):
310 captures[conversant] += lusers[
311 conversant].read_very_eager().decode("utf-8")
314 lusers[conversant].close()
315 logfile = "capture_%s.log" % conversant
316 print("Recording session %s as %s." % (conversant, logfile))
317 log = open(logfile, "w")
318 log.write(captures[conversant])
320 print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration))
328 if __name__ == '__main__':