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()

[((10277, 10292), 'unittest.main', 'unittest.main', ([], {}), '()\n', (10290, 10292), False, 'import unittest\n'), ((453, 468), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (466, 468), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((1399, 1414), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (1412, 1414), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((2347, 2362), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (2360, 2362), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((3527, 3542), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (3540, 3542), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((5017, 5032), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (5030, 5032), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((5978, 5993), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (5991, 5993), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((6941, 6956), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (6954, 6956), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((8328, 8343), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (8341, 8343), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((9238, 9253), 'reactivex.testing.TestScheduler', 'TestScheduler', ([], {}), '()\n', (9251, 9253), False, 'from reactivex.testing import ReactiveTest, TestScheduler\n'), ((1169, 1181), 'reactivex.operators.skip', 'ops.skip', (['(20)'], {}), '(20)\n', (1177, 1181), True, 'from reactivex import operators as ops\n'), ((2115, 2127), 'reactivex.operators.skip', 'ops.skip', (['(17)'], {}), '(17)\n', (2123, 2127), True, 'from reactivex import operators as ops\n'), ((3063, 3075), 'reactivex.operators.skip', 'ops.skip', (['(10)'], {}), '(10)\n', (3071, 3075), True, 'from reactivex import operators as ops\n'), ((4243, 4254), 'reactivex.operators.skip', 'ops.skip', (['(0)'], {}), '(0)\n', (4251, 4254), True, 'from reactivex import operators as ops\n'), ((5733, 5745), 'reactivex.operators.skip', 'ops.skip', (['(20)'], {}), '(20)\n', (5741, 5745), True, 'from reactivex import operators as ops\n'), ((6694, 6706), 'reactivex.operators.skip', 'ops.skip', (['(17)'], {}), '(17)\n', (6702, 6706), True, 'from reactivex import operators as ops\n'), ((7657, 7668), 'reactivex.operators.skip', 'ops.skip', (['(3)'], {}), '(3)\n', (7665, 7668), True, 'from reactivex import operators as ops\n'), ((9013, 9024), 'reactivex.operators.skip', 'ops.skip', (['(3)'], {}), '(3)\n', (9021, 9024), True, 'from reactivex import operators as ops\n'), ((9923, 9934), 'reactivex.operators.skip', 'ops.skip', (['(3)'], {}), '(3)\n', (9931, 9934), True, 'from reactivex import operators as ops\n')]