-
Notifications
You must be signed in to change notification settings - Fork 308
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
Add "check" command #395
Merged
Merged
Add "check" command #395
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
657fc84
Move helper functions to common location
di b26be0e
Remove unused (and incorrect) main runner
di ad828e3
Return the result of main to exit correctly
di 95b80b0
Add a check command
di 3ae98ed
Simplify keyring import and test
di 5355267
Update documentation
di bce81f4
Dogfood! Use twine check for twine itself
di ba98230
Update changelog
di 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 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,119 @@ | ||
# Copyright 2018 Dustin Ingram | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from __future__ import unicode_literals | ||
|
||
import pretend | ||
|
||
from twine.commands import check | ||
|
||
|
||
def test_warningstream_write_match(): | ||
stream = check._WarningStream() | ||
stream.output = pretend.stub(write=pretend.call_recorder(lambda a: None)) | ||
|
||
stream.write("<string>:2: (WARNING/2) Title underline too short.") | ||
|
||
assert stream.output.write.calls == [ | ||
pretend.call("line 2: Warning: Title underline too short.\n") | ||
] | ||
|
||
|
||
def test_warningstream_write_nomatch(): | ||
stream = check._WarningStream() | ||
stream.output = pretend.stub(write=pretend.call_recorder(lambda a: None)) | ||
|
||
stream.write("this does not match") | ||
|
||
assert stream.output.write.calls == [pretend.call("this does not match")] | ||
|
||
|
||
def test_warningstream_str(): | ||
stream = check._WarningStream() | ||
stream.output = pretend.stub(getvalue=lambda: "result") | ||
|
||
assert str(stream) == "result" | ||
|
||
|
||
def test_check_no_distributions(monkeypatch): | ||
stream = check.StringIO() | ||
|
||
monkeypatch.setattr(check, "_find_dists", lambda a: []) | ||
|
||
assert not check.check("dist/*", output_stream=stream) | ||
assert stream.getvalue() == "" | ||
|
||
|
||
def test_check_passing_distribution(monkeypatch): | ||
renderer = pretend.stub( | ||
render=pretend.call_recorder(lambda *a, **kw: "valid") | ||
) | ||
package = pretend.stub(metadata_dictionary=lambda: {"description": "blah"}) | ||
output_stream = check.StringIO() | ||
warning_stream = "" | ||
|
||
monkeypatch.setattr(check, "_RENDERERS", {"": renderer}) | ||
monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"]) | ||
monkeypatch.setattr( | ||
check, | ||
"PackageFile", | ||
pretend.stub(from_filename=lambda *a, **kw: package), | ||
) | ||
monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream) | ||
|
||
assert not check.check("dist/*", output_stream=output_stream) | ||
assert ( | ||
output_stream.getvalue() | ||
== "Checking distribution dist/dist.tar.gz: Passed\n" | ||
) | ||
assert renderer.render.calls == [ | ||
pretend.call("blah", stream=warning_stream) | ||
] | ||
|
||
|
||
def test_check_failing_distribution(monkeypatch): | ||
renderer = pretend.stub( | ||
render=pretend.call_recorder(lambda *a, **kw: None) | ||
) | ||
package = pretend.stub(metadata_dictionary=lambda: {"description": "blah"}) | ||
output_stream = check.StringIO() | ||
warning_stream = "WARNING" | ||
|
||
monkeypatch.setattr(check, "_RENDERERS", {"": renderer}) | ||
monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"]) | ||
monkeypatch.setattr( | ||
check, | ||
"PackageFile", | ||
pretend.stub(from_filename=lambda *a, **kw: package), | ||
) | ||
monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream) | ||
|
||
assert check.check("dist/*", output_stream=output_stream) | ||
assert output_stream.getvalue() == ( | ||
"Checking distribution dist/dist.tar.gz: Failed\n" | ||
"The project's long_description has invalid markup which will not be " | ||
"rendered on PyPI. The following syntax errors were detected:\n" | ||
"WARNING" | ||
) | ||
assert renderer.render.calls == [ | ||
pretend.call("blah", stream=warning_stream) | ||
] | ||
|
||
|
||
def test_main(monkeypatch): | ||
check_result = pretend.stub() | ||
check_stub = pretend.call_recorder(lambda a: check_result) | ||
monkeypatch.setattr(check, "check", check_stub) | ||
|
||
assert check.main(["dist/*"]) == check_result | ||
assert check_stub.calls == [pretend.call(["dist/*"])] |
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,50 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from twine.commands import _find_dists, _group_wheel_files_first | ||
|
||
|
||
def test_ensure_wheel_files_uploaded_first(): | ||
files = _group_wheel_files_first( | ||
["twine/foo.py", "twine/first.whl", "twine/bar.py", "twine/second.whl"] | ||
) | ||
expected = [ | ||
"twine/first.whl", | ||
"twine/second.whl", | ||
"twine/foo.py", | ||
"twine/bar.py", | ||
] | ||
assert expected == files | ||
|
||
|
||
def test_ensure_if_no_wheel_files(): | ||
files = _group_wheel_files_first(["twine/foo.py", "twine/bar.py"]) | ||
expected = ["twine/foo.py", "twine/bar.py"] | ||
assert expected == files | ||
|
||
|
||
def test_find_dists_expands_globs(): | ||
files = sorted(_find_dists(["twine/__*.py"])) | ||
expected = [ | ||
os.path.join("twine", "__init__.py"), | ||
os.path.join("twine", "__main__.py"), | ||
] | ||
assert expected == files | ||
|
||
|
||
def test_find_dists_errors_on_invalid_globs(): | ||
with pytest.raises(ValueError): | ||
_find_dists(["twine/*.rb"]) | ||
|
||
|
||
def test_find_dists_handles_real_files(): | ||
expected = [ | ||
"twine/__init__.py", | ||
"twine/__main__.py", | ||
"twine/cli.py", | ||
"twine/utils.py", | ||
"twine/wheel.py", | ||
] | ||
files = _find_dists(expected) | ||
assert expected == files |
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 |
---|---|---|
|
@@ -72,4 +72,4 @@ def dispatch(argv): | |
|
||
main = registered_commands[args.command].load() | ||
|
||
main(args.args) | ||
return main(args.args) | ||
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.
This is a very breaking change since the CLI now returns 1 (which is the standard code for "failure") on a successful execution.