forked from naylor-b/testflo
-
Notifications
You must be signed in to change notification settings - Fork 7
Deprecations report #76
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80de5dd
add deprecations report
swryan 9d8bd24
fix typo
swryan 17d171a
clarify report option
swryan ba24ed3
trim file paths in deprecations report
swryan 47998ac
markdown style title for deprecations report
swryan 56c216b
reduce newlines
swryan b022a07
reduce newlines
swryan 7587381
break
swryan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import sys | ||
| import os | ||
| import site | ||
|
|
||
| from io import StringIO | ||
|
|
||
| class DeprecationsReport(object): | ||
| """Generates a report of all Deprecation warnings raised during testing.""" | ||
|
|
||
| def __init__(self, options, stream=sys.stdout): | ||
| self.stream = stream | ||
| self.options = options | ||
| self.startdir = os.getcwd() | ||
|
|
||
| def get_iter(self, input_iter): | ||
|
|
||
| deprecations = {} | ||
|
|
||
| for test in input_iter: | ||
| for msg, locs in test.deprecations.items(): | ||
| deprecations[msg] = deprecations.get(msg, set()) | locs | ||
| yield test | ||
|
|
||
| report = self.generate_report(deprecations) | ||
|
|
||
| if self.options.show_deprecations: | ||
| self.stream.write(report) | ||
|
|
||
| if self.options.deprecations_report: | ||
| with open(self.options.deprecations_report, 'w') as stream: | ||
| stream.write(report) | ||
|
|
||
| def generate_report(self, deprecations): | ||
| report = StringIO() | ||
|
|
||
| title = "Deprecations Report" | ||
| eqs = "=" * len(title) | ||
|
|
||
| write = report.write | ||
|
|
||
| write("\n{}\n{}\n\n".format(title, eqs)) | ||
|
|
||
| count = len(deprecations) | ||
|
|
||
| write("{} unique deprecation warnings were captured{}\n\n".format(count, ':' if count else '.')) | ||
|
|
||
| if count == 0 and self.options.disallow_deprecations: | ||
| write("\nDeprecation warnings have been raised as Exceptions\n" | ||
| "due to the use of the --disallow_deprecations option,\n" | ||
| "so no deprecation warnings have been captured.") | ||
|
|
||
| startdir = self.startdir | ||
| try: | ||
| sitedirs = site.getsitepackages() | ||
| except: | ||
| # python older than 3.2 | ||
| sitedirs = [] | ||
|
|
||
| def trim_path(path): | ||
| # trim the start directory or the site-packages directory from the path | ||
| if path.startswith(startdir): | ||
| path = path[len(startdir):] | ||
| else: | ||
| for d in sitedirs: | ||
| if path.startswith(d): | ||
| path = path[len(d):] | ||
| return path | ||
|
|
||
| for msg in sorted(deprecations): | ||
| write("--\n{}\n\n".format(msg)) | ||
| for filename, lineno, test_spec in deprecations[msg]: | ||
| write(" {}, line {}\n".format(trim_path(filename), lineno)) | ||
| if test_spec: | ||
| write(" [{}]\n\n".format(trim_path(test_spec))) | ||
|
|
||
| if count > 0: | ||
| write("\n\nFor a stack trace of reported deprecations, run the " | ||
| "identified test with the --disallow_deprecations option.") | ||
|
|
||
| return report.getvalue() | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.