tools/httptester/results.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/httptester/results.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +"""Store the results.
     1.9 +
    1.10 +Use a db, but we could do better"""
    1.11 +
    1.12 +import shelve
    1.13 +import string
    1.14 +
    1.15 +class results:
    1.16 +    def __init__(self, id):
    1.17 +        self.id = id
    1.18 +        self.d = shelve.open("data/"+id+".db")
    1.19 +
    1.20 +    def get_tester(self, path):
    1.21 +        import BaseTest
    1.22 +
    1.23 +        try:
    1.24 +            fname = path+"tester.py"
    1.25 +            text = open(fname).read()
    1.26 +            # Thanks to markh, for showing me how to do this
    1.27 +            # Python Is Cool.
    1.28 +            codeob = compile(text, fname, "exec")
    1.29 +            namespace = { 'BaseTester': BaseTest.tester }
    1.30 +            exec codeob in namespace, namespace
    1.31 +            tester = namespace['tester']()
    1.32 +        except IOError:
    1.33 +            tester =  BaseTest.tester()
    1.34 +
    1.35 +        if self.d.has_key(path):
    1.36 +            tester.__dict__ = self.d[path]
    1.37 +        else:
    1.38 +            tester.parse_config(open(path+"config"))
    1.39 +
    1.40 +        return tester
    1.41 +
    1.42 +    def set_tester(self, path, test):
    1.43 +        self.d[path] = test.__dict__
    1.44 +
    1.45 +    def write_report(self, file):
    1.46 +        for i in self.d.keys():
    1.47 +            file.write("%s: " % (i))
    1.48 +            tester = self.get_tester(i)
    1.49 +            res, detail = tester.result()
    1.50 +            if res:
    1.51 +                file.write("Pass!\n")
    1.52 +            else:
    1.53 +                file.write("Fail: %s\n" % (detail))
    1.54 +
    1.55 +    def __del__(self):
    1.56 +        self.d.close()

mercurial