-#!/usr/bin/env python3
-"""Regression test script for the mudpy engine."""
-
-# Copyright (c) 2004-2016 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-2017 Jeremy Stanley <fungi@yuggoth.org>. Permission
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
(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(
- [re.compile(question.encode("utf-8"), flags=re.DOTALL)], 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())