def test_relational(tmp_path): """Test loading and using a queue with the filesystem database. """ from qme.main import Queue config_dir = os.path.join(str(tmp_path), ".qme") queue = Queue(config_dir=config_dir, database="sqlite") assert os.path.exists(config_dir) assert queue.config_dir == config_dir assert queue.config.configfile == os.path.join(queue.config_dir, "config.ini") assert queue.database == "sqlite" assert queue.db.database == "sqlite" # Test list, empty without anything assert not queue.list() # Run a task task = queue.run("ls") assert task.executor.name == "shell" assert task.taskid.startswith("shell") assert len(queue.list()) == 1 # Rerun the task, should still only have one rerun = queue.rerun() assert rerun.taskid == task.taskid assert len(queue.list()) == 1 # queue.get should return last task, given no id lasttask = queue.get() assert lasttask.taskid == task.taskid # Run a new task newtask = queue.run("whoami") assert len(queue.list()) == 2 exports = newtask.export() # Search for tasks assert len(queue.search("ls")) > 0 # Check exports for required in ["pwd", "output", "error", "cmd", "returncode"]: assert required in exports assert exports["pwd"] == os.getcwd() assert exports["cmd"] == ["whoami"] assert exports["returncode"] == 0 # Get a task id that isn't the last task notlast = queue.get(task.taskid) assert task.taskid == notlast.taskid # Clean up a specific task (no prompt) queue.clear(task.taskid, noprompt=True) assert len(queue.list()) == 1 queue.clear(noprompt=True) assert not queue.list()
def main(args, extra): # Clear an executor, taskid, or target queue = Queue(config_dir=args.config_dir) queue.clear(args.target, noprompt=args.force)