Lay groundwork for more thorough functional tests
[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
11 dialogue = (
12     # Create account 0
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     # Quit
24     (0, "> ", "quit"),
25
26     # Delete account 0
27     (0, "What would you like to do?", "d"),
28     (0, "Whom would you like to delete?", ""),
29     (0, "What would you like to do?", "p"),
30     (0, "permanently delete your account?", "y"),
31     (0, "Disconnecting...", ""),
32 )
33
34 captures = ["", ""]
35 lusers = [telnetlib.Telnet(), telnetlib.Telnet()]
36 success = True
37 for luser in lusers:
38     luser.open("::1", 6669)
39 for conversant, question, answer in dialogue:
40     print("luser%s waiting for: %s" % (conversant, question))
41     index, match, received = lusers[conversant].expect(
42         [question.encode("utf-8")], 5)
43     captures[conversant] += received.decode("utf-8")
44     if index is not 0:
45         print("ERROR: luser%s did not receive expected string:\n\n%s"
46               % (conversant, question))
47         success = False
48         break
49     print("luser%s sending: %s" % (conversant, answer))
50     lusers[conversant].write(("%s\r\n" % answer).encode("utf-8"))
51     captures[conversant] += "%s\r\n" % answer
52 for conversant in range(len(captures)):
53     try:
54         captures[conversant] += lusers[
55             conversant].read_very_eager().decode("utf-8")
56     except:
57         pass
58     lusers[conversant].close()
59     log = open("capture_%s.log" % conversant, "w")
60     log.write(captures[conversant])
61     log.close()
62 if not success:
63     sys.exit(1)