diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2005-12-23 21:24:35 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2005-12-23 21:24:35 (GMT) |
commit | 3e7de59bd2ac22f677f3a053ade22f44785f15f4 (patch) | |
tree | b2f803ac772da9e4be5ff0087b2d783c77ded54e /Lib/test | |
parent | b164dafebb6b73eccdf0ced74c23e8896786b456 (diff) | |
download | cpython-3e7de59bd2ac22f677f3a053ade22f44785f15f4.zip cpython-3e7de59bd2ac22f677f3a053ade22f44785f15f4.tar.gz cpython-3e7de59bd2ac22f677f3a053ade22f44785f15f4.tar.bz2 |
Fix SF #1117398, cookielib LWPCookieJar and MozillaCookieJar exceptions
cookielib.LWPCookieJar and .MozillaCookieJar are documented to raise
cookielib.LoadError on attempt to load an invalid cookies file, but
raise IOError instead. Compromise by having LoadError subclass IOError.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_cookielib.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_cookielib.py b/Lib/test/test_cookielib.py index 7828326..f0c6683 100644 --- a/Lib/test/test_cookielib.py +++ b/Lib/test/test_cookielib.py @@ -248,6 +248,31 @@ class FileCookieJarTests(TestCase): except OSError: pass self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None) + def test_bad_magic(self): + from cookielib import LWPCookieJar, MozillaCookieJar, LoadError + # IOErrors (eg. file doesn't exist) are allowed to propagate + filename = test_support.TESTFN + for cookiejar_class in LWPCookieJar, MozillaCookieJar: + c = cookiejar_class() + try: + c.load(filename="for this test to work, a file with this " + "filename should not exist") + except IOError, exc: + # exactly IOError, not LoadError + self.assertEqual(exc.__class__, IOError) + else: + self.fail("expected IOError for invalid filename") + # Invalid contents of cookies file (eg. bad magic string) + # causes a LoadError. + try: + f = open(filename, "w") + f.write("oops\n") + for cookiejar_class in LWPCookieJar, MozillaCookieJar: + c = cookiejar_class() + self.assertRaises(LoadError, c.load, filename) + finally: + try: os.unlink(filename) + except OSError: pass class CookieTests(TestCase): # XXX |