Skip to content
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

Normalize to module imports #576

Merged
merged 6 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[settings]
# NOTE: Consider single_line_exclusions=typing in next version of isort
force_single_line=True
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# 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 setuptools import setup
import setuptools


setup(
use_scm_version=True,
)
setuptools.setup(use_scm_version=True)
4 changes: 3 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest

from twine import auth, exceptions, utils
from twine import auth
from twine import exceptions
from twine import utils

cred = auth.CredentialInput

Expand Down
32 changes: 21 additions & 11 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
# 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.
import io

import pretend

from twine import commands
from twine import package as package_file
from twine.commands import check


Expand Down Expand Up @@ -40,9 +44,9 @@ def test_str_representation(self):


def test_check_no_distributions(monkeypatch):
stream = check.StringIO()
stream = io.StringIO()

monkeypatch.setattr(check, "_find_dists", lambda a: [])
monkeypatch.setattr(commands, "_find_dists", lambda a: [])

assert not check.check("dist/*", output_stream=stream)
assert stream.getvalue() == "No files to check.\n"
Expand All @@ -56,13 +60,15 @@ def test_check_passing_distribution(monkeypatch):
"description_content_type": "text/markdown",
}
)
output_stream = check.StringIO()
output_stream = io.StringIO()
warning_stream = ""

monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(commands, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(
check, "PackageFile", pretend.stub(from_filename=lambda *a, **kw: package),
package_file,
"PackageFile",
pretend.stub(from_filename=lambda *a, **kw: package),
)
monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream)

Expand All @@ -79,13 +85,15 @@ def test_check_no_description(monkeypatch, capsys):
}
)

monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(commands, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(
check, "PackageFile", pretend.stub(from_filename=lambda *a, **kw: package),
package_file,
"PackageFile",
pretend.stub(from_filename=lambda *a, **kw: package),
)

# used to crash with `AttributeError`
output_stream = check.StringIO()
output_stream = io.StringIO()
check.check("dist/*", output_stream=output_stream)
assert output_stream.getvalue() == (
"Checking dist/dist.tar.gz: PASSED, with warnings\n"
Expand All @@ -103,13 +111,15 @@ def test_check_failing_distribution(monkeypatch):
"description_content_type": "text/markdown",
}
)
output_stream = check.StringIO()
output_stream = io.StringIO()
warning_stream = "WARNING"

monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(commands, "_find_dists", lambda a: ["dist/dist.tar.gz"])
monkeypatch.setattr(
check, "PackageFile", pretend.stub(from_filename=lambda *a, **kw: package),
package_file,
"PackageFile",
pretend.stub(from_filename=lambda *a, **kw: package),
)
monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import pretend
import pytest

import twine.commands.upload
from twine import cli
from twine.commands import upload


def test_dispatch_to_subcommand(monkeypatch):
replaced_main = pretend.call_recorder(lambda args: None)
monkeypatch.setattr(twine.commands.upload, "main", replaced_main)
monkeypatch.setattr(upload, "main", replaced_main)

cli.dispatch(["upload", "path/to/file"])

Expand Down
12 changes: 6 additions & 6 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import pytest

from twine import commands
from twine import exceptions
from twine.commands import _find_dists, _group_wheel_files_first


def test_ensure_wheel_files_uploaded_first():
files = _group_wheel_files_first(
files = commands._group_wheel_files_first(
["twine/foo.py", "twine/first.whl", "twine/bar.py", "twine/second.whl"]
)
expected = [
Expand All @@ -20,13 +20,13 @@ def test_ensure_wheel_files_uploaded_first():


def test_ensure_if_no_wheel_files():
files = _group_wheel_files_first(["twine/foo.py", "twine/bar.py"])
files = commands._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"]))
files = sorted(commands._find_dists(["twine/__*.py"]))
expected = [
os.path.join("twine", "__init__.py"),
os.path.join("twine", "__main__.py"),
Expand All @@ -36,7 +36,7 @@ def test_find_dists_expands_globs():

def test_find_dists_errors_on_invalid_globs():
with pytest.raises(exceptions.InvalidDistribution):
_find_dists(["twine/*.rb"])
commands._find_dists(["twine/*.rb"])


def test_find_dists_handles_real_files():
Expand All @@ -47,5 +47,5 @@ def test_find_dists_handles_real_files():
"twine/utils.py",
"twine/wheel.py",
]
files = _find_dists(expected)
files = commands._find_dists(expected)
assert expected == files
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from twine.cli import dispatch
from twine import cli


def test_devpi_upload(devpi_server, uploadable_dist):
Expand All @@ -12,7 +12,7 @@ def test_devpi_upload(devpi_server, uploadable_dist):
devpi_server.password,
str(uploadable_dist),
]
dispatch(command)
cli.dispatch(command)


twine_sampleproject_token = (
Expand All @@ -35,7 +35,7 @@ def test_pypi_upload(sampleproject_dist):
twine_sampleproject_token,
str(sampleproject_dist),
]
dispatch(command)
cli.dispatch(command)


def test_pypiserver_upload(pypiserver_instance, uploadable_dist):
Expand All @@ -49,4 +49,4 @@ def test_pypiserver_upload(pypiserver_instance, uploadable_dist):
"any",
str(uploadable_dist),
]
dispatch(command)
cli.dispatch(command)
3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import pretend

from twine import __main__ as dunder_main
from twine import cli
from twine import exceptions


def test_exception_handling(monkeypatch):
replaced_dispatch = pretend.raiser(exceptions.InvalidConfiguration("foo"))
monkeypatch.setattr(dunder_main, "dispatch", replaced_dispatch)
monkeypatch.setattr(cli, "dispatch", replaced_dispatch)
assert dunder_main.main() == "InvalidConfiguration: foo"
Loading