Test actor movement
[mudpy.git] / bin / test
1 #!/usr/bin/env python
2 """Regression test script for the mudpy engine."""
3
4 # Copyright (c) 2004-2015 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.
7
8 import sys
9 import telnetlib
10 import time
11
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?", ""),
22 )
23
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?", ""),
34 )
35
36 test_actor_appears = (
37     (0, "You suddenly realize that .* is here\.", ""),
38 )
39
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;"', ""),
58 )
59
60 test_implicit_punctuation = (
61     (0, '> ', "say Whatever"),
62     (0, 'You say, "Whatever\."', ""),
63     (1, 'says, "Whatever\."', ""),
64 )
65
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\."', ""),
82 )
83
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', ""),
88 )
89
90 test_chat_mode = (
91     (1, '> ', "chat"),
92     (1, '> \(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\."', ""),
98 )
99
100 test_movement = (
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\.", ""),
120 )
121
122 test_actor_disappears = (
123     (1, "> ", "quit"),
124     (0, "You suddenly wonder where .* went\.", ""),
125 )
126
127 test_account0_teardown = (
128     (0, "> ", "quit"),
129     (0, "What would you like to do?", "d"),
130     (0, "Whom would you like to delete?", ""),
131     (0, "What would you like to do?", "p"),
132     (0, "permanently delete your account?", "y"),
133     (0, "Disconnecting...", ""),
134 )
135
136 test_account1_teardown = (
137     (1, "What would you like to do?", "d"),
138     (1, "Whom would you like to delete?", ""),
139     (1, "What would you like to do?", "p"),
140     (1, "permanently delete your account?", "y"),
141     (1, "Disconnecting...", ""),
142 )
143
144 dialogue = (
145     (test_account0_setup, "first account setup"),
146     (test_account1_setup, "second account setup"),
147     (test_actor_appears, "actor spontaneous appearance"),
148     (test_explicit_punctuation, " explicit punctuation"),
149     (test_implicit_punctuation, "implicit punctuation"),
150     (test_typo_replacement, "typo replacement"),
151     (test_sentence_capitalization, "sentence capitalization"),
152     (test_chat_mode, "chat mode"),
153     (test_movement, "movement"),
154     (test_actor_disappears, "actor spontaneous disappearance"),
155     (test_account0_teardown, "first account teardown"),
156     (test_account1_teardown, "second account teardown"),
157 )
158
159 captures = ["", ""]
160 lusers = [telnetlib.Telnet(), telnetlib.Telnet()]
161 success = True
162 start = time.time()
163 for luser in lusers:
164     luser.open("::1", 6669)
165 for test, description in dialogue:
166     print("\nTesting %s..." % description)
167     test_start = time.time()
168     for conversant, question, answer in test:
169         print("luser%s waiting for: %s" % (conversant, question))
170         index, match, received = lusers[conversant].expect(
171             [question.encode("utf-8")], 5)
172         captures[conversant] += received.decode("utf-8")
173         try:
174             captures[conversant] += lusers[
175                 conversant].read_very_eager().decode("utf-8")
176         except:
177             pass
178         if index is not 0:
179             print("ERROR: luser%s did not receive expected string:\n\n%s\n\n"
180                   "Check the end of capture_%s.log for received data."
181                   % (conversant, question, conversant))
182             success = False
183             break
184         print("luser%s sending: %s" % (conversant, answer))
185         lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
186         captures[conversant] += "%s\r\n" % answer
187     if not success:
188         break
189     print("Completed in %.3f seconds." % (time.time() - test_start))
190 duration = time.time() - start
191 print("")
192 for conversant in range(len(captures)):
193     try:
194         captures[conversant] += lusers[
195             conversant].read_very_eager().decode("utf-8")
196     except:
197         pass
198     lusers[conversant].close()
199     logfile = "capture_%s.log" % conversant
200     print("Recording session %s as %s." % (conversant, logfile))
201     log = open(logfile, "w")
202     log.write(captures[conversant])
203     log.close()
204 print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration))
205 if success:
206     print("SUCCESS")
207 else:
208     print("FAILURE")
209     sys.exit(1)