Exemplo n.º 1
0
 def send(self, command):
     if command.method == RequestMethod.POST:
         return self.send_post(command)
     elif command.method == RequestMethod.GET:
         return self.send_get(command)
     else:
         log.error("Unknown request method '%s'." % command.method)
Exemplo n.º 2
0
def __load_config(file):
    from os.path import exists, isfile, dirname, join, abspath, normpath

    global config

    #

    default = False
    if file is None:
        file = __DEFAULT_CONF_FILE
        default = True

    if not exists(file) or not isfile(file):
        file = join(join(dirname(__file__), "../"), file)

    file = normpath(abspath(file))

    if not exists(file) or not isfile(file):
        if default:
            log.warn("Config file '%s' is not found." % file)
            file = "/tmp/m3highload-test.conf.tmp"
            __generate_config(file)
        else:
            log.error("Config file '%s' is not found." % file)

    config = file
    log.debug("Configuration file '%s' loaded.\n\n%s" % (config, open(config, "r").read()))
Exemplo n.º 3
0
    def send_get(self, command):
        data = command.data

        if data:
            query = "&".join("%s=%s" % (key, str(data[key])) for key in data)
            log.debug("Server request\n" \
                  "Command: %s\n" \
                  "Data:    %s\n" % (command.name, query))
            self.__connection.request("GET", "%s?%s" % (command.name, query))
        else:
            log.debug("Server request:\n" \
                  "Command: %s\n" \
                  "Data:    None\n" % command.name)
            self.__connection.request("GET", command.name)

        response = self.__connection.getresponse()
        if response.status != 200:
            log.error("Invalid server response status %d: %s" % (response.status, response.reason))
        data = response.read()

        log.debug("Server response\n" \
              "Data:    %s\n" % data)

        command.process(utils.sdict(json.loads(data.decode("utf-8"))))
        return command
Exemplo n.º 4
0
 def send(self, command):
     if command.method == RequestMethod.POST:
         return self.send_post(command)
     elif command.method == RequestMethod.GET:
         return self.send_get(command)
     else:
         log.error("Unknown request method '%s'." % command.method)
Exemplo n.º 5
0
    def send_get(self, command):
        data = command.data

        if data:
            query = "&".join("%s=%s" % (key, str(data[key])) for key in data)
            log.debug("Server request\n" \
                  "Command: %s\n" \
                  "Data:    %s\n" % (command.name, query))
            self.__connection.request("GET", "%s?%s" % (command.name, query))
        else:
            log.debug("Server request:\n" \
                  "Command: %s\n" \
                  "Data:    None\n" % command.name)
            self.__connection.request("GET", command.name)

        response = self.__connection.getresponse()
        if response.status != 200:
            log.error("Invalid server response status %d: %s" %
                      (response.status, response.reason))
        data = response.read()

        log.debug("Server response\n" \
              "Data:    %s\n" % data)

        command.process(utils.sdict(json.loads(data.decode("utf-8"))))
        return command
Exemplo n.º 6
0
    def run(self):
        import sys, traceback

        result = True

        log.info("Starting group '%s'..." % self.name)

        try:
            __import__(self.fullname)
        except:
            log.error(
                "Error occurred during initialization of package '%s'." %
                self.fullname, False)
            raise

        for module in self.modules:
            if not module.exists:
                if not self.ignore_non_existent:
                    self.root.errors.append(
                        "In group '%s':\n  Module '%s' does not exist." %
                        (self.name, module.fullname))
                    log.error("Module '%s' does not exist." % module.fullname)
                else:
                    log.error("Module '%s' does not exist." % module.fullname,
                              False)
                continue

            try:
                result = module.run() and result
            except:
                result = False

                if isinstance(module, Group):
                    log.error("Group '%s' failed." % module.name, False)
                else:
                    log.error("Module '%s' failed." % module.name, False)

                if not self.ignore_failed:
                    raise
                else:
                    log.message("".join(
                        traceback.format_exception(sys.exc_type, sys.exc_value,
                                                   sys.exc_traceback)))

        log.ok("Group '%s' finished." % self.name)
        return result
Exemplo n.º 7
0
def run(host, config, port=None, http=False):
    from os.path import dirname, normpath, join
    from plamee.config import ConfigParser, Group

    Net.connect(host=host, port=port, http=http)

    dir = dirname(__file__)

    parser = ConfigParser(config)

    root = Group("plamee", dir=normpath(join(dir, "../../../")))

    prnt = root
    prnt.ignore_failed = True

    chld = Group("cakestory", prnt)
    prnt.modules.append(chld)
    prnt = chld
    prnt.ignore_failed = True

    chld = Group("test", prnt)
    prnt.modules.append(chld)

    try:
        chld.parse(parser)
    except:
        log.error(sys.exc_value.message, False)
        __exit()

    result = False
    try:
        result = chld.run()
    except:
        log.error("Group 'test' failed.", False)
        log.message("".join(
            traceback.format_exception(sys.exc_type, sys.exc_value,
                                       sys.exc_traceback)))

    log.info("All tests finished.")

    if not result:
        __exit(root.errors)
    else:
        log.ok("All tests successfully passed.")
Exemplo n.º 8
0
def run(host, config, port=None, http=False) :
    from os.path import dirname, normpath, join
    from plamee.config import ConfigParser, Group

    Net.connect(host=host, port=port, http=http)

    dir = dirname(__file__)

    parser = ConfigParser(config)

    root = Group("plamee", dir=normpath(join(dir, "../../../")))

    prnt = root
    prnt.ignore_failed = True

    chld = Group("cakestory", prnt)
    prnt.modules.append(chld)
    prnt = chld
    prnt.ignore_failed = True

    chld = Group("test", prnt)
    prnt.modules.append(chld)

    try:
        chld.parse(parser)
    except:
        log.error(sys.exc_value.message, False)
        __exit()

    result = False
    try:
        result = chld.run()
    except:
        log.error("Group 'test' failed.", False)
        log.message("".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)))

    log.info("All tests finished.")

    if not result:
        __exit(root.errors)
    else:
        log.ok("All tests successfully passed.")
Exemplo n.º 9
0
    def run(self):
        import sys, traceback

        result = True

        log.info("Starting group '%s'..." % self.name)

        try:
            __import__(self.fullname)
        except:
            log.error("Error occurred during initialization of package '%s'." % self.fullname, False)
            raise

        for module in self.modules:
            if not module.exists:
                if not self.ignore_non_existent:
                    self.root.errors.append("In group '%s':\n  Module '%s' does not exist." % (self.name, module.fullname))
                    log.error("Module '%s' does not exist." % module.fullname)
                else:
                    log.error("Module '%s' does not exist." % module.fullname, False)
                continue

            try:
                result = module.run() and result
            except:
                result = False

                if isinstance(module, Group):
                    log.error("Group '%s' failed." % module.name, False)
                else:
                    log.error("Module '%s' failed." % module.name, False)

                if not self.ignore_failed:
                    raise
                else:
                    log.message("".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)))

        log.ok("Group '%s' finished." % self.name)
        return result
Exemplo n.º 10
0
def log_error(message):
    errors.append(message)
    log.error(message, False)
Exemplo n.º 11
0
def __exit(errors=None):
    log.error("Test failed.", False)
    if errors and len(errors):
        log.message("Errors:\n\n%s" % "\n".join("%d. %s" % (i + 1, errors[i])
                                                for i in range(len(errors))))
    sys.exit(-1)
Exemplo n.º 12
0
import random
from plamee.cakestory import *
from plamee import log

client1 = Client()
client2 = Client()

for level in client1.map.bonus_levels:
    if not level.chapter.force_finish():
        log.error("Cannot finish chapter.")

    score = random.randint(10000, 50000)
    level.finish(score=score)

    if level.get_user_score() != score:
        raise RuntimeError("Test failed.")

    if client2.map.get_bonus_level(level.id).get_friend_score(client1) != score:
        raise RuntimeError("Test failed.")
Exemplo n.º 13
0
def init():
    import sys
    from plamee import log

    global config
    global host
    global port
    global http

    alist = list()
    map(lambda arg: alist.append([arg, None]) if not arg.find("--") else alist[len(alist) - 1].__setitem__(1, arg), sys.argv[1:])

    amap = dict(alist)


    if "--no-decoration" in amap:
        if amap["--no-decoration"] is not None:
            log.error("Invalid argument '%s'." % amap["--no-decoration"], False)
            print_help()
            sys.exit(-1)
        log.decoration = False
        del amap["--no-decoration"]

    if "--verbose" in amap:
        if amap["--verbose"] is not None:
            log.error("Invalid argument '%s'." % amap["--verbose"], False)
            print_help()
            sys.exit(-1)
        log.level = 0
        del amap["--verbose"]

    if "--log" in amap:
        file = amap["--log"]
        if file is None:
            log.error("Output file is not specified.", False)
        log.file = file
        del amap["--log"]

    if "--help" in amap:
        if amap["--help"] is not None:
            log.error("Invalid argument '%s'." % amap["--help"], False)
            print_help()
            sys.exit(-1)
        if len(amap.keys()) > 1:
            log.error("Too many arguments.", False)
            print_help()
            sys.exit(-1)
        print_help()
        sys.exit(0)

    if "--generate-config" in amap:
        if len(amap.keys()) > 1:
            print_help()
            log.error("Too many arguments.", False)
            sys.exit(-1)
        file = amap["--generate-config"]
        if file is None:
            log.error("Output file is not specified.", False)
        __generate_config(file)
        sys.exit(0)

    for arg in amap:
        if arg == "--config":
            if amap[arg] is not None:
                config = str(amap[arg])
            else:
                log.error("Config file is not specified.", False)
        elif arg == "--host":
            if amap[arg] is not None:
                host = str(amap[arg])
            else:
                log.error("Host is not specified.", False)
        elif arg == "--port":
            if amap[arg] is not None:
                port = int(amap[arg])
            else:
                log.error("Port is not specified.", False)
        elif arg == "--use-http":
            if amap["--use-http"] is not None:
                log.error("Invalid argument '%s'." % amap["--use-http"], False)
                print_help()
                sys.exit(-1)
            http = True
        else:
            log.error("Invalid argument '%s'." % arg, False)
            print_help()
            sys.exit(-1)

    __load_config(config)
Exemplo n.º 14
0
def __exit(errors=None):
    log.error("Test failed.", False)
    if errors and len(errors):
        log.message("Errors:\n\n%s" % "\n".join("%d. %s" % (i + 1, errors[i]) for i in range(len(errors))))
    sys.exit(-1)