From b0c1e3fd80a7a7199d7a78a1abbd35492435e838 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 9 May 2015 11:45:03 +0000 Subject: [PATCH] Lay groundwork for more thorough functional tests Make bin/test support an arbitrary number of connections, be more verbose about what it's doing, and archive complete captures of each session involved. --- .gitignore | 1 + bin/test | 74 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 37a6926..4c982d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +capture_*.log data/ lib/mudpy/__pycache__/ test_config.yaml 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) -- 2.11.0