aboutsummaryrefslogtreecommitdiff
blob: 3e1cf436b5876c9b160fe1d7028bc834f08a5393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from functools import partial

from pkgcore.merge import triggers


class fake_trigger(triggers.base):

    def __init__(self, **kwargs):
        self._called = []
        if isinstance(kwargs.get('_hooks', False), str):
            kwargs['_hooks'] = (kwargs['_hooks'],)
        for k, v in kwargs.items():
            if callable(v):
                v = partial(v, self)
            setattr(self, k, v)

    def trigger(self, *args):
        self._called.append(args)


class fake_engine:

    def __init__(self, **kwargs):
        kwargs.setdefault('observer', None)
        self._triggers = []
        for k, v in kwargs.items():
            if callable(v):
                v = partial(v, self)
            setattr(self, k, v)

    def add_trigger(self, hook_point, trigger, required_csets):
        if hook_point in getattr(self, "blocked_hooks", []):
            raise KeyError(hook_point)
        self._triggers.append((hook_point, trigger, required_csets))


class fake_reporter:
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)