Esempio n. 1
0
    def tester(*a, fakeServer=None):
        sys.argv = ["reqman.exe"] + list(a)

        f = FakeExeReturn()

        print(sys.argv)
        fo, fe = io.StringIO(), io.StringIO()
        with contextlib.redirect_stderr(fe):
            with contextlib.redirect_stdout(fo):
                rc = reqman.main(fakeServer=fakeServer, hookResults=f)

        output = fo.getvalue() + fe.getvalue()
        print(output)

        f.rc = rc
        f.console = output

        return f
Esempio n. 2
0
def main(runServer=False):
    """
    retourne 0 : si valid est ok
    retourne 1 : si valid est ko
    retourne None : si pas validation
    """
    class RR:
        pass

    o = RR()

    #check valid in argv -> valid
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    removeArgIdx = None
    valid = None
    for idx, argv in enumerate(sys.argv):
        if argv.startswith("valid:"):
            valid = argv[6:]
            removeArgIdx = idx
    if removeArgIdx:
        del sys.argv[removeArgIdx]
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    try:
        if runServer:
            ws = FakeWebServer(11111)
            ws.start()
            import time
            time.sleep(1)  # wait server start ;-(

        rc = reqman.main(hookResults=o)
    finally:
        if runServer:
            ws.stop()

    frc = None
    if rc >= 0 and hasattr(o, "rr"):
        details = []
        for i in o.rr.results:
            for j in i.exchanges:
                details.append("".join([str(int(t)) for t in j.tests]))
        toValid = ",".join(details)

        if valid:
            err = checkSign(valid, toValid)
            print("> Check valid:", valid, "?==", toValid, "-->",
                  "!!! ERROR: %s !!!" % err if err else "OK")
        else:
            print("> No validation check! (valid:%s)" % toValid)
            err = None
    else:
        toValid = "ERROR"
        if valid:
            err = "" if valid == toValid else "no error"
            print("> Check valid:", valid, "?==", toValid, "-->",
                  "!!! ERROR: %s !!!" % err if err else "OK")
        else:
            print("> No validation check! (valid:%s)" % toValid)
            err = None

    return err
Esempio n. 3
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# #############################################################################
#    Copyright (C) 2018-2021 manatlan manatlan[at]gmail(dot)com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 2 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# https://github.com/manatlan/reqman
# #############################################################################

import sys, reqman

sys.exit(reqman.main())
Esempio n. 4
0
def main(file, avoidBrowser=True):
    """
    yield "" : si valid est ok
    yield "error" : si valid est ko
    yield None : si pas validation
    """
    class RR:
        rr = None

    o = RR()

    #/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ NEW SYSTEM
    newValids = [
        i[8:i.rfind('#') or None].strip().split()
        for i in reqman.FString(file).splitlines() if i.startswith("#:valid:")
    ]
    #/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ NEW SYSTEM
    try:
        precdir = os.getcwd()
        testdir = tempfile.mkdtemp()
        os.chdir(testdir)

        for newValid in newValids:
            valid, *args = newValid
            args = [file if i == "THIS" else i for i in args]
            if avoidBrowser == True and "--b" in args:
                args.remove("--b")  # remove --b when pytest ;-)
            sys.argv = ["reqman"] + args

            rc = reqman.main(hookResults=o)
            if rc >= 0:
                if hasattr(o, "rr"):
                    details = []
                    details2 = []
                    if o.rr and o.rr.results:
                        for i in o.rr.results:
                            for j in i.exchanges:
                                if type(j) == tuple:
                                    if j[0]:
                                        details.append("".join(
                                            [str(int(t)) for t in j[0].tests]))
                                    if j[1]:
                                        details2.append("".join(
                                            [str(int(t)) for t in j[1].tests]))
                                else:
                                    details.append("".join(
                                        [str(int(t)) for t in j.tests]))
                        toValid = ",".join(details)
                        if details2: toValid += ":" + ",".join(details2)

                        if valid:
                            err = checkSign(valid, toValid, args)
                            print("> Check valid:", valid, "?==", toValid,
                                  "-->",
                                  "!!! ERROR: %s !!!" % err if err else "OK")
                        else:
                            print("> No validation check! (valid:%s)" %
                                  toValid)
                            err = None
                    else:
                        err = None
                else:
                    err = ""  #TODO: do something here (see test "new url")
            else:
                toValid = "ERROR"
                if valid:
                    err = "" if valid == toValid else "mismatch (%s!=%s, for %s)" % (
                        valid, toValid, args)
                    print("> Check valid:", valid, "?==", toValid, "-->",
                          "!!! ERROR: %s !!!" % err if err else "OK")
                else:
                    print("> No validation check! (valid:%s)" % toValid)
                    err = None

            yield err

    finally:
        os.chdir(precdir)