click.get_pager_file: add tests (#1572 followup)#3405
click.get_pager_file: add tests (#1572 followup)#3405AndreasBackx wants to merge 2 commits intopallets:mainfrom
click.get_pager_file: add tests (#1572 followup)#3405Conversation
click.get_pager_file: add tests (#1572 followup)
kdeldycke
left a comment
There was a problem hiding this comment.
There are workaround and late changes in #1572 about windows so yes, it's better to try to test on that platform too. If you don't have access to a Windows machine, just remove your skip decorator and use the feedback from GitHub workflow runs. Slow, but doable.
|
|
||
| @pytest.mark.skipif(WIN, reason="Exercises the pipe pager path.") | ||
| @pytest.mark.parametrize( | ||
| ("text", "color", "expected"), |
There was a problem hiding this comment.
I like this matrix of ANSI test cases! 👍
| yield wrapped, "utf-8", color | ||
|
|
||
| monkeypatch.setattr( | ||
| click._termui_impl, "_pager_contextmanager", pager_contextmanager |
There was a problem hiding this comment.
Instead of monkeypatching _pager_contextmanager everytwhere, you can just feed get_pager_file with PAGER=. That way you can check with PAGER being set to cat, PAGER left unset, PAGER set to a missing binary etc to test even more edge-cases.
There was a problem hiding this comment.
Yes, I think that's the way to go because this is the top level API that is being modified by #1572. So if there are regressions, they will surface from here. Maybe you can even repack your tests to only target that higher-level API and demonstrate more use-cases, and skip testing implementation details.
And you can do the same with the other echo_via_pager function that was impacted by #1572.
There was a problem hiding this comment.
I've redesigned it all a bit because I made the mistake of diving into the differences between BinaryIO, TextIO, io.StringIO, and other io shenanigans. My brain is a bit fried and I'm just going to make dinner as I'm starving.
Let me know what you think. I don't think it's perfect yet, but honestly am just gonna put this down for today and give it another look another day.
| "Popen", | ||
| partial(subprocess.Popen, stdout=f), | ||
| ) | ||
| with force_subprocess_stdout: |
There was a problem hiding this comment.
Just a style nitpicking: why do you need the temporary force_subprocess_stdout variblae? Just fold everything in the with statement.
There was a problem hiding this comment.
Explains a bit what it does and makes the with statement a bit less unsightly, just a preference and I don't think too much about it in test code.
| return pager_out.read_text() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(WIN, reason="Exercises the pipe pager path.") |
There was a problem hiding this comment.
I just learned the existence of the more utility on Windows. So you can probably test with that as a PAGER.
There was a problem hiding this comment.
I've given more a try. Let's see if it passes.
…t set color unknowingly.
AndreasBackx
left a comment
There was a problem hiding this comment.
Will still update the change entries, but likely not today.
| "Popen", | ||
| partial(subprocess.Popen, stdout=f), | ||
| ) | ||
| with force_subprocess_stdout: |
There was a problem hiding this comment.
Explains a bit what it does and makes the with statement a bit less unsightly, just a preference and I don't think too much about it in test code.
| return pager_out.read_text() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(WIN, reason="Exercises the pipe pager path.") |
There was a problem hiding this comment.
I've given more a try. Let's see if it passes.
| yield wrapped, "utf-8", color | ||
|
|
||
| monkeypatch.setattr( | ||
| click._termui_impl, "_pager_contextmanager", pager_contextmanager |
There was a problem hiding this comment.
I've redesigned it all a bit because I made the mistake of diving into the differences between BinaryIO, TextIO, io.StringIO, and other io shenanigans. My brain is a bit fried and I'm just going to make dinner as I'm starving.
Let me know what you think. I don't think it's perfect yet, but honestly am just gonna put this down for today and give it another look another day.
This is a follow-up to #1572 which adds tests to validate the behaviour of
click.get_pager_file. There are still some open-standing questions / todos depending on requirements:catcould we use to create simple tests? We might be able to installcaton our CI, though I haven't looked into it yet.cat-based integration tests. We basically want to make sure that it works how we expect with a real pager, but usingcatseems like the easiest way to validate this as I don't know how we'd test interactive CLIs. 🤔