X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=bin%2Ftest;h=0ceb4ebc4ced573ae1d1931b34e36e6ad36356e9;hp=22dce68fee20fb2d150929e34a0a0ea77d6e128c;hb=b0c1e3fd80a7a7199d7a78a1abbd35492435e838;hpb=7e78772b5ba2efbb84710db0ecd540c9b745217a diff --git a/bin/test b/bin/test index 22dce68..0ceb4eb 100755 --- a/bin/test +++ b/bin/test @@ -5,29 +5,59 @@ # 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 -conversation = ( - ("Identify yourself:", "testuser"), - ("Enter your choice:", "n"), - ("Enter a new password for \"testuser\":", "Test123"), - ("Enter the same new password again:", "Test123"), - ("What would you like to do?", "c"), - ("Pick a birth gender for your new avatar:", "f"), - ("Choose a name for her:", "1"), - ("What would you like to do?", "a"), - ("Whom would you like to awaken?", ""), - (">", "quit"), - ("What would you like to do?", "d"), - ("Whom would you like to delete?", ""), - ("What would you like to do?", "p"), - ("permanently delete your account?", "y"), - ("Disconnecting...", ""), +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...", ""), ) -mud = telnetlib.Telnet() -mud.open("::1", 6669) -for question, answer in conversation: - mud.read_until(("%s " % question).encode("utf-8")) - mud.write(("%s\r\n" % answer).encode("utf-8")) -mud.close() +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)