Heray-Was-Here
Server : Apache
System : Linux vps37394.inmotionhosting.com 3.10.0-1160.119.1.vz7.224.4 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User : jasonp18 ( 1000)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /lib/rads/venv/lib64/python3.13/site-packages/netaddr/tests/core/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/rads/venv/lib64/python3.13/site-packages/netaddr/tests/core/test_pubsub.py
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')

Hry