Debian Codegraph @

tests/test_test_helpers.py

raw
1 import urllib
2
3 import pytest
4
5 import tests
6
7
8 @pytest.mark.parametrize("path", ("_", "/"), ids=lambda x: "path=" + x)
9 @pytest.mark.parametrize("port", ("_", None, 81), ids=lambda x: "port={}".format(x))
10 @pytest.mark.parametrize("host", ("_", "1.1.1.1", "[fe80::1]", "fqdn."), ids=lambda x: "host=" + x)
11 @pytest.mark.parametrize("scheme", ("_", "http", "https", "random"), ids=lambda x: "scheme=" + x)
12 @pytest.mark.parametrize(
13 "base", ("127.0.0.1:8001", "//[::1]/path1", "https://foo.bar:8443/p?query",), ids=lambda x: "base=" + x,
14 )
15 def test_rebuild_uri(base, scheme, host, port, path):
16 ubase = urllib.parse.urlsplit("//" + base if "//" not in base else base)
17 kwargs_prepare = {"scheme": scheme, "host": host, "port": port, "path": path}
18 kwargs = {k: v for k, v in kwargs_prepare.items() if v != "_"}
19 result = tests.rebuild_uri(base, **kwargs)
20 u2 = urllib.parse.urlsplit(result)
21 describe = "rebuild_uri({}, {}) = {}".format(
22 base, ", ".join("{}={}".format(k, v) for k, v in kwargs.items()), result
23 )
24 expect = lambda x, y: x if x != "_" else None or y
25 assert u2.scheme == expect(scheme, ubase.scheme), describe
26 assert u2.hostname == expect(host, ubase.hostname).strip("[]"), describe
27 assert u2.port == expect(port, ubase.port), describe
28 assert u2.path == expect(path, ubase.path), describe