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)
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"
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'"
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'"