Skip to content
Myr

Drop private imports from test_main.py (#2574)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent 7488b15 · Browse files · 1 file+11 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

1 file+11 added−16 removed

  • tests:+11 added−16 removed

1 file+11 added−16 removed

modified:tests/test_main.py+11 added-16 removed
2 unmodified lines
34from click.testing import CliRunner56import httpx7from httpx import main79if typing.TYPE_CHECKING: # pragma: no cover10 # don't let mypy be misled by the fallback defined in httpx/__init__.py11 from httpx._main import main # noqa: F8118139def splitlines(output: str) -> typing.Iterable[str]:10 return [line.strip() for line in output.splitlines()]1112
2 unmodified lines
151617def test_help():18 runner = CliRunner()24 result = runner.invoke(main, ["--help"])19 result = runner.invoke(httpx.main, ["--help"])20 assert result.exit_code == 021 assert "A next generation HTTP client." in result.output222324def test_get(server):25 url = str(server.url)26 runner = CliRunner()32 result = runner.invoke(main, [url])27 result = runner.invoke(httpx.main, [url])28 assert result.exit_code == 029 assert remove_date_header(splitlines(result.output)) == [30 "HTTP/1.1 200 OK",31 "server: uvicorn",
6 unmodified lines
3839def test_json(server):40 url = str(server.url.copy_with(path="/json"))41 runner = CliRunner()47 result = runner.invoke(main, [url])42 result = runner.invoke(httpx.main, [url])43 assert result.exit_code == 044 assert remove_date_header(splitlines(result.output)) == [45 "HTTP/1.1 200 OK",46 "server: uvicorn",
9 unmodified lines
56def test_binary(server):57 url = str(server.url.copy_with(path="/echo_binary"))58 runner = CliRunner()59 content = "Hello, world!"65 result = runner.invoke(main, [url, "-c", content])60 result = runner.invoke(httpx.main, [url, "-c", content])61 assert result.exit_code == 062 assert remove_date_header(splitlines(result.output)) == [63 "HTTP/1.1 200 OK",64 "server: uvicorn",
6 unmodified lines
7172def test_redirects(server):73 url = str(server.url.copy_with(path="/redirect_301"))74 runner = CliRunner()80 result = runner.invoke(main, [url])75 result = runner.invoke(httpx.main, [url])76 assert result.exit_code == 177 assert remove_date_header(splitlines(result.output)) == [78 "HTTP/1.1 301 Moved Permanently",79 "server: uvicorn",
5 unmodified lines
8586def test_follow_redirects(server):87 url = str(server.url.copy_with(path="/redirect_301"))88 runner = CliRunner()94 result = runner.invoke(main, [url, "--follow-redirects"])89 result = runner.invoke(httpx.main, [url, "--follow-redirects"])90 assert result.exit_code == 091 assert remove_date_header(splitlines(result.output)) == [92 "HTTP/1.1 301 Moved Permanently",93 "server: uvicorn",
11 unmodified lines
105106def test_post(server):107 url = str(server.url.copy_with(path="/echo_body"))108 runner = CliRunner()114 result = runner.invoke(main, [url, "-m", "POST", "-j", '{"hello": "world"}'])109 result = runner.invoke(httpx.main, [url, "-m", "POST", "-j", '{"hello": "world"}'])110 assert result.exit_code == 0111 assert remove_date_header(splitlines(result.output)) == [112 "HTTP/1.1 200 OK",113 "server: uvicorn",
6 unmodified lines
120121def test_verbose(server):122 url = str(server.url)123 runner = CliRunner()129 result = runner.invoke(main, [url, "-v"])124 result = runner.invoke(httpx.main, [url, "-v"])125 assert result.exit_code == 0126 assert remove_date_header(splitlines(result.output)) == [127 "* Connecting to '127.0.0.1'",128 "* Connected to '127.0.0.1' on port 8000",
15 unmodified lines
144145def test_auth(server):146 url = str(server.url)147 runner = CliRunner()153 result = runner.invoke(main, [url, "-v", "--auth", "username", "password"])148 result = runner.invoke(httpx.main, [url, "-v", "--auth", "username", "password"])149 print(result.output)150 assert result.exit_code == 0151 assert remove_date_header(splitlines(result.output)) == [152 "* Connecting to '127.0.0.1'",
18 unmodified lines
171def test_download(server):172 url = str(server.url)173 runner = CliRunner()174 with runner.isolated_filesystem():180 runner.invoke(main, [url, "--download", "index.txt"])175 runner.invoke(httpx.main, [url, "--download", "index.txt"])176 assert os.path.exists("index.txt")177 with open("index.txt", "r") as input_file:178 assert input_file.read() == "Hello, world!"179180181def test_errors():182 runner = CliRunner()188 result = runner.invoke(main, ["invalid://example.org"])183 result = runner.invoke(httpx.main, ["invalid://example.org"])184 assert result.exit_code == 1185 assert splitlines(result.output) == [186 "UnsupportedProtocol: Request URL has an unsupported protocol 'invalid://'.",187 ]