from nose.tools import assert_raises

from rx import Observer
from rx.notification import OnNext, OnError, OnCompleted
from rx.internal.exceptions import CompletedException

class MyObserver(Observer):
    def on_next(self, value):
        self.has_on_next = value
    
    def on_error(self, err):
        self.has_on_error = err

    def on_completed(self):
        self.has_on_completed = True

def test_to_observer_notification_on_next():
    i = 0
    def next(n):
        assert(i == 0)
        assert(n.kind == 'N')
        assert(n.value == 42)
        assert(not hasattr(n, "exception"))
        assert(n.has_value)
    
    Observer.from_notifier(next).on_next(42)

def test_to_observer_notification_on_error():
    ex = 'ex'
    i = 0
    def next(n):
        assert(i == 0)
        assert(n.kind == 'E')
        assert(n.exception == ex)
        assert(not n.has_value)