diff options
author | Gregory P. Smith <greg@krypto.org> | 2021-05-12 00:01:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 00:01:44 (GMT) |
commit | d597fdc5fd0e8aa73a783fea27287db669950c15 (patch) | |
tree | 2279592f52acf02a00a412edb72ff625efac232f /Lib/test | |
parent | e9d7f88d5643f7e6387bf994c130503766d7eb92 (diff) | |
download | cpython-d597fdc5fd0e8aa73a783fea27287db669950c15.zip cpython-d597fdc5fd0e8aa73a783fea27287db669950c15.tar.gz cpython-d597fdc5fd0e8aa73a783fea27287db669950c15.tar.bz2 |
bpo-44002: Switch to lru_cache in urllib.parse. (GH-25798)
Switch to lru_cache in urllib.parse.
urllib.parse now uses functool.lru_cache for its internal URL splitting and
quoting caches instead of rolling its own like its the 90s.
The undocumented internal Quoted class API is now deprecated
as it had no reason to be public and no existing OSS users were found.
The clear_cache() API remains undocumented but gets an explicit test as it
is used in a few projects' (twisted, gevent) tests as well as our own regrtest.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_urlparse.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 31943f3..dff9a8e 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -1044,16 +1044,24 @@ class UrlParseTestCase(unittest.TestCase): self.assertEqual(p1.params, 'phone-context=+1-914-555') def test_Quoter_repr(self): - quoter = urllib.parse.Quoter(urllib.parse._ALWAYS_SAFE) + quoter = urllib.parse._Quoter(urllib.parse._ALWAYS_SAFE) self.assertIn('Quoter', repr(quoter)) + def test_clear_cache_for_code_coverage(self): + urllib.parse.clear_cache() + + def test_urllib_parse_getattr_failure(self): + """Test that urllib.parse.__getattr__() fails correctly.""" + with self.assertRaises(AttributeError): + unused = urllib.parse.this_does_not_exist + def test_all(self): expected = [] undocumented = { 'splitattr', 'splithost', 'splitnport', 'splitpasswd', 'splitport', 'splitquery', 'splittag', 'splittype', 'splituser', 'splitvalue', - 'Quoter', 'ResultBase', 'clear_cache', 'to_bytes', 'unwrap', + 'ResultBase', 'clear_cache', 'to_bytes', 'unwrap', } for name in dir(urllib.parse): if name.startswith('_') or name in undocumented: @@ -1245,6 +1253,12 @@ class Utility_Tests(unittest.TestCase): class DeprecationTest(unittest.TestCase): + def test_Quoter_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + old_class = urllib.parse.Quoter + self.assertIs(old_class, urllib.parse._Quoter) + self.assertIn('Quoter will be removed', str(cm.warning)) + def test_splittype_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splittype('') |