Drop private imports from test_main.py (#2574)

Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
Florimond Manca 2023-02-09 16:50:09 +01:00 committed by GitHub
parent 7488b15226
commit 78d381fc7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,11 +4,6 @@ import typing
from click.testing import CliRunner
import httpx
from httpx import main
if typing.TYPE_CHECKING: # pragma: no cover
# don't let mypy be misled by the fallback defined in httpx/__init__.py
from httpx._main import main # noqa: F811
def splitlines(output: str) -> typing.Iterable[str]:
@ -21,7 +16,7 @@ def remove_date_header(lines: typing.Iterable[str]) -> typing.Iterable[str]:
def test_help():
runner = CliRunner()
result = runner.invoke(main, ["--help"])
result = runner.invoke(httpx.main, ["--help"])
assert result.exit_code == 0
assert "A next generation HTTP client." in result.output
@ -29,7 +24,7 @@ def test_help():
def test_get(server):
url = str(server.url)
runner = CliRunner()
result = runner.invoke(main, [url])
result = runner.invoke(httpx.main, [url])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 200 OK",
@ -44,7 +39,7 @@ def test_get(server):
def test_json(server):
url = str(server.url.copy_with(path="/json"))
runner = CliRunner()
result = runner.invoke(main, [url])
result = runner.invoke(httpx.main, [url])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 200 OK",
@ -62,7 +57,7 @@ def test_binary(server):
url = str(server.url.copy_with(path="/echo_binary"))
runner = CliRunner()
content = "Hello, world!"
result = runner.invoke(main, [url, "-c", content])
result = runner.invoke(httpx.main, [url, "-c", content])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 200 OK",
@ -77,7 +72,7 @@ def test_binary(server):
def test_redirects(server):
url = str(server.url.copy_with(path="/redirect_301"))
runner = CliRunner()
result = runner.invoke(main, [url])
result = runner.invoke(httpx.main, [url])
assert result.exit_code == 1
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 301 Moved Permanently",
@ -91,7 +86,7 @@ def test_redirects(server):
def test_follow_redirects(server):
url = str(server.url.copy_with(path="/redirect_301"))
runner = CliRunner()
result = runner.invoke(main, [url, "--follow-redirects"])
result = runner.invoke(httpx.main, [url, "--follow-redirects"])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 301 Moved Permanently",
@ -111,7 +106,7 @@ def test_follow_redirects(server):
def test_post(server):
url = str(server.url.copy_with(path="/echo_body"))
runner = CliRunner()
result = runner.invoke(main, [url, "-m", "POST", "-j", '{"hello": "world"}'])
result = runner.invoke(httpx.main, [url, "-m", "POST", "-j", '{"hello": "world"}'])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"HTTP/1.1 200 OK",
@ -126,7 +121,7 @@ def test_post(server):
def test_verbose(server):
url = str(server.url)
runner = CliRunner()
result = runner.invoke(main, [url, "-v"])
result = runner.invoke(httpx.main, [url, "-v"])
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
"* Connecting to '127.0.0.1'",
@ -150,7 +145,7 @@ def test_verbose(server):
def test_auth(server):
url = str(server.url)
runner = CliRunner()
result = runner.invoke(main, [url, "-v", "--auth", "username", "password"])
result = runner.invoke(httpx.main, [url, "-v", "--auth", "username", "password"])
print(result.output)
assert result.exit_code == 0
assert remove_date_header(splitlines(result.output)) == [
@ -177,7 +172,7 @@ def test_download(server):
url = str(server.url)
runner = CliRunner()
with runner.isolated_filesystem():
runner.invoke(main, [url, "--download", "index.txt"])
runner.invoke(httpx.main, [url, "--download", "index.txt"])
assert os.path.exists("index.txt")
with open("index.txt", "r") as input_file:
assert input_file.read() == "Hello, world!"
@ -185,7 +180,7 @@ def test_download(server):
def test_errors():
runner = CliRunner()
result = runner.invoke(main, ["invalid://example.org"])
result = runner.invoke(httpx.main, ["invalid://example.org"])
assert result.exit_code == 1
assert splitlines(result.output) == [
"UnsupportedProtocol: Request URL has an unsupported protocol 'invalid://'.",