Example #1
0
def testmatches(wantmatches, wantwritten, wantdeleted, comment):
    global written, deleted, dump
    written = []
    deleted = []
    meta101.matchall("matches")
    eq_ok(written.pop()[1]["matches"], wantmatches, comment)
    eq_ok(written, wantwritten, "...correct files and data written")
    eq_ok(deleted, wantdeleted, "...correct files deleted")
def testmatches(matches, deleted, failures, comment):
    meta101.matchall("matches", entirerepo=True)

    todump = lambda match: {"filename": match, "units": [{"metadata": rule["metadata"]}]}
    wantdump = {"matches": [todump(match) for match in matches], "failures": failures, "rules": [{"rule": rule}]}
    with open(os.environ["matches101dump"]) as f:
        eq_ok(json.load(f), wantdump, comment)

    toderived = lambda f: os.path.join(os.environ["targets101dir"], f) + meta101.Matches.suffix

    for match in matches:
        with open(toderived(match)) as f:
            eq_ok(
                json.load(f), [{"metadata": rule["metadata"]}], "...correct derived matches file for {}".format(match)
            )

    for d in deleted:
        ok(not os.path.exists(toderived(d)), "...deleted derived matches file for {}".format(d))
Example #3
0
deleted = []
inc.writejson  = lambda path, data: written.append([path, data])
inc.deletefile = lambda path      : deleted.append(path)
inc.outstream  = StringIO()

def testmatches(wantmatches, wantwritten, wantdeleted, comment):
    global written, deleted, dump
    written = []
    deleted = []
    meta101.matchall("matches")
    eq_ok(written.pop()[1]["matches"], wantmatches, comment)
    eq_ok(written, wantwritten, "...correct files and data written")
    eq_ok(deleted, wantdeleted, "...correct files deleted")


dies_ok(lambda: meta101.matchall("matches"), "missing environment variable dies")

os.environ["rules101dump"] = "t/rules/nonexistent.json"
dies_ok(lambda: meta101.matchall("matches"), "missing rules dump dies")

os.environ["rules101dump"] = "t/rules/invalid.json"
dies_ok(lambda: meta101.matchall("matches"), "invalid json in rules dump dies")

os.environ["rules101dump"] = "t/rules/malformed.json"
dies_ok(lambda: meta101.matchall("matches"), "malformed rules dump dies")

os.environ["rules101dump"] = "t/rules/empty.json"
dies_ok(lambda: meta101.matchall("whatever"), "invalid phase dies")


inc.instream = StringIO("""A /repo/added
Example #4
0
#!/usr/bin/env python
import os
import meta101


pdir       = os.environ["predicates101dir"]
predicates = [os.path.join(pdir, d, "predicate.py") for d in os.listdir(pdir)]
changed    = meta101.havechanged(__file__, "module.json", *predicates )


meta101.matchall("predicates", entirerepo=changed)
Example #5
0
#!/usr/bin/env python
import meta101

# FIXME also check changes on fragments when they get moved into 101worker
meta101.matchall("fragments", entirerepo=meta101.havechanged(__file__))
Example #6
0
#!/usr/bin/env python
import os
import meta101

pdir = os.environ["predicates101dir"]
predicates = [os.path.join(pdir, d, "predicate.py") for d in os.listdir(pdir)]
changed = meta101.havechanged(__file__, "module.json", *predicates)

meta101.matchall("predicates", entirerepo=changed)
Example #7
0
#!/usr/bin/env python
import meta101
meta101.matchall("matches", meta101.havechanged(__file__))