-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show code snippets on demand (#7440)
* Start working on source code snippets * Make some cleanup * Add couple tests * Undo the dedicated error; update self-check to see these columns * Only do wrapping when showing source * Minor fixes * Fix tests on Python 3.5 * Support also blocking errors and daemon * Add couple tests * Fix bug * Address some CR * More CR * Separate fit in terminal from colorizing * Don't mutate message lists in-place * Update tests * Fix couple of-by-one errors; add tests and comments * Small tweaks * Add an end-to-end daemon test for --pretty
- Loading branch information
1 parent
bb7b5cd
commit 91adf61
Showing
14 changed files
with
427 additions
and
31 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
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
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,51 @@ | ||
from unittest import TestCase, main | ||
|
||
from mypy.util import trim_source_line, split_words | ||
|
||
|
||
class FancyErrorFormattingTestCases(TestCase): | ||
def test_trim_source(self) -> None: | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=16, col=5, min_width=2) == ('0123456789abcdef', 0) | ||
|
||
# Locations near start. | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=0, min_width=2) == ('0123456...', 0) | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=4, min_width=2) == ('0123456...', 0) | ||
|
||
# Middle locations. | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=5, min_width=2) == ('...1234567...', -2) | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=6, min_width=2) == ('...2345678...', -1) | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=8, min_width=2) == ('...456789a...', 1) | ||
|
||
# Locations near the end. | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=11, min_width=2) == ('...789abcd...', 4) | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=13, min_width=2) == ('...9abcdef', 6) | ||
assert trim_source_line('0123456789abcdef', | ||
max_len=7, col=15, min_width=2) == ('...9abcdef', 6) | ||
|
||
def test_split_words(self) -> None: | ||
assert split_words('Simple message') == ['Simple', 'message'] | ||
assert split_words('Message with "Some[Long, Types]"' | ||
' in it') == ['Message', 'with', | ||
'"Some[Long, Types]"', 'in', 'it'] | ||
assert split_words('Message with "Some[Long, Types]"' | ||
' and [error-code]') == ['Message', 'with', '"Some[Long, Types]"', | ||
'and', '[error-code]'] | ||
assert split_words('"Type[Stands, First]" then words') == ['"Type[Stands, First]"', | ||
'then', 'words'] | ||
assert split_words('First words "Then[Stands, Type]"') == ['First', 'words', | ||
'"Then[Stands, Type]"'] | ||
assert split_words('"Type[Only, Here]"') == ['"Type[Only, Here]"'] | ||
assert split_words('OneWord') == ['OneWord'] | ||
assert split_words(' ') == ['', ''] | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.