File: test_marbles.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 (190 lines) | stat: -rw-r--r-- 6,132 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import unittest

from reactivex.testing.marbles import marbles_testing
from reactivex.testing.reactivetest import ReactiveTest

# from reactivex.scheduler import timeout_scheduler, new_thread_scheduler

# marble sequences to test:
# tested_marbles = '0-1-(10)|', '0|', '(10)-(20)|', '(abc)-|'


# class TestFromToMarbles(unittest.TestCase):

#     def test_new_thread_scheduler(self):
#         stream = Observable.from_marbles(marbles)
#         result = stream.to_blocking().to_marbles()
#         self.assertEqual(result, expected)

#         'this is the default scheduler'
#         self._run_test(tested_marbles, new_thread_scheduler)

# def test_timeout_scheduler(self):
#     self._run_test(tested_marbles, timeout_scheduler)

# def test_timeout_new_thread_scheduler(self):
#     self._run_test(tested_marbles, timeout_scheduler, new_thread_scheduler)

# def test_new_thread_scheduler_timeout(self):
#     self._run_test(tested_marbles, new_thread_scheduler, timeout_scheduler)

# def test_timeout_testscheduler(self):
#     '''the test scheduler uses virtual time => `to_marbles` does not
#        see the original delays.
#     '''
#     expected = [t.replace('-', '') for t in tested_marbles]
#     self._run_test(expected, timeout_scheduler, TestScheduler())

# def test_newthread_testscheduler(self):
#     '''the test scheduler uses virtual time => `to_marbles` does not
#        see the original delays.
#     '''
#     expected = [t.replace('-', '') for t in tested_marbles]
#     self._run_test(expected, new_thread_scheduler, TestScheduler())


class TestTestContext(unittest.TestCase):
    def test_start_with_cold_never(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("----")
            "           012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = []
            assert results == expected

    def test_start_with_cold_empty(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("------|")
            "           012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = [ReactiveTest.on_completed(206)]
            assert results == expected

    def test_start_with_cold_normal(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("12--3-|")
            "           012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = [
                ReactiveTest.on_next(200.0, 12),
                ReactiveTest.on_next(204.0, 3),
                ReactiveTest.on_completed(206.0),
            ]
            assert results == expected

    def test_start_with_cold_no_create_function(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("12--3-|")
            "           012345678901234567890"

            results = start(obs)
            expected = [
                ReactiveTest.on_next(200.0, 12),
                ReactiveTest.on_next(204.0, 3),
                ReactiveTest.on_completed(206.0),
            ]
            assert results == expected

    def test_start_with_hot_never(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = hot("------")
            "          012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = []
            assert results == expected

    def test_start_with_hot_empty(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = hot("---|")
            "          012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = [
                ReactiveTest.on_completed(203.0),
            ]
            assert results == expected

    def test_start_with_hot_normal(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = hot("-12--3-|")
            "          012345678901234567890"

            def create():
                return obs

            results = start(create)
            expected = [
                ReactiveTest.on_next(201.0, 12),
                ReactiveTest.on_next(205.0, 3),
                ReactiveTest.on_completed(207.0),
            ]
            assert results == expected

    def test_exp(self):
        with marbles_testing() as (start, cold, hot, exp):
            results = exp("12--3--4--5-|")
            "              012345678901234567890"

            expected = [
                ReactiveTest.on_next(200.0, 12),
                ReactiveTest.on_next(204.0, 3),
                ReactiveTest.on_next(207.0, 4),
                ReactiveTest.on_next(210.0, 5),
                ReactiveTest.on_completed(212.0),
            ]
            assert results == expected

    def test_start_with_hot_and_exp(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = hot("     --3--4--5-|")
            expected = exp("--3--4--5-|")
            "               012345678901234567890"

            def create():
                return obs

            results = start(create)
            assert results == expected

    def test_start_with_cold_and_exp(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("     12--3--4--5-|")
            expected = exp(" 12--3--4--5-|")
            "                012345678901234567890"

            def create():
                return obs

            results = start(create)
            assert results == expected

    def test_start_with_cold_and_exp_group(self):
        with marbles_testing() as (start, cold, hot, exp):
            obs = cold("     12--(3,6.5)----(5,#)")
            expected = exp(" 12--(3,6.5)----(5,#)")
            "                012345678901234567890"

            def create():
                return obs

            results = start(create)
            assert results == expected