import unittest

from reactivex import operators as ops
from reactivex.testing import ReactiveTest, TestScheduler

on_next = ReactiveTest.on_next
on_completed = ReactiveTest.on_completed
on_error = ReactiveTest.on_error
subscribe = ReactiveTest.subscribe
subscribed = ReactiveTest.subscribed
disposed = ReactiveTest.disposed
created = ReactiveTest.created


class TestSkip(unittest.TestCase):
    def test_skip_complete_after(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        )

        def create():
            return xs.pipe(ops.skip(20))

        results = scheduler.start(create)

        assert results.messages == [on_completed(690)]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_complete_same(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        )

        def create():
            return xs.pipe(ops.skip(17))

        results = scheduler.start(create)

        assert results.messages == [on_completed(690)]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_complete_before(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        )

        def create():
            return xs.pipe(ops.skip(10))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        ]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_Complete_zero(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        )

        def create():
            return xs.pipe(ops.skip(0))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_completed(690),
        ]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_error_after(self):
        ex = "ex"
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_error(690, ex),
        )

        def create():
            return xs.pipe(ops.skip(20))

        results = scheduler.start(create)

        assert results.messages == [on_error(690, ex)]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_error_same(self):
        ex = "ex"
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_error(690, ex),
        )

        def create():
            return xs.pipe(ops.skip(17))

        results = scheduler.start(create)

        assert results.messages == [on_error(690, ex)]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_error_before(self):
        ex = "ex"
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_error(690, ex),
        )

        def create():
            return xs.pipe(ops.skip(3))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
            on_error(690, ex),
        ]
        assert xs.subscriptions == [subscribe(200, 690)]

    def test_skip_dispose_before(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
        )

        def create():
            return xs.pipe(ops.skip(3))

        results = scheduler.start(create, disposed=250)
        assert results.messages == []
        assert xs.subscriptions == [subscribe(200, 250)]

    def test_skip_dispose_after(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(70, 6),
            on_next(150, 4),
            on_next(210, 9),
            on_next(230, 13),
            on_next(270, 7),
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
            on_next(410, 15),
            on_next(415, 16),
            on_next(460, 72),
            on_next(510, 76),
            on_next(560, 32),
            on_next(570, -100),
            on_next(580, -3),
            on_next(590, 5),
            on_next(630, 10),
        )

        def create():
            return xs.pipe(ops.skip(3))

        results = scheduler.start(create, disposed=400)
        assert results.messages == [
            on_next(280, 1),
            on_next(300, -1),
            on_next(310, 3),
            on_next(340, 8),
            on_next(370, 11),
        ]
        assert xs.subscriptions == [subscribe(200, 400)]


if __name__ == "__main__":
    unittest.main()

[((364, 4, 364, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((17, 20, 17, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((50, 20, 50, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((83, 20, 83, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((125, 20, 125, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((178, 20, 178, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((212, 20, 212, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((246, 20, 246, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((295, 20, 295, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((326, 20, 326, 35), 'reactivex.testing.TestScheduler', 'TestScheduler', ({}, {}), '()', False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((42, 27, 42, 39), 'reactivex.operators.skip', 'ops.skip', ({(42, 36, 42, 38): '(20)'}, {}), '(20)', True, 'from reactivex import operators as ops\n'), ((75, 27, 75, 39), 'reactivex.operators.skip', 'ops.skip', ({(75, 36, 75, 38): '(17)'}, {}), '(17)', True, 'from reactivex import operators as ops\n'), ((108, 27, 108, 39), 'reactivex.operators.skip', 'ops.skip', ({(108, 36, 108, 38): '(10)'}, {}), '(10)', True, 'from reactivex import operators as ops\n'), ((150, 27, 150, 38), 'reactivex.operators.skip', 'ops.skip', ({(150, 36, 150, 37): '(0)'}, {}), '(0)', True, 'from reactivex import operators as ops\n'), ((203, 27, 203, 39), 'reactivex.operators.skip', 'ops.skip', ({(203, 36, 203, 38): '(20)'}, {}), '(20)', True, 'from reactivex import operators as ops\n'), ((237, 27, 237, 39), 'reactivex.operators.skip', 'ops.skip', ({(237, 36, 237, 38): '(17)'}, {}), '(17)', True, 'from reactivex import operators as ops\n'), ((271, 27, 271, 38), 'reactivex.operators.skip', 'ops.skip', ({(271, 36, 271, 37): '(3)'}, {}), '(3)', True, 'from reactivex import operators as ops\n'), ((319, 27, 319, 38), 'reactivex.operators.skip', 'ops.skip', ({(319, 36, 319, 37): '(3)'}, {}), '(3)', True, 'from reactivex import operators as ops\n'), ((350, 27, 350, 38), 'reactivex.operators.skip', 'ops.skip', ({(350, 36, 350, 37): '(3)'}, {}), '(3)', True, 'from reactivex import operators as ops\n')]