コード例 #1
0
ファイル: util.py プロジェクト: GitHubTianPeng/101worker
def diff(suffix, resources, **switch):
    """
    Iterates over 101diff input using the incremental101 library and calls the
    given callbacks when appropriate. This handles changes in primary and
    relevant derived resources incrementally.


    Parameters
    ----------
    suffix : string or list of string
        Suffix(es) of the resources to be derived.

    resources : list of resource
        Resources that the current module depends on.

    switch : dict of function(**kwargs)
        A dict with callbacks with the keys "A", "M" and "D", for added,
        modified and deleted files respecitvely. In practice, these are onfile
        and ondelete in Deriver and Phase.
    """
    primary = set()
    derived = set()

    for op, path in incremental101.eachdiff():
        relative, kind = torelative(path, resources)
        if not relative:
            continue

        todo_primary = relative not in primary
        todo_derived = relative not in derived

        if kind == PRIMARY:
            if todo_primary and (op == "D" or todo_derived):
                if op in switch:
                    handlepath(suffix, switch[op], relative)
                primary.add(relative)

        elif kind == DERIVED:
            if todo_primary and todo_derived:
                if "M" in switch:
                    handlepath(suffix, switch["M"], relative)
                derived.add(relative)
コード例 #2
0
from TAP.Simple import *
import incremental101 as inc

plan(2)

# we don't test nextdiff here
def monkeypatch():
    global counter
    counter -= 1       # Python doesn't have counter--,
    return counter + 1 # so this hack will have to do.

inc.nextdiff = monkeypatch


counter = 5
values  = [diff for diff in inc.eachdiff()]
eq_ok(values, [5, 4, 3, 2, 1], "eachdiff iterates over nextdiff's values")


counter = 0
values  = [diff for diff in inc.eachdiff()]
eq_ok(values, [], "eachdiff with no values yields no values")