From f914ac4620d3fe3fbfb69234a4dcbb58758f502a Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 8 Jun 2022 20:49:52 +0200 Subject: [PATCH] gh-79096: Fix/improve http cookiejar tests Fixup of GH-93463: - remove stray print - use proper way to check file mode - add working chmod decorator --- Lib/test/test_http_cookiejar.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py index 3988bf864fb04b..7d8ee1857a337c 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -1,6 +1,7 @@ """Tests for http/cookiejar.py.""" import os +import stat import sys import re import test.support @@ -371,6 +372,7 @@ def test_lwp_valueless_cookie(self): self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None) @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes") + @os_helper.skip_unless_working_chmod def test_lwp_filepermissions(self): # Cookie file should only be readable by the creator filename = os_helper.TESTFN @@ -378,14 +380,13 @@ def test_lwp_filepermissions(self): interact_netscape(c, "http://www.acme.com/", 'boo') try: c.save(filename, ignore_discard=True) - status = os.stat(filename) - print(status.st_mode) - self.assertEqual(oct(status.st_mode)[-3:], '600') + st = os.stat(filename) + self.assertEqual(stat.S_IMODE(st.st_mode), 0o600) finally: - try: os.unlink(filename) - except OSError: pass + test.support.unlink(filename) @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes") + @os_helper.skip_unless_working_chmod def test_mozilla_filepermissions(self): # Cookie file should only be readable by the creator filename = os_helper.TESTFN @@ -393,11 +394,10 @@ def test_mozilla_filepermissions(self): interact_netscape(c, "http://www.acme.com/", 'boo') try: c.save(filename, ignore_discard=True) - status = os.stat(filename) - self.assertEqual(oct(status.st_mode)[-3:], '600') + st = os.stat(filename) + self.assertEqual(stat.S_IMODE(st.st_mode), 0o600) finally: - try: os.unlink(filename) - except OSError: pass + test.support.unlink(filename) def test_bad_magic(self): # OSErrors (eg. file doesn't exist) are allowed to propagate