|
6 | 6 | import time |
7 | 7 | import unittest |
8 | 8 | import urllib.request |
| 9 | +import pathlib |
9 | 10 |
|
10 | 11 | from http.cookiejar import (time2isoz, http2time, iso2time, time2netscape, |
11 | 12 | parse_ns_headers, join_header_words, split_header_words, Cookie, |
@@ -313,6 +314,30 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name): |
313 | 314 |
|
314 | 315 |
|
315 | 316 | class FileCookieJarTests(unittest.TestCase): |
| 317 | + def test_constructor_with_str(self): |
| 318 | + filename = test.support.TESTFN |
| 319 | + c = LWPCookieJar(filename) |
| 320 | + self.assertEqual(c.filename, filename) |
| 321 | + |
| 322 | + def test_constructor_with_path_like(self): |
| 323 | + filename = pathlib.Path(test.support.TESTFN) |
| 324 | + c = LWPCookieJar(filename) |
| 325 | + self.assertEqual(c.filename, os.fspath(filename)) |
| 326 | + |
| 327 | + def test_constructor_with_none(self): |
| 328 | + c = LWPCookieJar(None) |
| 329 | + self.assertIsNone(c.filename) |
| 330 | + |
| 331 | + def test_constructor_with_other_types(self): |
| 332 | + class A: |
| 333 | + pass |
| 334 | + |
| 335 | + for type_ in (int, float, A): |
| 336 | + with self.subTest(filename=type_): |
| 337 | + with self.assertRaises(TypeError): |
| 338 | + instance = type_() |
| 339 | + c = LWPCookieJar(filename=instance) |
| 340 | + |
316 | 341 | def test_lwp_valueless_cookie(self): |
317 | 342 | # cookies with no value should be saved and loaded consistently |
318 | 343 | filename = test.support.TESTFN |
|
0 commit comments