#!/usr/bin/env python """Regression test script for the mudpy engine.""" # Copyright (c) 2004-2015 Jeremy Stanley . Permission # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. import sys import telnetlib dialogue = ( # Create account 0 (0, "Identify yourself:", "luser0"), (0, "Enter your choice:", "n"), (0, "Enter a new password for \"luser0\":", "Test123"), (0, "Enter the same new password again:", "Test123"), (0, "What would you like to do\?", "c"), (0, "Pick a birth gender for your new avatar:", "f"), (0, "Choose a name for her:", "1"), (0, "What would you like to do?", "a"), (0, "Whom would you like to awaken?", ""), # Quit (0, "> ", "quit"), # Delete account 0 (0, "What would you like to do?", "d"), (0, "Whom would you like to delete?", ""), (0, "What would you like to do?", "p"), (0, "permanently delete your account?", "y"), (0, "Disconnecting...", ""), ) captures = ["", ""] lusers = [telnetlib.Telnet(), telnetlib.Telnet()] success = True for luser in lusers: luser.open("::1", 6669) for conversant, question, answer in dialogue: print("luser%s waiting for: %s" % (conversant, question)) index, match, received = lusers[conversant].expect( [question.encode("utf-8")], 5) captures[conversant] += received.decode("utf-8") if index is not 0: print("ERROR: luser%s did not receive expected string:\n\n%s" % (conversant, question)) success = False break print("luser%s sending: %s" % (conversant, answer)) lusers[conversant].write(("%s\r\n" % answer).encode("utf-8")) captures[conversant] += "%s\r\n" % answer for conversant in range(len(captures)): try: captures[conversant] += lusers[ conversant].read_very_eager().decode("utf-8") except: pass lusers[conversant].close() log = open("capture_%s.log" % conversant, "w") log.write(captures[conversant]) log.close() if not success: sys.exit(1)