|
1 | 1 | """Tests for http/cookiejar.py."""
|
2 | 2 |
|
3 | 3 | import os
|
| 4 | +import stat |
4 | 5 | import sys
|
5 | 6 | import re
|
6 | 7 | import test.support
|
@@ -371,33 +372,32 @@ def test_lwp_valueless_cookie(self):
|
371 | 372 | self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
|
372 | 373 |
|
373 | 374 | @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
|
| 375 | + @os_helper.skip_unless_working_chmod |
374 | 376 | def test_lwp_filepermissions(self):
|
375 | 377 | # Cookie file should only be readable by the creator
|
376 | 378 | filename = os_helper.TESTFN
|
377 | 379 | c = LWPCookieJar()
|
378 | 380 | interact_netscape(c, "http://www.acme.com/", 'boo')
|
379 | 381 | try:
|
380 | 382 | 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) |
384 | 385 | finally:
|
385 |
| - try: os.unlink(filename) |
386 |
| - except OSError: pass |
| 386 | + test.support.unlink(filename) |
387 | 387 |
|
388 | 388 | @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
|
| 389 | + @os_helper.skip_unless_working_chmod |
389 | 390 | def test_mozilla_filepermissions(self):
|
390 | 391 | # Cookie file should only be readable by the creator
|
391 | 392 | filename = os_helper.TESTFN
|
392 | 393 | c = MozillaCookieJar()
|
393 | 394 | interact_netscape(c, "http://www.acme.com/", 'boo')
|
394 | 395 | try:
|
395 | 396 | 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) |
398 | 399 | finally:
|
399 |
| - try: os.unlink(filename) |
400 |
| - except OSError: pass |
| 400 | + test.support.unlink(filename) |
401 | 401 |
|
402 | 402 | def test_bad_magic(self):
|
403 | 403 | # OSErrors (eg. file doesn't exist) are allowed to propagate
|
|
0 commit comments