Skip to content

Commit f914ac4

Browse files
committed
pythongh-79096: Fix/improve http cookiejar tests
Fixup of pythonGH-93463: - remove stray print - use proper way to check file mode - add working chmod decorator
1 parent 22df2e0 commit f914ac4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Lib/test/test_http_cookiejar.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for http/cookiejar.py."""
22

33
import os
4+
import stat
45
import sys
56
import re
67
import test.support
@@ -371,33 +372,32 @@ def test_lwp_valueless_cookie(self):
371372
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
372373

373374
@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
375+
@os_helper.skip_unless_working_chmod
374376
def test_lwp_filepermissions(self):
375377
# Cookie file should only be readable by the creator
376378
filename = os_helper.TESTFN
377379
c = LWPCookieJar()
378380
interact_netscape(c, "http://www.acme.com/", 'boo')
379381
try:
380382
c.save(filename, ignore_discard=True)
381-
status = os.stat(filename)
382-
print(status.st_mode)
383-
self.assertEqual(oct(status.st_mode)[-3:], '600')
383+
st = os.stat(filename)
384+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
384385
finally:
385-
try: os.unlink(filename)
386-
except OSError: pass
386+
test.support.unlink(filename)
387387

388388
@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
389+
@os_helper.skip_unless_working_chmod
389390
def test_mozilla_filepermissions(self):
390391
# Cookie file should only be readable by the creator
391392
filename = os_helper.TESTFN
392393
c = MozillaCookieJar()
393394
interact_netscape(c, "http://www.acme.com/", 'boo')
394395
try:
395396
c.save(filename, ignore_discard=True)
396-
status = os.stat(filename)
397-
self.assertEqual(oct(status.st_mode)[-3:], '600')
397+
st = os.stat(filename)
398+
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
398399
finally:
399-
try: os.unlink(filename)
400-
except OSError: pass
400+
test.support.unlink(filename)
401401

402402
def test_bad_magic(self):
403403
# OSErrors (eg. file doesn't exist) are allowed to propagate

0 commit comments

Comments
 (0)