File: testing_flatmap.py

package info (click to toggle)
python-rx 4.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,056 kB
  • sloc: python: 39,070; javascript: 77; makefile: 24
file content (30 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from reactivex import operators as ops
from reactivex.testing.marbles import marbles_testing

"""
Tests MergeMap from reactivexjs
https://github.com/ReactiveX/rxjs/blob/master/spec/operators/mergeMap-spec.ts

it should flat_map many regular interval inners
"""
with marbles_testing(timespan=1.0) as context:
    start, cold, hot, exp = context

    a = cold(" ----a---a----a----(a,|)                     ")
    b = cold("     ----1----b----(b,|)                     ")
    c = cold("                 -------c---c---c----c---(c,|)")
    d = cold("                         -------(d,|)        ")
    e1 = hot("-a---b-----------c-------d------------|      ")
    ex = exp("-----a---(a,1)(a,b)(a,b)c---c---(c,d)c---(c,|)")
    expected = ex

    observableLookup = {"a": a, "b": b, "c": c, "d": d}

    obs = e1.pipe(ops.flat_map(lambda value: observableLookup[value]))

    results = start(obs)
    assert results == expected

print("flat_map: results vs expected")
for r, e in zip(results, expected):
    print(r, e)