MCPcopy
hub / github.com/pallets/click / test_echo_via_pager

Function test_echo_via_pager

tests/test_utils.py:421–456  ·  view source on GitHub ↗
(monkeypatch, capfd, pager_cmd, test, tmp_path)

Source from the content-addressed store, hash-verified

419 ],
420)
421def test_echo_via_pager(monkeypatch, capfd, pager_cmd, test, tmp_path):
422 monkeypatch.setitem(os.environ, "PAGER", pager_cmd)
423 monkeypatch.setattr(click._termui_impl, "isatty", lambda x: True)
424
425 test_input = test.test_input()
426 expected_pager = test.expected_pager
427 expected_stdout = test.expected_stdout
428 expected_stderr = test.expected_stderr
429 expected_error = test.expected_error
430
431 check_raise = pytest.raises(expected_error) if expected_error else nullcontext()
432
433 pager_out_tmp = tmp_path / "pager_out.txt"
434 with pager_out_tmp.open("w") as f:
435 force_subprocess_stdout = patch.object(
436 subprocess,
437 "Popen",
438 partial(subprocess.Popen, stdout=f),
439 )
440 with force_subprocess_stdout:
441 with check_raise:
442 click.echo_via_pager(test_input)
443
444 out, err = capfd.readouterr()
445
446 pager = pager_out_tmp.read_text()
447
448 assert pager == expected_pager, (
449 f"Unexpected pager output in test case '{test.description}'"
450 )
451 assert out == expected_stdout, (
452 f"Unexpected stdout in test case '{test.description}'"
453 )
454 assert err == expected_stderr, (
455 f"Unexpected stderr in test case '{test.description}'"
456 )
457
458
459@pytest.mark.skipif(WIN, reason="Different behavior on windows.")

Callers

nothing calls this directly

Calls 1

openMethod · 0.80

Tested by

no test coverage detected