(monkeypatch, terminal_size, testdata, explicit_pager, expect_pager)
| 786 | |
| 787 | |
| 788 | def output(monkeypatch, terminal_size, testdata, explicit_pager, expect_pager): |
| 789 | global clickoutput |
| 790 | clickoutput = "" |
| 791 | m = MyCli(myclirc=default_config_file) |
| 792 | |
| 793 | class TestOutput: |
| 794 | def get_size(self): |
| 795 | size = namedtuple("Size", "rows columns") |
| 796 | size.columns, size.rows = terminal_size |
| 797 | return size |
| 798 | |
| 799 | class TestExecute: |
| 800 | host = "test" |
| 801 | user = "test" |
| 802 | dbname = "test" |
| 803 | server_info = ServerInfo.from_version_string("unknown") |
| 804 | port = 0 |
| 805 | socket = '' |
| 806 | |
| 807 | def server_type(self): |
| 808 | return ["test"] |
| 809 | |
| 810 | class TestPromptSession: |
| 811 | output = TestOutput() |
| 812 | app = None |
| 813 | |
| 814 | m.prompt_session = TestPromptSession() |
| 815 | m.sqlexecute = TestExecute() |
| 816 | m.explicit_pager = explicit_pager |
| 817 | |
| 818 | def echo_via_pager(s): |
| 819 | assert expect_pager |
| 820 | global clickoutput |
| 821 | clickoutput += "".join(s) |
| 822 | |
| 823 | def secho(s): |
| 824 | assert not expect_pager |
| 825 | global clickoutput |
| 826 | clickoutput += s + "\n" |
| 827 | |
| 828 | monkeypatch.setattr(click, "echo_via_pager", echo_via_pager) |
| 829 | monkeypatch.setattr(click, "secho", secho) |
| 830 | m.output(testdata, SQLResult()) |
| 831 | if clickoutput.endswith("\n"): |
| 832 | clickoutput = clickoutput[:-1] |
| 833 | assert clickoutput == "\n".join(testdata) |
| 834 | |
| 835 | |
| 836 | def test_conditional_pager(monkeypatch): |
no test coverage detected