def test_emit_records_call(): s = Signal() s.add('foo', record=True) s.add('bar', record=True) s.add('baz', record=False) assert s.emissions == () s.emit('foo', 123) s.emit('bar', 'hello', 'world') s.emit('foo', 'and', this='that') s.emit('baz', 0) s.emit('bar', four=56) assert s.emissions == ( ('foo', { 'args': (123, ), 'kwargs': {} }), ('bar', { 'args': ('hello', 'world'), 'kwargs': {} }), ('foo', { 'args': ('and', ), 'kwargs': { 'this': 'that' } }), ('bar', { 'args': (), 'kwargs': { 'four': 56 } }), )
def test_adding_adds_signal(): s = Signal() assert s.signals == {} assert s._record_signals == [] s.add('foo') assert s.signals == {'foo': []} assert s._record_signals == [] s.add('bar', record=True) assert s.signals == {'foo': [], 'bar': []} assert s._record_signals == ['bar'] s.add('baz', record=False) assert s.signals == {'foo': [], 'bar': [], 'baz': []} assert s._record_signals == ['bar']
def test_adding_duplicate_signal(): s = Signal('foo') with pytest.raises(RuntimeError, match=r"^Signal already added: 'foo'$"): s.add('foo')
def test_adding_unhashable_signal(): s = Signal() with pytest.raises(TypeError, match=r'^Unhashable signal: \{\}$'): assert s.add({})