|
Server : Apache System : Linux ecngx264.inmotionhosting.com 4.18.0-553.77.1.lve.el8.x86_64 #1 SMP Wed Oct 8 14:21:00 UTC 2025 x86_64 User : lonias5 ( 3576) PHP Version : 7.3.33 Disable Function : NONE Directory : /usr/lib/imh-fail2ban/lib64/python3.13/site-packages/netaddr/tests/core/ |
Upload File : |
import pytest
from netaddr.core import Publisher, Subscriber
import pprint
class Subject(Publisher):
pass
class Observer(Subscriber):
def __init__(self, id):
self.id = id
def update(self, data):
return repr(self), pprint.pformat(data)
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.id)
def test_pubsub():
s = Subject()
s.attach(Observer('foo'))
s.attach(Observer('bar'))
data = [
{'foo': 42},
{'list': [1, '2', list(range(10))]},
{'strings': ['foo', 'bar', 'baz', 'quux']},
]
s.notify(data)
s.notify(['foo', 'bar', 'baz'])
with pytest.raises(TypeError):
s.attach('foo')