summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urlparse.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-06-25 20:39:26 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-06-25 20:39:26 (GMT)
commita7c781724f32bbc659894e5e1ee9f7f18d1252c6 (patch)
tree835265e85cd19ca63394fc9e7b7ce46027a74808 /Lib/test/test_urlparse.py
parente79f3557cc82f54e9b6b95143b4619b9ad33dccc (diff)
parent89584c97e44b7cc7ca782e8e4c668b0647147f24 (diff)
downloadcpython-a7c781724f32bbc659894e5e1ee9f7f18d1252c6.zip
cpython-a7c781724f32bbc659894e5e1ee9f7f18d1252c6.tar.gz
cpython-a7c781724f32bbc659894e5e1ee9f7f18d1252c6.tar.bz2
Issue #23684: Clarify the return value of the scheme attribute of ParseResult and SplitResult objects.
Patch by Martin Panter.
Diffstat (limited to 'Lib/test/test_urlparse.py')
-rw-r--r--Lib/test/test_urlparse.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 4fa3dc6..0552f90 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -686,6 +686,47 @@ class UrlParseTestCase(unittest.TestCase):
self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query"),
(b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b''))
+ def test_default_scheme(self):
+ # Exercise the scheme parameter of urlparse() and urlsplit()
+ for func in (urllib.parse.urlparse, urllib.parse.urlsplit):
+ with self.subTest(function=func):
+ result = func("http://example.net/", "ftp")
+ self.assertEqual(result.scheme, "http")
+ result = func(b"http://example.net/", b"ftp")
+ self.assertEqual(result.scheme, b"http")
+ self.assertEqual(func("path", "ftp").scheme, "ftp")
+ self.assertEqual(func("path", scheme="ftp").scheme, "ftp")
+ self.assertEqual(func(b"path", scheme=b"ftp").scheme, b"ftp")
+ self.assertEqual(func("path").scheme, "")
+ self.assertEqual(func(b"path").scheme, b"")
+ self.assertEqual(func(b"path", "").scheme, b"")
+
+ def test_parse_fragments(self):
+ # Exercise the allow_fragments parameter of urlparse() and urlsplit()
+ tests = (
+ ("http:#frag", "path"),
+ ("//example.net#frag", "path"),
+ ("index.html#frag", "path"),
+ (";a=b#frag", "params"),
+ ("?a=b#frag", "query"),
+ ("#frag", "path"),
+ )
+ for url, attr in tests:
+ for func in (urllib.parse.urlparse, urllib.parse.urlsplit):
+ if attr == "params" and func is urllib.parse.urlsplit:
+ attr = "path"
+ with self.subTest(url=url, function=func):
+ result = func(url, allow_fragments=False)
+ self.assertEqual(result.fragment, "")
+ self.assertTrue(getattr(result, attr).endswith("#frag"))
+ self.assertEqual(func(url, "", False).fragment, "")
+
+ result = func(url, allow_fragments=True)
+ self.assertEqual(result.fragment, "frag")
+ self.assertFalse(getattr(result, attr).endswith("frag"))
+ self.assertEqual(func(url, "", True).fragment, "frag")
+ self.assertEqual(func(url).fragment, "frag")
+
def test_mixed_types_rejected(self):
# Several functions that process either strings or ASCII encoded bytes
# accept multiple arguments. Check they reject mixed type input