X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;f=bin%2Ftest;h=0ceb4ebc4ced573ae1d1931b34e36e6ad36356e9;hb=b0c1e3fd80a7a7199d7a78a1abbd35492435e838;hp=8e5939bbec919149c3006f2c1d406bcfbd1c7832;hpb=3a6185cccba6b7af5725d2767d0c57de05f9fac5;p=mudpy.git diff --git a/bin/test b/bin/test index 8e5939b..0ceb4eb 100755 --- a/bin/test +++ b/bin/test @@ -1,33 +1,63 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -u"""Regression test script for the mudpy engine.""" +"""Regression test script for the mudpy engine.""" -# Copyright (c) 2004-2010 Jeremy Stanley . Permission +# 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. -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 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..." , "" ), +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...", ""), ) -import telnetlib -mud = telnetlib.Telnet() -mud.open("::1",6669) -for question,answer in conversation: - mud.read_until("%s " % question) - mud.write("%s\r\n" % answer) -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)