def test_integration():
    """integration test"""
    in_path, err_path, done_path = make_dirs(tmpdir)
    temp_path = os.path.join(tmpdir, "sample-text.odt")
    log = StringIO()

    worker = UnoConvWorker(in_path, err_path)
    log_all(worker, log)  # we log so we now what is done by our thread

    with controlled_worker(worker):
        # prepare a task
        shutil.copyfile(sample_path, temp_path)
        group_permissions(temp_path)
        task_path = os.path.join(tmpdir, "t1")
        with open(task_path, "w") as f:
            f.write("[unoconv]\n")
            f.write("src=%s\n" % temp_path)
            f.write("next=%s\n" % done_path)
        # push it
        os.rename(task_path, os.path.join(in_path, "t1"))
        # wait for completion
        while not "exit method run" in log.getvalue():
            time.sleep(0.1)
        assert "t1" in os.listdir(done_path)
        pdf_path = os.path.join(tmpdir, "sample-text.pdf")
        assert os.path.exists(pdf_path)
Ejemplo n.º 2
0
def test_main_loop():
    """test main worker loop, that is in start"""
    in_path, err_path, done_path = make_dirs(tmpdir)
    worker = ControlledWorker(in_path, err_path)

    log_all(worker, log)

    with controlled_worker(worker):
        # now we just wake it
        with worker.task_queue_guard:
            worker.task_queue.add('t1')
            worker.task_queue_signal.notify()
        while not "exit method run" in log.getvalue():
            time.sleep(0.2)
        assert output.getvalue() == "run t1"
Ejemplo n.º 3
0
def test_incoming_file():
    """integration test"""
    in_path, err_path, done_path = make_dirs(tmpdir)

    worker = SimpleWorker(in_path, err_path)
    log_all(worker, log)  # we log so we now what is done by our thread

    with controlled_worker(worker):
        # prepare a task
        task_path = os.path.join(tmpdir, 't1')
        with open(task_path, 'w') as f:
            f.write("""[simple]
a=1
b=some text
next=%s""" % done_path)
        # push it
        os.rename(task_path, os.path.join(in_path, 't1'))
        # wait for completion
        while not "exit method run" in log.getvalue():
            time.sleep(0.1)
        assert 't1' in os.listdir(done_path)
        assert output.getvalue() == "runing with a = '1' and b = 'some text'"
Ejemplo n.º 4
0
def test_observer():
    in_path, err_path, done_path = make_dirs(tmpdir)
    worker = NoRunWorker(in_path, err_path)
    log_all(worker, log)
    try:
        worker._launch_observer()
        assert worker.notifier is not None

        # add some file
        task_path = os.path.join(tmpdir, 't1')
        with open(task_path, 'w') as f:
            f.write(".")
            # take queue lock (to control the execution of notifier)
            with worker.task_queue_guard:
                # push task
                new_path = os.path.join(in_path, 't1')
                os.rename(task_path, new_path)
                # We nust be sure pyinotify have seen file before releasing
                # the lock
                worker.task_queue_signal.wait()  # notifier shall notify
                assert worker.task_queue == set([new_path])
    finally:
        worker.stop()
Ejemplo n.º 5
0
def test_init_with_files():
    """test worker when file are present in start directory"""
    in_path, err_path, done_path = make_dirs(tmpdir)
    worker = SimpleWorker(in_path, err_path)

    # push a task
    task_path = os.path.join(in_path, 't1')
    with open(task_path, 'w') as f:
        f.write("""[simple]
a=1
b=some text
next=%s""" % done_path)

    log_all(worker, log)

    worker._launch_observer = lambda: None

    # start
    with controlled_worker(worker):
        # shall execute task at startup
        while not "exit method run" in log.getvalue():
            time.sleep(0.1)
        assert output.getvalue() == "runing with a = '1' and b = 'some text'"