Exemplo n.º 1
0
 def test_hot_skipped_at_200(self):
     string = "a"
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.0, scheduler=scheduler)
     results = scheduler.start(self.create_factory(obs)).messages
     expected = []
     assert results == expected
Exemplo n.º 2
0
 def test_hot_on_next(self):
     string = "a"
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.1, scheduler=scheduler)
     results = scheduler.start(self.create_factory(obs)).messages
     expected = [ReactiveTest.on_next(200.1, 'a')]
     assert results == expected
Exemplo n.º 3
0
    def test_hot_on_error(self):
        string = "#"
        scheduler = TestScheduler()
        obs = rx.hot(string, 0.1, 200.1, scheduler=scheduler)
        results = scheduler.start(self.create_factory(obs)).messages

        expected = [ReactiveTest.on_error(200.1, Exception('error'))]
        assert results == expected
Exemplo n.º 4
0
    def test_hot_on_error_specified(self):
        string = "#"
        ex = Exception('Foo')
        scheduler = TestScheduler()
        obs = rx.hot(string, 0.1, 200.1, error=ex, scheduler=scheduler)
        results = scheduler.start(self.create_factory(obs)).messages

        expected = [ReactiveTest.on_error(200.1, ex)]
        assert results == expected
Exemplo n.º 5
0
 def test_hot(string: str, lookup: Dict = None, error: Exception = None) -> Observable:
     check()
     hot_obs = rx.hot(
         string,
         timespan=timespan,
         duetime=subscribed,
         lookup=lookup,
         error=error,
         scheduler=scheduler,
         )
     return hot_obs
Exemplo n.º 6
0
 def test_hot_marble_with_space(self):
     string = " -a  b- c-  - |"
     "          01  23 45  6 78901234567890"
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.0, scheduler=scheduler)
     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
Exemplo n.º 7
0
 def test_hot_marble_with_consecutive_symbols(self):
     string = "-ab(12)#--"
     "         012345678901234567890"
     ex = Exception('ex')
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.0, error=ex, scheduler=scheduler)
     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
Exemplo n.º 8
0
 def test_hot_timespan(self):
     string = "-a-b---c"
     "         012345678901234567890"
     ts = 0.5
     scheduler = TestScheduler()
     obs = rx.hot(string, ts, 200.0, scheduler=scheduler)
     results = scheduler.start(self.create_factory(obs)).messages
     expected = [
         ReactiveTest.on_next(1 * ts + 200.0, 'a'),
         ReactiveTest.on_next(3 * ts + 200.0, 'b'),
         ReactiveTest.on_next(7 * ts + 200.0, 'c'),
         ]
     assert results == expected
Exemplo n.º 9
0
    def test_hot_marble_with_timedelta(self):
        string = "-ab-c--|"
        "         012345678901234567890"
        scheduler = TestScheduler()
        duetime = datetime.timedelta(seconds=300.0)

        obs = rx.hot(string, 0.1, duetime, scheduler=scheduler)
        results = scheduler.start(self.create_factory(obs)).messages
        expected = [
                ReactiveTest.on_next(300.1, 'ab'),
                ReactiveTest.on_next(300.4, 'c'),
                ReactiveTest.on_completed(300.7),
                ]
        assert results == expected
Exemplo n.º 10
0
 def test_hot_marble_with_group(self):
     string = "-(ab)-c-(12.5,def)--(6,|)"
     "         01234567890123456789012345"
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.0, scheduler=scheduler)
     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
Exemplo n.º 11
0
 def test_hot_marble_lookup(self):
     string = "-ab-c-12-3-|"
     "         012345678901234567890"
     lookup = {
         'ab': 'aabb',
         'c': 'cc',
         12: '1122',
         3: 33,
         }
     scheduler = TestScheduler()
     obs = rx.hot(string, 0.1, 200.0, lookup=lookup, scheduler=scheduler)
     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
Exemplo n.º 12
0
import datetime

import rx
import rx.operators as ops

"""
Delay the emission of elements to the specified datetime.
"""

now = datetime.datetime.utcnow()
dt = datetime.timedelta(seconds=3.0)
duetime = now + dt

print('{} ->  now\n'
      '{} ->  start of emission in {}s'.format(now, duetime, dt.total_seconds()))

hot = rx.hot('10--11--12--13--(14,|)', timespan=0.2, duetime=duetime)

source = hot.pipe(ops.do_action(print))
source.run()
Exemplo n.º 13
0
import datetime

import rx
import rx.operators as ops
"""
Delay the emission of elements to the specified datetime.
"""

now = datetime.datetime.utcnow()
dt = datetime.timedelta(seconds=3.0)
duetime = now + dt

print('{} ->  now\n'
      '{} ->  start of emission in {}s'.format(now, duetime,
                                               dt.total_seconds()))

hot = rx.hot('10--11--12--13--(14,|)', timespan=0.2, duetime=duetime)

source = hot.pipe(ops.do_action(print))
source.run()