X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=bin%2Ftest;h=d246cfeaef44730797464bcc7ed044c4603715fd;hp=37e81000b9ba00ec57f2e1a5427fc77260f29820;hb=2e63544e800a2465ced646a7a044412a9ded0957;hpb=0cda64117ac0b79b8c8f16a37ec3f9316f4c4d16 diff --git a/bin/test b/bin/test index 37e8100..d246cfe 100755 --- a/bin/test +++ b/bin/test @@ -1,10 +1,8 @@ -#!/usr/bin/env python3 -"""Regression test script for the mudpy engine.""" - -# Copyright (c) 2004-2016 Jeremy Stanley . Permission +# Copyright (c) 2004-2017 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 re import sys import telnetlib import time @@ -156,6 +154,13 @@ test_admin_help = ( (2, "This will save all active accounts", ""), ) +test_show_element = ( + (2, "> ", "show element internal:counters"), + (2, "These are the properties of the \"internal:counters\" element " + "\(in.*data/internal\.yaml\"\):.* \x1b\[32melapsed: " + "\x1b\[31m[0-9]+\x1b\[0m", ""), +) + test_show_log = ( (2, "> ", "show log"), (2, "There are [0-9]+ log lines in memory and [0-9]+ at or above level " @@ -182,58 +187,66 @@ dialogue = ( (test_admin_setup, "admin account setup"), (test_admin_restriction, "restricted admin commands"), (test_admin_help, "admin help"), + (test_show_element, "show element"), (test_show_log, "show log"), (test_log_no_errors, "no errors logged"), ) -captures = ["", "", ""] -lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()] -success = True -start = time.time() -for luser in lusers: - luser.open("::1", 6669) -for test, description in dialogue: - print("\nTesting %s..." % description) - test_start = time.time() - for conversant, question, answer in test: - 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") + +def main(): + captures = ["", "", ""] + lusers = [telnetlib.Telnet(), telnetlib.Telnet(), telnetlib.Telnet()] + success = True + start = time.time() + for luser in lusers: + luser.open("::1", 6669) + for test, description in dialogue: + print("\nTesting %s..." % description) + test_start = time.time() + for conversant, question, answer in test: + print("luser%s waiting for: %s" % (conversant, question)) + index, match, received = lusers[conversant].expect( + [re.compile(question.encode("utf-8"), flags=re.DOTALL)], 5) + captures[conversant] += received.decode("utf-8") + try: + captures[conversant] += lusers[ + conversant].read_very_eager().decode("utf-8") + except: + pass + if index is not 0: + print("ERROR: luser%s did not receive expected string:\n\n" + "%s\n\n" + "Check the end of capture_%s.log for received data." + % (conversant, question, conversant)) + 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 + if not success: + break + print("Completed in %.3f seconds." % (time.time() - test_start)) + duration = time.time() - start + print("") + for conversant in range(len(captures)): try: captures[conversant] += lusers[ conversant].read_very_eager().decode("utf-8") except: pass - if index is not 0: - print("ERROR: luser%s did not receive expected string:\n\n%s\n\n" - "Check the end of capture_%s.log for received data." - % (conversant, question, conversant)) - 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 - if not success: - break - print("Completed in %.3f seconds." % (time.time() - test_start)) -duration = time.time() - start -print("") -for conversant in range(len(captures)): - try: - captures[conversant] += lusers[ - conversant].read_very_eager().decode("utf-8") - except: - pass - lusers[conversant].close() - logfile = "capture_%s.log" % conversant - print("Recording session %s as %s." % (conversant, logfile)) - log = open(logfile, "w") - log.write(captures[conversant]) - log.close() -print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration)) -if success: - print("SUCCESS") -else: - print("FAILURE") - sys.exit(1) + lusers[conversant].close() + logfile = "capture_%s.log" % conversant + print("Recording session %s as %s." % (conversant, logfile)) + log = open(logfile, "w") + log.write(captures[conversant]) + log.close() + print("\nRan %s tests in %.3f seconds." % (len(dialogue), duration)) + if success: + print("SUCCESS") + else: + print("FAILURE") + sys.exit(1) + + +if __name__ == '__main__': + sys.exit(main())