예제 #1
0
    def test_close_multiple_subscribers_late_subscription(self):
        observable = self.create_observable()

        observable.push('test')
        observable.close()

        observer1 = SimpleStoringObserver()
        observable.subscribe(observer1)

        observer2 = SimpleStoringObserver()
        observable.subscribe(observer2)
        self.assertTrue(observer1.closed)
        self.assertTrue(observer2.closed)
예제 #2
0
    def test_multiple_observers_single_update(self):
        observable = self.create_observable()

        observer1 = SimpleStoringObserver()
        observable.subscribe(observer1)

        observer2 = SimpleStoringObserver()
        observable.subscribe(observer2)

        observer3 = SimpleStoringObserver()
        observable.subscribe(observer3)

        observable.push('message')

        self.assertEqual(['message'], observer1.data)
        self.assertEqual(['message'], observer2.data)
        self.assertEqual(['message'], observer3.data)
예제 #3
0
    def test_single_update_late_subscription(self):
        observable = self.create_observable()

        observable.push('test')

        observer = SimpleStoringObserver()
        observable.subscribe(observer)

        self.assertEqual(['test'], observer.data)
예제 #4
0
    def test_close_late_subscription(self):
        observable = self.create_observable()

        observable.push('test')
        observable.close()

        observer = SimpleStoringObserver()
        observable.subscribe(observer)
        self.assertTrue(observer.closed)
예제 #5
0
    def test_map_single_update(self):
        observable = self.create_observable()

        mapped_observable = observable.map(lambda chunk: chunk + '_x')

        observer = SimpleStoringObserver()
        mapped_observable.subscribe(observer)

        observable.push('message')

        self.assertEqual(['message_x'], observer.data)
예제 #6
0
    def test_multiple_updates(self):
        observable = self.create_observable()

        observer = SimpleStoringObserver()
        observable.subscribe(observer)

        observable.push('1')
        observable.push('2')
        observable.push('3')

        self.assertEqual(['1', '2', '3'], observer.data)
예제 #7
0
    def test_map_close_late_subscription(self):
        observable = self.create_observable()

        mapped_observable = observable.map(lambda chunk: chunk + '_x')

        observable.close()

        observer = SimpleStoringObserver()
        mapped_observable.subscribe(observer)

        self.assertTrue(observer.closed)
예제 #8
0
    def test_log_unsecure_single_line(self):
        self.create_and_start_executor()

        observer = SimpleStoringObserver()
        self.executor.get_unsecure_output_stream().subscribe(observer)

        self.write_process_output('some text')

        wait_buffer_flush()

        self.assertEqual(['some text'], observer.data)
예제 #9
0
    def test_multiple_updates_late_subscription(self):
        observable = self.create_observable()

        observable.push('test1')
        observable.push('test2')
        observable.push('test3')

        observer = SimpleStoringObserver()
        observable.subscribe(observer)

        self.assertEqual(['test1', 'test2', 'test3'], observer.data)
예제 #10
0
    def test_multiple_observers_multiple_updates(self):
        observable = self.create_observable()

        observer1 = SimpleStoringObserver()
        observable.subscribe(observer1)

        observer2 = SimpleStoringObserver()
        observable.subscribe(observer2)

        observer3 = SimpleStoringObserver()
        observable.subscribe(observer3)

        observable.push('message')
        observable.push('and another one')
        observable.push('and the third')

        self.assertEqual(['message', 'and another one', 'and the third'],
                         observer1.data)
        self.assertEqual(['message', 'and another one', 'and the third'],
                         observer2.data)
        self.assertEqual(['message', 'and another one', 'and the third'],
                         observer3.data)
예제 #11
0
    def test_map_multiple_updates_late_subscription(self):
        observable = self.create_observable()

        observable.push('a')
        observable.push('b')
        observable.push('c')

        mapped_observable = observable.map(lambda chunk: chunk + '_x')

        observer = SimpleStoringObserver()
        mapped_observable.subscribe(observer)

        self.assertEqual(['a_x', 'b_x', 'c_x'], observer.data)
예제 #12
0
    def test_time_buffer_single_update(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(10)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('message1')

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['message1'], observer.data)
예제 #13
0
    def test_time_buffer_close_late_subscription(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(10)

        observable.push('message')
        observable.close()

        self.wait_buffer_flush(buffered_observable)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        self.assertTrue(observer.closed)
예제 #14
0
    def test_time_buffer_late_subscription(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(10)

        observable.push('m1')
        observable.push('m2')

        self.wait_buffer_flush(buffered_observable)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        self.assertEqual(['m1', 'm2'], observer.data)
예제 #15
0
    def test_time_buffer_aggregate_single_update(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(
            100, lambda chunks: ['|||'.join(chunks)])

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('message1')

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['message1'], observer.data)
예제 #16
0
    def test_time_buffer_multiple_updates(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(10)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('a')
        observable.push('b')
        observable.push('c')

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['a', 'b', 'c'], observer.data)
예제 #17
0
    def test_time_buffer_aggregated_late_subscription(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(
            100, lambda chunks: ['|'.join(chunks)])

        observable.push('m1')
        observable.push('m2')
        observable.push('m3')

        self.wait_buffer_flush(buffered_observable)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        self.assertEqual(['m1|m2|m3'], observer.data)
예제 #18
0
    def test_map_wait_close(self):
        observable = self.create_observable()

        mapped_observable = observable.map(lambda chunk: chunk + '_x')

        observer = SimpleStoringObserver()
        mapped_observable.subscribe(observer)

        thread = threading.Thread(target=self.close_delayed,
                                  args=[observable],
                                  daemon=True)
        thread.start()

        mapped_observable.wait_close()

        self.assertTrue(observer.closed)
예제 #19
0
    def test_on_close_exception_different_observers(self):
        observable = self.create_observable()

        class FailingObserver(SimpleStoringObserver):
            def on_close(self):
                raise Exception

        failing_observer = FailingObserver()
        observable.subscribe(failing_observer)

        normal_observer = SimpleStoringObserver()
        observable.subscribe(normal_observer)

        observable.close()

        self.assertTrue(observable.closed)
        self.assertTrue(normal_observer.closed)
예제 #20
0
    def test_on_next_exception_different_observers(self):
        observable = self.create_observable()

        class FailingObserver(SimpleStoringObserver):
            def on_next(self, chunk):
                raise Exception

        failing_observer = FailingObserver()
        observable.subscribe(failing_observer)

        normal_observer = SimpleStoringObserver()
        observable.subscribe(normal_observer)

        observable.push('m1')
        observable.push('m2')

        self.assertEqual([], failing_observer.data)
        self.assertEqual(['m1', 'm2'], normal_observer.data)
예제 #21
0
    def test_time_buffer_flush_before_close(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(100)

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('m1')
        observable.push('m2')
        observable.close()

        self.assertEqual([], observer.data)
        self.assertFalse(observer.closed)

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['m1', 'm2'], observer.data)
        self.assertTrue(observer.closed)
예제 #22
0
    def test_time_buffer_aggregate_multiple_updates_multiple_buffers(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(
            100, lambda chunks: ['|||'.join(chunks)])

        observer = SimpleStoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('a')
        observable.push('b')
        observable.push('c')

        self.wait_buffer_flush(buffered_observable)

        observable.push('d')
        observable.push('e')
        observable.push('f')

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['a|||b|||c', 'd|||e|||f'], observer.data)