# Path: tests/utils.py
# class TObserver(object):
#     def __init__(self, observer):
#         self.events = []
#         observer.bind('change', self.handler)
# 
#     def handler(self, event):
#         self.events.append(event)


import src.circular.template.observer as o
from tests.utils import TObserver

class MockObj(object):
    def __init__(self,v):
        self.v = v

def test_obj_observer():
    m = MockObj(10)
    ob1 = o.observe(m)
    ob2 = o.observe(m)

    t1 = TObserver(ob1)
    t2 = TObserver(ob2)

    m.v = 20

    ev1 = t1.events.pop()
    ev2 = t2.events.pop()
    assert ev1 == ev2
    assert ev1.data == {
        'observed_obj':m,
        'type':'__setattr__',
        'key':'v',
        'value':20,
    }

def test_dict_observer():

    d = o.DictProxy({'a':10})
    obs = o.observe(d)

# Path: tests/utils.py
# class TObserver(object):
#     def __init__(self, observer):
#         self.events = []
#         observer.bind('change', self.handler)
# 
#     def handler(self, event):
#         self.events.append(event)


# Path: tests/circular/template/test_observer.py
import src.circular.template.observer as o
from tests.utils import TObserver


class MockObj(object):
    def __init__(self,v):
        self.v = v

def test_obj_observer():
    m = MockObj(10)
    ob1 = o.observe(m)
    ob2 = o.observe(m)

    t1 = TObserver(ob1)
    t2 = TObserver(ob2)

    m.v = 20

    ev1 = t1.events.pop()
    ev2 = t2.events.pop()
    assert ev1 == ev2
    assert ev1.data == {
        'observed_obj':m,
        'type':'__setattr__',
        'key':'v',
        'value':20,
    }

def test_dict_observer():

    d = o.DictProxy({'a':10})
    obs = o.observe(d)

    t = TObserver(obs)