def main(): xs = reactivex.from_marbles("1-2-3-4-5-6-7-9-|").pipe(ops.publish()) xs.pipe(ops.map(failing), ops.retry()).subscribe(print) xs.connect() # Must connect. Cannot use ref_count() with publish() time.sleep(5)
def test_from_marbles_reuse(self): string = "a--b---c--|" " 012345678901234567890" obs = reactivex.from_marbles(string) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.0, "a"), ReactiveTest.on_next(200.3, "b"), ReactiveTest.on_next(200.7, "c"), ReactiveTest.on_completed(201.0), ] assert results == expected scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.0, "a"), ReactiveTest.on_next(200.3, "b"), ReactiveTest.on_next(200.7, "c"), ReactiveTest.on_completed(201.0), ] assert results == expected scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.0, "a"), ReactiveTest.on_next(200.3, "b"), ReactiveTest.on_next(200.7, "c"), ReactiveTest.on_completed(201.0), ] assert results == expected
def test_from_marbles_on_next(self): string = "a" obs = reactivex.from_marbles(string) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ReactiveTest.on_next(200.0, "a")] assert results == expected
def test_from_marbles_on_error(self): string = "#" obs = reactivex.from_marbles(string) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ReactiveTest.on_error(200.0, Exception("error"))] assert results == expected
def test_from_marbles_on_error_specified(self): string = "#" ex = Exception("Foo") obs = reactivex.from_marbles(string, error=ex) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ReactiveTest.on_error(200.0, ex)] assert results == expected
def test_cold( string: str, lookup: Optional[Dict[Union[str, float], Any]] = None, error: Optional[Exception] = None, ) -> Observable[Any]: check() return reactivex.from_marbles( string, timespan=timespan, lookup=lookup, error=error, )
def test_from_marbles_marble_with_space(self): string = " -a b- c- - |" " 01 23 45 6 78901234567890" obs = reactivex.from_marbles(string) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.1, "ab"), ReactiveTest.on_next(200.4, "c"), ReactiveTest.on_completed(200.7), ] assert results == expected
def test_from_marbles_marble_with_consecutive_symbols(self): string = "-ab(12)#--" " 012345678901234567890" ex = Exception("ex") obs = reactivex.from_marbles(string, error=ex) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.1, "ab"), ReactiveTest.on_next(200.3, 12), ReactiveTest.on_error(200.7, ex), ] assert results == expected
def test_from_marbles_timespan(self): string = "a--b---c" " 012345678901234567890" ts = 0.5 obs = reactivex.from_marbles(string, timespan=ts) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(0 * ts + 200.0, "a"), ReactiveTest.on_next(3 * ts + 200.0, "b"), ReactiveTest.on_next(7 * ts + 200.0, "c"), ] assert results == expected
def test_from_marbles_marble_with_group(self): string = "-(ab)-c-(12.5,def)--(6,|)" " 012345678901234567890" obs = reactivex.from_marbles(string) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.1, "ab"), ReactiveTest.on_next(200.6, "c"), ReactiveTest.on_next(200.8, str(12.5)), ReactiveTest.on_next(200.8, "def"), ReactiveTest.on_next(202.0, 6), ReactiveTest.on_completed(202.0), ] assert results == expected
def test_from_marbles_marble_lookup(self): string = "-ab-c-12-3-|" " 012345678901234567890" lookup = { "ab": "aabb", "c": "cc", 12: "1122", 3: 33, } obs = reactivex.from_marbles(string, lookup=lookup) scheduler = TestScheduler() results = scheduler.start(self.create_factory(obs)).messages expected = [ ReactiveTest.on_next(200.1, "aabb"), ReactiveTest.on_next(200.4, "cc"), ReactiveTest.on_next(200.6, "1122"), ReactiveTest.on_next(200.9, 33), ReactiveTest.on_completed(201.1), ] assert results == expected
import reactivex from reactivex import operators as ops """ Specify the error to be raised in place of the # symbol. """ err = ValueError("I don't like 5!") src0 = reactivex.from_marbles("12-----4-----67--|", timespan=0.2) src1 = reactivex.from_marbles("----3----5-# ", timespan=0.2, error=err) source = reactivex.merge(src0, src1).pipe(ops.do_action(print)) source.run()