How to use the pyhf.events.trigger function in pyhf

To help you get started, we’ve selected a few pyhf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_event():
    ename = 'test'

    m = mock.Mock()
    events.subscribe(ename)(m)

    events.trigger(ename)()
    m.assert_called_once()
    del events.__events[ename]
github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_trigger_noevent():
    noop, noop_m = events.noop, mock.Mock()

    assert 'fake' not in events.__events
    assert events.trigger('fake') == events.noop
    assert events.trigger('fake')() == events.noop()
    assert noop_m.is_called_once()

    events.noop = noop
github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_disable_event():
    ename = 'test'

    m = mock.Mock()
    noop, noop_m = events.noop, mock.Mock()
    events.noop = noop_m
    events.subscribe(ename)(m)

    events.disable(ename)
    assert m.called is False
    assert ename in events.__disabled_events
    assert events.trigger(ename) == events.noop
    assert events.trigger(ename)() == events.noop()
    assert m.called is False
    assert noop_m.is_called_once()
    events.enable(ename)
    assert ename not in events.__disabled_events
    del events.__events[ename]
    events.noop = noop
github scikit-hep / pyhf / tests / test_interpolate.py View on Github external
def test_interpolator_subscription(interpcode, random_histosets_alphasets_pair):
    histogramssets, alphasets = random_histosets_alphasets_pair
    ename = 'tensorlib_changed'

    # inject into our interpolator class
    interpolator_cls = pyhf.interpolators.get(interpcode)
    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=False)
        assert m.call_count == 1
        assert m not in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 1

    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=True)
        assert m.call_count == 1
        assert m in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 2
github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_disable_event():
    ename = 'test'

    m = mock.Mock()
    noop, noop_m = events.noop, mock.Mock()
    events.noop = noop_m
    events.subscribe(ename)(m)

    events.disable(ename)
    assert m.called is False
    assert ename in events.__disabled_events
    assert events.trigger(ename) == events.noop
    assert events.trigger(ename)() == events.noop()
    assert m.called is False
    assert noop_m.is_called_once()
    events.enable(ename)
    assert ename not in events.__disabled_events
    del events.__events[ename]
    events.noop = noop