From bd9138e8be908a363c79d4516cb2e2636529e806 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Sun, 26 Dec 2021 13:13:38 +0200 Subject: [PATCH] Rename test file --- tests/test_routing_utils.py | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 tests/test_routing_utils.py diff --git a/tests/test_routing_utils.py b/tests/test_routing_utils.py new file mode 100644 index 0000000..9b53acc --- /dev/null +++ b/tests/test_routing_utils.py @@ -0,0 +1,128 @@ +import pytest + +from sanic_routing.utils import path_to_parts + + +@pytest.mark.parametrize( + "parts", + ( + ("",), + ("foo",), + ("foo", "", "", ""), + ("foo", "", "bar", r""), + ("foo", r""), + ("foo", r"txt)>", r""), + ("foo", r"", r"txt)d>"), + ( + "iiif", + "", + r"", + r"", + "", + "default.jpg", + ), + ("test", "bc|b)c>", ""), + ("test", ""), + ("path", "to", r"", "thing"), + (r"",), + (r"",), + ), +) +def test_path_to_parts_splitter(parts): + path = "/".join(parts) + assert path_to_parts(f"/{path}") == parts, path + + +@pytest.mark.parametrize( + "parts", + ( + ("foo",), + ("foo", "bar", "baz"), + ("", "bar", "baz"), + ("foo", "", "baz"), + ("foo", "", ""), + ("foo", ""), + ("foo", "", ""), + ("foo", "", "bar", r""), + ("foo", r""), + ( + "iiif", + "", + r"", + r"", + "", + "default", + ), + ("test", "bc|b)c>"), + ("test", r"", ""), + (r"",), + (r"",), + ), +) +def test_path_to_parts_splitter_dot_delimiter(parts): + path = ".".join(parts) + assert path_to_parts(path, delimiter=".") == parts, path + + +@pytest.mark.parametrize( + "path,parts", + ( + (r"/foo///", ("foo", "", "", "")), + ( + r"/foo//bar/", + ("foo", "", "bar", r""), + ), + ( + r"/foo/", + ("foo", r""), + ), + ( + r"/foo/txt)>/", + ("foo", r"txt)>", r""), + ), + ( + r"/foo//txt)d>", + ("foo", r"", r"txt)d>"), + ), + ( + r"/iiif///" + r"//default.jpg", + ( + "iiif", + "", + r"", + r"", + "", + "default.jpg", + ), + ), + (r"/test/bc|b)c>/", ("test", "bc|b)c>", "")), + ( + r"/test/", + ("test", ""), + ), + ( + r"/path/to//thing", + ("path", "to", r"", "thing"), + ), + ("no/start/slash/", ("no", "start", "slash", "")), + ("/%E4%BD%A0%E5%A5%BD/hello", ("%E4%BD%A0%E5%A5%BD", "hello")), + ( + "/πάτι/ᴄᴏᴅᴇ", + ( + "%CF%80%CE%AC%CF%84%CE%B9", + "%E1%B4%84%E1%B4%8F%E1%B4%85%E1%B4%87", + ), + ), + ( + "/юзер///", + ("%D1%8E%D0%B7%D0%B5%D1%80", "", "", ""), + ), + ( + r"/ru/txt)>/", + ("ru", r"txt)>", ""), + ), + ), +) +def test_path_to_parts_splitter_normalization(path, parts): + assert path_to_parts(path) == parts, path