11"""Tests for http/cookiejar.py."""
22
33import os
4+ import stat
45import sys
56import re
67import test .support
@@ -366,38 +367,36 @@ def test_lwp_valueless_cookie(self):
366367 c = LWPCookieJar ()
367368 c .load (filename , ignore_discard = True )
368369 finally :
369- try : os .unlink (filename )
370- except OSError : pass
370+ os_helper .unlink (filename )
371371 self .assertEqual (c ._cookies ["www.acme.com" ]["/" ]["boo" ].value , None )
372372
373373 @unittest .skipIf (mswindows , "windows file permissions are incompatible with file modes" )
374+ @os_helper .skip_unless_working_chmod
374375 def test_lwp_filepermissions (self ):
375376 # Cookie file should only be readable by the creator
376377 filename = os_helper .TESTFN
377378 c = LWPCookieJar ()
378379 interact_netscape (c , "http://www.acme.com/" , 'boo' )
379380 try :
380381 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' )
382+ st = os .stat (filename )
383+ self .assertEqual (stat .S_IMODE (st .st_mode ), 0o600 )
384384 finally :
385- try : os .unlink (filename )
386- except OSError : pass
385+ os_helper .unlink (filename )
387386
388387 @unittest .skipIf (mswindows , "windows file permissions are incompatible with file modes" )
388+ @os_helper .skip_unless_working_chmod
389389 def test_mozilla_filepermissions (self ):
390390 # Cookie file should only be readable by the creator
391391 filename = os_helper .TESTFN
392392 c = MozillaCookieJar ()
393393 interact_netscape (c , "http://www.acme.com/" , 'boo' )
394394 try :
395395 c .save (filename , ignore_discard = True )
396- status = os .stat (filename )
397- self .assertEqual (oct ( status .st_mode )[ - 3 :], '600' )
396+ st = os .stat (filename )
397+ self .assertEqual (stat . S_IMODE ( st .st_mode ), 0o600 )
398398 finally :
399- try : os .unlink (filename )
400- except OSError : pass
399+ os_helper .unlink (filename )
401400
402401 def test_bad_magic (self ):
403402 # OSErrors (eg. file doesn't exist) are allowed to propagate
@@ -422,8 +421,7 @@ def test_bad_magic(self):
422421 c = cookiejar_class ()
423422 self .assertRaises (LoadError , c .load , filename )
424423 finally :
425- try : os .unlink (filename )
426- except OSError : pass
424+ os_helper .unlink (filename )
427425
428426class CookieTests (unittest .TestCase ):
429427 # XXX
@@ -527,7 +525,7 @@ def test_missing_value(self):
527525 c = MozillaCookieJar (filename )
528526 c .revert (ignore_expires = True , ignore_discard = True )
529527 finally :
530- os .unlink (c .filename )
528+ os_helper .unlink (c .filename )
531529 # cookies unchanged apart from lost info re. whether path was specified
532530 self .assertEqual (
533531 repr (c ),
@@ -1797,8 +1795,7 @@ def test_rejection(self):
17971795 c = LWPCookieJar (policy = pol )
17981796 c .load (filename , ignore_discard = True )
17991797 finally :
1800- try : os .unlink (filename )
1801- except OSError : pass
1798+ os_helper .unlink (filename )
18021799
18031800 self .assertEqual (old , repr (c ))
18041801
@@ -1857,8 +1854,7 @@ def save_and_restore(cj, ignore_discard):
18571854 DefaultCookiePolicy (rfc2965 = True ))
18581855 new_c .load (ignore_discard = ignore_discard )
18591856 finally :
1860- try : os .unlink (filename )
1861- except OSError : pass
1857+ os_helper .unlink (filename )
18621858 return new_c
18631859
18641860 new_c = save_and_restore (c , True )
0 commit comments