def __createEvent(self, sentence, events):
     tokensentences = self.__tagWords(sentence)
     whotemp = Who(tokensentences)
     whattemp = What(tokensentences, whotemp.getwhopos())
     whentemp = When(tokensentences)
     wheretemp = Where(whattemp.getwhatpos(), tokensentences)
     event = {
         'who': whotemp.getwho(),
         'what': whattemp.getwhat(),
         'when': whentemp.getwhen(),
         'where': wheretemp.getwhere()
     }
     if whotemp.getwho() != 'No who found' and whattemp.getwhat(
     ) != 'No what found':
         events.append(event)
Beispiel #2
0
def get_result_of_shell(run_cmd, time_out=5):
    """
    run the cmd
    :param time_out:
    :param run_cmd:
    :return:
    """
    from what import What
    w = What(*(run_cmd.split()))
    wait_time = time_out
    while wait_time >= 0:
        if w.get_output().__len__() == 0:
            time.sleep(1)
        else:
            return w.get_output()
        wait_time -= 1
    else:
        return ""
Beispiel #3
0
def run_python(args, cwd):
    dirname = os.path.dirname(__file__)
    cwd = os.path.join(dirname, cwd)
    What(sys.executable, *args.split(' '), cwd=cwd).expect_exit(0)
Beispiel #4
0
def run_kuyruk(queue='kuyruk', terminate=True):
    assert not_running()
    args = [
        sys.executable,
        '-u',
        '-m',
        'kuyruk.__main__',  # run main module
        "--app",
        "tests.tasks.kuyruk",
        "worker",
        '--queue',
        queue,
    ]

    environ = os.environ.copy()
    environ['COVERAGE_PROCESS_START'] = '.coveragerc'

    popen = What(*args, preexec_fn=os.setsid, env=environ)
    popen.timeout = TIMEOUT
    try:
        yield popen

        if terminate:
            # Send SIGTERM to worker for gracefull shutdown
            popen.terminate()
            popen.expect("End run worker")

        popen.expect_exit()

    finally:
        # We need to make sure that not any process of kuyruk is running
        # after the test is finished.

        # Kill the process and wait until it is dead
        try:
            popen.kill()
            popen.wait()
        except OSError as e:
            if e.errno != errno.ESRCH:  # No such process
                raise

        logger.debug('Worker return code: %s', popen.returncode)

        try:
            wait_while(lambda: get_pids('kuyruk:'))
        except KeyboardInterrupt:
            print(popen.get_output())
            # Do not raise KeyboardInterrupt here because nose does not print
            # captured stdout and logging on KeyboardInterrupt
            raise Exception
Beispiel #5
0
def run_kuyruk(queue='kuyruk', terminate=True):
    assert not_running()
    args = [
        sys.executable, '-u',
        '-m', 'kuyruk.__main__',  # run main module
        "--app", "tests.tasks.kuyruk",
        "worker", '--queue', queue,
    ]

    environ = os.environ.copy()
    environ['COVERAGE_PROCESS_START'] = '.coveragerc'

    popen = What(*args, preexec_fn=os.setsid, env=environ)
    popen.timeout = TIMEOUT
    try:
        yield popen

        if terminate:
            # Send SIGTERM to worker for gracefull shutdown
            popen.terminate()
            popen.expect("End run worker")

        popen.expect_exit()

    finally:
        # We need to make sure that not any process of kuyruk is running
        # after the test is finished.

        # Kill the process and wait until it is dead
        try:
            popen.kill()
            popen.wait()
        except OSError as e:
            if e.errno != errno.ESRCH:  # No such process
                raise

        logger.debug('Worker return code: %s', popen.returncode)

        try:
            wait_while(lambda: get_pids('kuyruk:'))
        except KeyboardInterrupt:
            print(popen.get_output())
            # Do not raise KeyboardInterrupt here because nose does not print
            # captured stdout and logging on KeyboardInterrupt
            raise Exception
Beispiel #6
0
def run_kuyruk(queue='kuyruk', save_failed_tasks=False, terminate=True,
               process='worker'):
    assert not_running()
    args = [
        sys.executable, '-u',
        '-m', 'kuyruk.__main__',  # run main module
        '--max-load', '999',  # do not pause because of load
    ]
    args.extend(['--logging-level=DEBUG'])
    if save_failed_tasks:
        args.extend(['--save-failed-tasks', 'True'])

    args.append(process)
    if process == 'worker':
        args.extend(['--queue', queue])

    environ = os.environ.copy()
    environ['COVERAGE_PROCESS_START'] = '.coveragerc'

    popen = What(*args, preexec_fn=os.setsid, env=environ)
    popen.timeout = TIMEOUT
    try:
        yield popen

        if terminate:
            # Send SIGTERM to worker for gracefull shutdown
            popen.terminate()
            popen.expect("End run %s" % process)

        popen.expect_exit()

    finally:
        # We need to make sure that not any process of kuyruk is running
        # after the test is finished.

        # Kill master process and wait until it is dead
        try:
            popen.kill()
            popen.wait()
        except OSError as e:
            if e.errno != errno.ESRCH:  # No such process
                raise

        logger.debug('Worker return code: %s', popen.returncode)

        # Kill worker processes by sending SIGKILL to their process group id
        try:
            logger.info('Killing process group: %s', popen.pid)
            os.killpg(popen.pid, signal.SIGTERM)
        except OSError as e:
            if e.errno != errno.ESRCH:  # No such process
                raise

        try:
            wait_while(lambda: get_pids('kuyruk:'))
        except KeyboardInterrupt:
            print popen.get_output()
            # Do not raise KeyboardInterrupt here because nose does not print
            # captured stdout and logging on KeyboardInterrupt
            raise Exception