forked from psf/black
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix is_type_comment function issue psf#2097
- Loading branch information
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,21 @@ | ||
from black import format_str, FileMode | ||
from black.nodes import is_type_comment, Leaf, STANDALONE_COMMENT | ||
|
||
def test_is_type_comment_recognition(): | ||
|
||
assert is_type_comment(Leaf(STANDALONE_COMMENT, "# type: int")) | ||
assert is_type_comment(Leaf(STANDALONE_COMMENT, "# type: int")) | ||
assert is_type_comment(Leaf(STANDALONE_COMMENT, "# type: int")) | ||
assert not is_type_comment(Leaf(STANDALONE_COMMENT, "# nope: int")) | ||
|
||
def test_type_comment_normalization(): | ||
|
||
src = "x = 1 # type: int\n" | ||
expected = "x = 1 # type: int\n" | ||
result = format_str(src, mode=FileMode()) | ||
assert result == expected | ||
|
||
src = "def foo(): # type: str\n pass" | ||
expected = "def foo(): # type: str\n pass\n" | ||
result = format_str(src, mode=FileMode()) | ||
assert result == expected |