def test_lookup(): change = signal('change', 'attribute') d = {} sentinel = object() d[change('name')] = sentinel assert_that(d[change('name')], equal_to(sentinel))
def test_define_parameterisation(): change = signal('change', 'attribute') p = change('name') q = change('name') assert_that(p, instance_of(signal)) assert_that(p, equal_to(q)) assert_that(hash(p), equal_to(hash(q)))
def test_free_signal(): sentinel = object() source = Source() listener = mock.Mock() sig = signal('spam') subscribe(source, 'spam', listener.spam_cb) sig(source, s=sentinel) assert_that(listener.spam_cb, called_once_with(s=sentinel))
def test_subscribe_generic(): s = Source() l = mock.Mock() sentinel = object() change = signal('change', 'attribute') p = change('name') change.subscribe(s, l) p.publish(s, s=sentinel) assert_that(l, called_once_with(s=sentinel))
def test_subscribe_mismatch(): s = Source() l = mock.Mock() sentinel = object() change = signal('change', 'attribute') p = change('name') q = change('age') q.subscribe(s, l) p.publish(s, s=sentinel) assert_that(p, is_not(equal_to(q))) assert_that(l, has_property('call_count', 0))
def test_disallows_publish_without_all_parameters(): change = signal('change', 'attribute', 'type') p = change('name') with assert_raises(instance_of(TypeError)): p(Source())
def test_different_parameterisations_compare_unequal(): change = signal('change', 'attribute') p = change('name') q = change('age') assert_that(p, is_not(equal_to(q)))
def test_empty_parameters_compare_equal_to_parent(): change = signal('change', 'attribute') p = change() assert_that(p, equal_to(change))
def test_define_with_unhashable_raises(): change = signal('change', 'context') with assert_raises(instance_of(TypeError)): change([])
def test_define_parameterised(): change = signal('change', 'attribute') assert_that(change, instance_of(signal))