示例#1
0
def test_select_throws():
    try:
        Observable.return_value(1) \
            .select(lambda x, y: x) \
            .subscribe(lambda x: _raise("ex"))
    except RxException:
        pass

    try:
        Observable.throw_exception('ex') \
            .select(lambda x, y: x) \
            .subscribe(on_error=lambda ex: _raise(ex))
    except RxException:
        pass

    try:
        Observable.empty() \
            .select(lambda x, y: x) \
            .subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
    except RxException:
        pass

    def subscribe(observer):
        _raise('ex')

    try:
        Observable.create(subscribe) \
            .select(lambda x: x).dump() \
            .subscribe()
    except RxException:
        pass
示例#2
0
 def test_select_throws(self):
     try:
         Observable.return_value(1) \
             .select(lambda x, y: x) \
             .subscribe(lambda x: _raise("ex"))
     except RxException:
         pass
 
     try:
         Observable.throw_exception('ex') \
             .select(lambda x, y: x) \
             .subscribe(on_error=lambda ex: _raise(ex))
     except RxException:
         pass
 
     try:
         Observable.empty() \
             .select(lambda x, y: x) \
             .subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
     except RxException:
         pass
 
     def subscribe(observer):
         _raise('ex')
 
     try:
         Observable.create(subscribe) \
             .select(lambda x: x) \
             .subscribe()
     except RxException:
         pass
示例#3
0
 def test_select_with_index_throws(self):
     try:
         return Observable.return_value(1) \
             .select(lambda x, index: x) \
             .subscribe(lambda x: _raise('ex'))
     except RxException:
         pass
 
     try:
         return Observable.throw_exception('ex') \
             .select(lambda x, index: x) \
             .subscribe(lambda x: x, lambda ex: _raise(ex))
     except RxException:
         pass
 
     try:
         return Observable.empty() \
             .select(lambda x, index: x) \
             .subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))
     except RxException:
         pass
 
     try:
         return Observable.create(lambda o: _raise('ex')) \
             .select(lambda x, index: x) \
             .subscribe()
     except RxException:
         pass
示例#4
0
    def test_retry_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).retry()
        xs.subscribe(lambda x: _raise('ex'))
        
        try:
            return scheduler1.start()
        except RxException:
            pass

        scheduler2 = TestScheduler()
        ys = Observable.throw_exception('ex', scheduler2).retry()
        d = ys.subscribe(on_error=lambda ex: _raise('ex'))
        
        scheduler2.schedule_absolute(210, lambda: d.dispose())
        
        scheduler2.start()
        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).retry()
        zs.subscribe(on_completed=lambda: _raise('ex'))
        
        try:
            return scheduler3.start()
        except RxException:
            pass

        xss = Observable.create(lambda o: _raise('ex')).retry()
        try:
            return xss.subscribe()
        except RxException:
            pass
示例#5
0
    def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).repeat(3)
        xs.subscribe(lambda x: _raise('ex'))
        
        with self.assertRaises(RxException):
            scheduler1.start()
        
        scheduler2 = TestScheduler()
        ys = Observable.throw_exception('ex1', scheduler2).repeat(3)
        ys.subscribe(on_error=lambda ex: _raise('ex2'))
        
        with self.assertRaises(RxException):
            scheduler2.start()
        
        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).repeat(100)
        d = zs.subscribe(on_completed=lambda: _raise('ex3'))
        
        scheduler3.schedule_absolute(10, lambda sc, st: d.dispose())
        scheduler3.start()

        xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
        with self.assertRaises(RxException):
            xss.subscribe()
示例#6
0
def test_select_with_index_throws():
    try:
        return Observable.return_value(1) \
            .select(lambda x, index: x) \
            .subscribe(lambda x: _raise('ex'))
    except RxException:
        pass

    try:
        return Observable.throw_exception('ex') \
            .select(lambda x, index: x) \
            .subscribe(lambda x: x, lambda ex: _raise(ex))
    except RxException:
        pass

    try:
        return Observable.empty() \
            .select(lambda x, index: x) \
            .subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))
    except RxException:
        pass

    try:
        return Observable.create(lambda o: _raise('ex')) \
            .select(lambda x, index: x) \
            .subscribe()
    except RxException:
        pass
示例#7
0
    def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).repeat(3)
        xs.subscribe(lambda x: _raise('ex'))
        
        try:
            return scheduler1.start()
        except RxException:
            pass

        scheduler2 = TestScheduler()
        ys = Observable.throwException('ex1', scheduler2).repeat(3)
        ys.subscribe(lambda ex: _raise('ex2'))
        
        try:
            return scheduler2.start()
        except RxException:
            pass

        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).repeat(100)
        d = zs.subscribe(on_complete=lambda: _raise('ex3'))
        
        scheduler3.schedule_absolute(10, lambda: d.dispose())
        
        scheduler3.start()
        xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
        try:
            return xss.subscribe()
        except RxException:
            pass
示例#8
0
    def test_select_throws(self):
        with self.assertRaises(RxException):
            Observable.return_value(1) \
                .select(lambda x, y: x) \
                .subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            Observable.throw_exception('ex') \
                .select(lambda x, y: x) \
                .subscribe(on_error=lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            Observable.empty() \
                .select(lambda x, y: x) \
                .subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))

        def subscribe(observer):
            _raise('ex')

        with self.assertRaises(RxException):
            Observable.create(subscribe) \
                .select(lambda x: x) \
                .subscribe()
示例#9
0
 def test_select_throws(self):
     with self.assertRaises(RxException):
         Observable.return_value(1) \
             .map(lambda x, y: x) \
             .subscribe(lambda x: _raise("ex"))
     
     with self.assertRaises(RxException):
         Observable.throw_exception('ex') \
             .map(lambda x, y: x) \
             .subscribe(on_error=lambda ex: _raise(ex))
     
     with self.assertRaises(RxException):
         Observable.empty() \
             .map(lambda x, y: x) \
             .subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
     
     def subscribe(observer):
         _raise('ex')
 
     with self.assertRaises(RxException):
         Observable.create(subscribe) \
             .map(lambda x: x) \
             .subscribe()
示例#10
0
    def test_select_with_index_throws(self):
        with self.assertRaises(RxException):
            return Observable.return_value(1) \
                .select(lambda x, index: x) \
                .subscribe(lambda x: _raise('ex'))

        with self.assertRaises(RxException):
            return Observable.throw_exception('ex') \
                .select(lambda x, index: x) \
                .subscribe(lambda x: x, lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            return Observable.empty() \
                .select(lambda x, index: x) \
                .subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))

        with self.assertRaises(RxException):
            return Observable.create(lambda o: _raise('ex')) \
                .select(lambda x, index: x) \
                .subscribe()
示例#11
0
 def test_select_with_index_throws(self):
     with self.assertRaises(RxException):
         return Observable.return_value(1) \
             .map(lambda x, index: x) \
             .subscribe(lambda x: _raise('ex'))
     
     with self.assertRaises(RxException):
         return Observable.throw_exception('ex') \
             .map(lambda x, index: x) \
             .subscribe(lambda x: x, lambda ex: _raise(ex))
     
     with self.assertRaises(RxException):
         return Observable.empty() \
             .map(lambda x, index: x) \
             .subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))
     
     with self.assertRaises(RxException):
         return Observable.create(lambda o: _raise('ex')) \
             .map(lambda x, index: x) \
             .subscribe()
示例#12
0
    def test_as_observable_isnoteager(self):
        scheduler = TestScheduler()
        subscribed = [False]
        
        def subscribe(obs):
            subscribed[0] = True
            disp = scheduler.create_hot_observable(on_next(150, 1), on_next(220, 2), on_completed(250)).subscribe(obs)

            def func():
                return disp.dispose()
            return func

        xs = Observable.create(subscribe)
        xs.as_observable()
        assert(not subscribed[0])

        def create():
            return xs.as_observable()
        scheduler.start(create)

        assert(subscribed[0])
示例#13
0
    def test_retry_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).retry()
        xs.subscribe(lambda x: _raise('ex'))
        
        self.assertRaises(RxException, scheduler1.start)
        
        scheduler2 = TestScheduler()
        ys = Observable.throw_exception('ex', scheduler2).retry()
        d = ys.subscribe(on_error=lambda ex: _raise('ex'))
        
        scheduler2.schedule_absolute(210, lambda sc, st: d.dispose())
        
        scheduler2.start()
        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).retry()
        zs.subscribe(on_completed=lambda: _raise('ex'))
        
        self.assertRaises(RxException, scheduler3.start)

        xss = Observable.create(lambda o: _raise('ex')).retry()
        self.assertRaises(Exception, xss.subscribe)
示例#14
0
    def test_as_observable_isnoteager(self):
        scheduler = TestScheduler()
        subscribed = [False]

        def subscribe(obs):
            subscribed[0] = True
            disp = scheduler.create_hot_observable(on_next(
                150, 1), on_next(220, 2), on_completed(250)).subscribe(obs)

            def func():
                return disp.dispose()

            return func

        xs = Observable.create(subscribe)
        xs.as_observable()
        assert (not subscribed[0])

        def create():
            return xs.as_observable()

        scheduler.start(create)

        assert (subscribed[0])