Skip to content

Commit c718b44

Browse files
Fix the test to use the current test support API
test.support.TESTFN and MozillaCookieJar.header no longer exist.
1 parent 3ca5d88 commit c718b44

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

Lib/test/test_http_cookiejar.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CookieJar, DefaultCookiePolicy, LWPCookieJar, MozillaCookieJar,
1717
LoadError, lwp_cookie_str, DEFAULT_HTTP_PORT, escape_path,
1818
reach, is_HDN, domain_match, user_domain_match, request_path,
19-
request_port, request_host)
19+
request_port, request_host, NETSCAPE_HEADER_TEXT)
2020

2121
mswindows = (sys.platform == "win32")
2222

@@ -2049,31 +2049,29 @@ def test_session_cookies(self):
20492049
self.assertNotEqual(counter["session_before"], 0)
20502050

20512051
def test_curl_format(self):
2052-
# Check compatibility with curl / wget cookiejar format.
2053-
# See issue 17164
2054-
filename = test.support.TESTFN
2055-
try:
2056-
expires = int(time.time() + 3600)
2057-
with open(filename, "w") as f:
2058-
f.write(MozillaCookieJar.header)
2059-
f.write("www.foo.com\tFALSE\t/\tFALSE\t%u\tfoo1\tbar\n" %
2060-
expires)
2061-
f.write("www.foo.com\tFALSE\t/\tFALSE\t0\tfoo2\tbar\n")
2062-
f.write("www.foo.com\tFALSE\t/\tFALSE\t\tfoo3\tbar\n")
2063-
c = MozillaCookieJar()
2064-
c.revert(filename)
2065-
self.assertEqual(len(c), 1)
2066-
c.revert(filename, ignore_discard = True)
2067-
self.assertEqual(len(c), 3)
2068-
c.save(filename, ignore_discard = True)
2069-
with open(filename, "r") as f:
2070-
for line in f:
2071-
if line == '\n' or line.startswith('#'):
2072-
continue
2073-
self.assertRegex(line.split('\t')[4], '^\d+$')
2074-
finally:
2075-
try: os.unlink(filename)
2076-
except OSError: pass
2052+
# Check compatibility with the curl and Wget cookie file format,
2053+
# which uses 0 for session cookies (gh-61364).
2054+
filename = os_helper.TESTFN
2055+
self.addCleanup(os_helper.unlink, filename)
2056+
expires = int(time.time() + 3600)
2057+
with open(filename, "w") as f:
2058+
f.write(NETSCAPE_HEADER_TEXT)
2059+
f.write("www.foo.com\tFALSE\t/\tFALSE\t%u\tfoo1\tbar\n" % expires)
2060+
f.write("www.foo.com\tFALSE\t/\tFALSE\t0\tfoo2\tbar\n")
2061+
f.write("www.foo.com\tFALSE\t/\tFALSE\t\tfoo3\tbar\n")
2062+
2063+
c = MozillaCookieJar()
2064+
c.revert(filename)
2065+
self.assertEqual(len(c), 1)
2066+
c.revert(filename, ignore_discard=True)
2067+
self.assertEqual(len(c), 3)
2068+
2069+
# Session cookies are saved with 0, not with an empty field.
2070+
c.save(filename, ignore_discard=True)
2071+
with open(filename) as f:
2072+
for line in f:
2073+
if line.strip() and not line.startswith('#'):
2074+
self.assertRegex(line.split('\t')[4], r'^\d+$')
20772075

20782076

20792077
if __name__ == "__main__":

0 commit comments

Comments
 (0)