# Path: netman/adapters/switches/util.py
# class PageReader(object):
#     def __init__(self, read_while, and_press, unless_prompt):
#         self.next_page_indicator = read_while
#         self.continue_key = and_press
#         self.prompt = unless_prompt
# 
#     def do(self, shell, command):
#         result = shell.do(command,
#                           wait_for=(self.next_page_indicator, self.prompt),
#                           include_last_line=True)
# 
#         while len(result) > 0 and self.next_page_indicator in result[-1]:
#             result = result[:-1] + shell.send_key(self.continue_key,
#                                                   wait_for=(self.next_page_indicator, self.prompt),
#                                                   include_last_line=True)
# 
#         return result[:-1]


import unittest
from flexmock import flexmock, flexmock_teardown
from hamcrest import assert_that, is_
from netman.adapters.switches.util import PageReader
        ]))

    def test_reads_2_pages_and_removes_page_indicators_and_prompt(self):
        self.shell_mock.should_receive("do").with_args("command", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line1",
            "line2",
            "--More-- or (q)uit"
        ])

        self.shell_mock.should_receive("send_key").with_args("m", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line3",
            "line4",
            "--More-- or (q)uit"
        ])

        self.shell_mock.should_receive("send_key").with_args("m", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line5",
            "line6",
            "prompt#"
        ])

        result = self.reader.do(self.shell_mock, "command")

        assert_that(result, is_([
            "line1",
            "line2",
            "line3",
            "line4",
            "line5",
            "line6"

# Path: netman/adapters/switches/util.py
# class PageReader(object):
#     def __init__(self, read_while, and_press, unless_prompt):
#         self.next_page_indicator = read_while
#         self.continue_key = and_press
#         self.prompt = unless_prompt
# 
#     def do(self, shell, command):
#         result = shell.do(command,
#                           wait_for=(self.next_page_indicator, self.prompt),
#                           include_last_line=True)
# 
#         while len(result) > 0 and self.next_page_indicator in result[-1]:
#             result = result[:-1] + shell.send_key(self.continue_key,
#                                                   wait_for=(self.next_page_indicator, self.prompt),
#                                                   include_last_line=True)
# 
#         return result[:-1]


# Path: tests/adapters/switches/page_reader_test.py
import unittest
from flexmock import flexmock, flexmock_teardown
from hamcrest import assert_that, is_
from netman.adapters.switches.util import PageReader

        ]))

    def test_reads_2_pages_and_removes_page_indicators_and_prompt(self):
        self.shell_mock.should_receive("do").with_args("command", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line1",
            "line2",
            "--More-- or (q)uit"
        ])

        self.shell_mock.should_receive("send_key").with_args("m", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line3",
            "line4",
            "--More-- or (q)uit"
        ])

        self.shell_mock.should_receive("send_key").with_args("m", wait_for=("--More-- or (q)uit", "#"), include_last_line=True).once().ordered().and_return([
            "line5",
            "line6",
            "prompt#"
        ])

        result = self.reader.do(self.shell_mock, "command")

        assert_that(result, is_([
            "line1",
            "line2",
            "line3",
            "line4",
            "line5",
            "line6"

        ]))