-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix color output logic #19685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Fix color output logic #19685
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
433159b
Some progress
studyingegret 807f022
More changes
studyingegret 2188acb
Merge remote-tracking branch 'refs/remotes/origin/master' into color-…
studyingegret 30e8e43
Document the option
studyingegret ff79d3c
Fix type errors
studyingegret 5a3d5ff
Merge branch 'master' into color-output-option
studyingegret b3c4e87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 068f116
Fix Ruff lint UP022
studyingegret ecb8e9a
Merge branch 'color-output-option' of https://github.com/studyingegre…
studyingegret cc905b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2dfb813
lint: Delete unused "type: ignore" comment
studyingegret 0a1351c
Merge branch 'color-output-option' of https://github.com/studyingegre…
studyingegret 819b867
Some fixes
studyingegret 5879267
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd4460d
Remove MYPY_FORCE_COLOR and FORCE_COLOR in workflows/test.yml (??)
studyingegret 10ca3ab
Merge branch 'color-output-option' of https://github.com/studyingegre…
studyingegret 91be93d
Delete some workflows for this fork only (?)
studyingegret a873c67
Change workflows for this fork only (?)
studyingegret 2fe22d5
Merge branch 'color-output-option' of https://github.com/studyingegre…
studyingegret af56737
...
studyingegret 0fd4b98
!!!
studyingegret 3e101fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1bce878
Revert changed workflow files
studyingegret 89c0c93
Merge branch 'color-output-option' of https://github.com/studyingegre…
studyingegret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from functools import partial | ||
from subprocess import run | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
# TODO Would like help with this test, how do I make it runnable? | ||
|
||
|
||
def test(expect_color: bool, *args: Any, **kwargs: Any) -> None: | ||
res = run(*args, capture_output=True, **kwargs) | ||
if "Found" not in res.stdout: # ?? | ||
pytest.fail("Command failed to complete or did not detect type error") | ||
if expect_color: # Expect color control chars | ||
assert "<string>:1: error:" not in res.stdout | ||
assert "\nFound" not in res.stdout | ||
else: # Expect no color control chars | ||
assert "<string>:1: error:" in res.stdout | ||
assert "\nFound" in res.stdout | ||
|
||
|
||
colored = partial(test, True) | ||
not_colored = partial(test, False) | ||
|
||
|
||
@pytest.mark.parametrize("command", ["mypy", "dmypy run --"]) | ||
def test_color_output(command: str) -> None: | ||
# Note: Though we don't check stderr, capturing it is useful | ||
# because it provides traceback if mypy crashes due to exception | ||
# and pytest reveals it upon failure (?) | ||
not_colored(f"{command} -c \"1+'a'\"") | ||
colored(f"{command} -c \"1+'a'\"", env={"MYPY_FORCE_COLOR": "1"}) | ||
colored(f"{command} -c \"1+'a'\" --color-output") | ||
not_colored(f"{command} -c \"1+'a'\" --no-color-output") | ||
colored(f"{command} -c \"1+'a'\" --no-color-output", env={"MYPY_FORCE_COLOR": "1"}) # TODO | ||
|
||
|
||
# TODO: Tests in the terminal (require manual testing?) | ||
""" | ||
In the terminal: | ||
colored: mypy -c "1+'a'" | ||
colored: mypy -c "1+'a'" --color-output | ||
not colored: mypy -c "1+'a'" --no-color-output | ||
colored: mypy -c "1+'a'" --color-output (with MYPY_FORCE_COLOR=1) | ||
colored: mypy -c "1+'a'" --no-color-output (with MYPY_FORCE_COLOR=1) | ||
|
||
To test, save this as a .bat and run in a Windows terminal (I don't know the Unix equivalent): | ||
|
||
set MYPY_FORCE_COLOR= | ||
mypy -c "1+'a'" | ||
mypy -c "1+'a'" --color-output | ||
mypy -c "1+'a'" --no-color-output | ||
set MYPY_FORCE_COLOR=1 | ||
mypy -c "1+'a'" --color-output | ||
mypy -c "1+'a'" --no-color-output | ||
set MYPY_FORCE_COLOR= | ||
""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL, are you serious?