Пример #1
0
    def test_close_multiple_subscribers_late_subscription(self):
        observable = self.create_observable()

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

        observer1 = _StoringObserver()
        observable.subscribe(observer1)

        observer2 = _StoringObserver()
        observable.subscribe(observer2)
        self.assertTrue(observer1.closed)
        self.assertTrue(observer2.closed)
Пример #2
0
    def _test_multiple_observers_single_update(self, source, observable):
        observer1 = _StoringObserver()
        observable.subscribe(observer1)

        observer2 = _StoringObserver()
        observable.subscribe(observer2)

        observer3 = _StoringObserver()
        observable.subscribe(observer3)

        message = 'message'
        source.push(message)

        return [observer1, observer2, observer3], message
Пример #3
0
    def _test_multiple_observers_multiple_updates(self, source, observable):
        observer1 = _StoringObserver()
        observable.subscribe(observer1)

        observer2 = _StoringObserver()
        observable.subscribe(observer2)

        observer3 = _StoringObserver()
        observable.subscribe(observer3)

        messages = ['message', 'and another one', 'and the third']
        for message in messages:
            source.push(message)

        return [observer1, observer2, observer3], messages
Пример #4
0
    def _test_single_update(self, source, observable):
        observer = _StoringObserver()
        observable.subscribe(observer)

        message = 'test notification'
        source.push(message)

        return observer, message
Пример #5
0
    def _test_multiple_updates(self, source, observable):
        observer = _StoringObserver()
        observable.subscribe(observer)

        messages = ['m1', '', 'message 3']
        for message in messages:
            source.push(message)

        return observer, messages
Пример #6
0
    def _test_multiple_updates_before_late_subscription(self, source, observable):
        messages = ['a', 'b', 'c']

        for message in messages:
            source.push(message)

        observer = _StoringObserver()
        observable.subscribe(observer)

        return observer, messages
Пример #7
0
    def test_log_raw_single_line(self):
        self.create_and_start_executor()

        observer = _StoringObserver()
        self.executor.get_raw_output_stream().subscribe(observer)

        self.write_process_output('some text')

        wait_buffer_flush()

        self.assertEqual(['some text'], observer.data)
Пример #8
0
    def _test_close(self, source, observable, postclose_callback=None):
        observer = _StoringObserver()
        observable.subscribe(observer)

        source.close()

        if postclose_callback:
            postclose_callback()

        self.assertTrue(observer.closed)
        self.assertTrue(observable.closed)
Пример #9
0
    def _test_push_before_late_subscription(self, source, observable, push_postprocessor=None):
        message = 'test1'
        source.push(message)

        if push_postprocessor is not None:
            push_postprocessor()

        observer = _StoringObserver()
        observable.subscribe(observer)

        return observer, message
Пример #10
0
    def _test_close_late_subscription(self, source, observable, postclose_callback=None):
        source.push('test')
        source.close()

        if postclose_callback:
            postclose_callback()

        observer = _StoringObserver()
        observable.subscribe(observer)

        self.assertTrue(observer.closed)
        self.assertTrue(observable.closed)
Пример #11
0
    def test_log_raw_single_line(self):
        config = self._create_config()
        self.create_and_start_executor(config)

        observer = _StoringObserver()
        self.executor.get_raw_output_stream().subscribe(observer)

        self.write_process_output('some text')

        wait_buffer_flush()

        self.assertEqual(['some text'], observer.data)
Пример #12
0
    def test_log_raw_single_buffer(self):
        config = self._create_config()
        self.create_and_start_executor(config)

        observer = _StoringObserver()
        self.executor.get_raw_output_stream().subscribe(observer)

        self.write_process_output('some text')
        self.write_process_output(' and continuation')

        wait_buffer_flush()

        self.assertEqual(['some text and continuation'], observer.data)
Пример #13
0
    def test_pipe_replay_dispose_deferred_for_updates(self):
        observable = self.create_observable()
        replay = self.replay(observable)

        observer = _StoringObserver()
        replay.subscribe(observer)

        observable.push('1')
        replay.dispose()
        observable.push('2')

        self.assertEqual(['1', '2'], observer.data)

        observable.close()
        self.assertEqual([], read_until_closed(replay, timeout=0.001))
Пример #14
0
    def test_pipe_replay_dispose_deferred(self):
        observable = self.create_observable()
        replay = self.replay(observable)

        observer = _StoringObserver()
        replay.subscribe(observer)

        replay.dispose()

        self.assertFalse(replay.closed)
        self.assertFalse(observer.closed)

        observable.close()
        self.assertTrue(replay.closed)
        self.assertTrue(observer.closed)
Пример #15
0
    def test_on_close_exception_different_observers(self):
        observable = self.create_observable()

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

        failing_observer = FailingObserver()
        observable.subscribe(failing_observer)

        normal_observer = _StoringObserver()
        observable.subscribe(normal_observer)

        observable.close()

        self.assertTrue(observable.closed)
        self.assertTrue(normal_observer.closed)
Пример #16
0
    def _test_push_after_late_subscription(self, source, observable, push_postprocessor=None):
        early_message = 'test1'
        source.push(early_message)

        if push_postprocessor is not None:
            push_postprocessor()

        observer = _StoringObserver()
        observable.subscribe(observer)

        late_message = 'test3'
        source.push(late_message)

        if push_postprocessor is not None:
            push_postprocessor()

        return observer, early_message, late_message
Пример #17
0
    def test_on_next_exception_different_observers(self):
        observable = self.create_observable()

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

        failing_observer = FailingObserver()
        observable.subscribe(failing_observer)

        normal_observer = _StoringObserver()
        observable.subscribe(normal_observer)

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

        self.assertEqual([], failing_observer.data)
        self.assertEqual(['m1', 'm2'], normal_observer.data)
Пример #18
0
    def test_time_buffer_flush_before_close(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(100)

        observer = _StoringObserver()
        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)
Пример #19
0
    def test_time_buffer_multiple_buffers(self):
        observable = self.create_observable()

        buffered_observable = observable.time_buffered(10)

        observer = _StoringObserver()
        buffered_observable.subscribe(observer)

        observable.push('message1')

        self.wait_buffer_flush(buffered_observable)

        observable.push('message2')

        self.wait_buffer_flush(buffered_observable)

        observable.push('message3')

        self.wait_buffer_flush(buffered_observable)

        self.assertEqual(['message1', 'message2', 'message3'], observer.data)
Пример #20
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 = _StoringObserver()
        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)
Пример #21
0
    def _test_no_updates(self, observable):
        observer = _StoringObserver()
        observable.subscribe(observer)

        self.assertEqual([], observer.data)