def test_overwrite_obj(tmpdir): jobdb = str(tmpdir.join("db")) j = dep.open_job_db(jobdb) j.add_template( dep.Template([dep.ForEach("in", {"A": "a"})], [], "transform")) # add the object, which results in a rule execution id1 = j.add_obj("public", 1, {"A": "a", "mut": {"$value": "1"}}) objs = j.find_objs("public", {"A": "a"}) assert len(objs) == 1 j.refresh_rules() assert len(j.get_pending()) == 1 assert len(j.get_all_executions()) == 0 rule_exec_id1 = j.get_pending()[0].id # add object with same "key" which should result in the old rule execution being replaced id2 = j.add_obj("public", 2, {"A": "a", "mut": {"$value": "2"}}) objs = j.find_objs("public", {"A": "a"}) assert len(objs) == 1 j.refresh_rules() assert len(j.get_pending()) == 1 # there should still only be a single rule, but it should be a new rule with the new input rule_exec_id2 = j.get_pending()[0].id assert id1 != id2 assert rule_exec_id1 != rule_exec_id2 # now, try with a different key to make sure it's not that all objects overwrite one another id1 = j.add_obj("public", 1, {"B": "b", "mut": {"$filename": "1"}}) objs = j.find_objs("public", {"B": "b"}) assert len(objs) == 1 id2 = j.add_obj("public", 2, {"B": "b", "mut": {"$filename": "2"}}) objs = j.find_objs("public", {"B": "b"}) assert len(objs) == 1 assert id1 != id2
def to_template(jinja2_env: Environment, rule: Rule, config: Dict[str, Union[str, Dict[str, str]]]) -> Template: queries, predicates = convert_input_spec_to_queries( jinja2_env, rule, config) return dep.Template( queries, predicates, rule.name, output_matches_expectation=rule.output_matches_expectation)
def test_stuff(tmpdir): jobdb = str(tmpdir.join("db")) templates = [ dep.Template([dep.ForEach("contexts", dict(type="contexts"))], [], "MakeContexts"), dep.Template([ dep.ForEach("avana_lib", dict(type="crispr_dataset", library="Avana")), dep.ForAll("gecko_libs", dict(library="Gecko")) ], [], "AvanaGeckoMerge"), dep.Template([ dep.ForEach("dataset", dict(type="crispr_dataset")), dep.ForEach("context", dict(type="context")) ], [], "CalculateEnrichment"), dep.Template([ dep.ForEach("dataset", dict(type="crispr_dataset")), dep.ForEach("parameters", dict(type="atlantis_params")) ], [], "RunAtlantis") ] j = dep.open_job_db(jobdb) for t in templates: j.add_template(t) def execute(execution_id, transform, inputs): if transform == "MakeContexts": j.record_completed(2, execution_id, dep.STATUS_COMPLETED, [ dict(name="a", type="context"), dict(name="b", type="context") ]) j.add_obj("public", 1, dict(type="contexts")) j.add_obj("public", 1, dict(type="atlantis_params", parameters="p1")) j.add_obj("public", 1, dict(type="atlantis_params", parameters="p2")) j.add_obj("public", 1, dict(type="crispr_dataset", library="Avana")) j.add_obj("public", 1, dict(type="crispr_dataset", library="Gecko")) j.refresh_rules() for pending in j.get_pending(): execute(pending.id, pending.transform, pending.inputs) print(j.to_dot(True))
def debugrun(state_dir, depfile, target, override_vars, config_file): db_path = os.path.join(state_dir, "db.sqlite3") print("opening", db_path) j = dep.open_job_db(db_path) rules = read_rules(state_dir, depfile, config_file) for var, value in override_vars.items(): rules.set_var(var, value) rule = rules.get_rule(target) queries, predicates = convert_input_spec_to_queries( rules.jinja2_env, rule, rules.vars) for q in queries: t = dep.Template([q], [], rule.name) applications = j.query_template(t) log.info("{} matches for {}".format(len(applications), q)) applications = j.query_template( dep.Template(queries, predicates, rule.name)) log.info("{} matches for entire rule".format(len(applications)))
def test_foreach(tmpdir): jobdb = str(tmpdir.join("db")) templates = [ dep.Template([dep.ForEach("contexts", dict(type="contexts"))], [], "MakeContexts") ] j = dep.open_job_db(jobdb) for t in templates: j.add_template(t) j.add_obj("public", 1, dict(type="contexts", name="a")) j.refresh_rules() assert len(j.get_pending()) == 1 j.add_obj("public", 1, dict(type="contexts", name="b")) j.refresh_rules() assert len(j.get_pending()) == 2