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
@@ -366,38 +367,36 @@ def test_lwp_valueless_cookie(self):
366
367
c = LWPCookieJar ()
367
368
c .load (filename , ignore_discard = True )
368
369
finally :
369
- try : os .unlink (filename )
370
- except OSError : pass
370
+ os_helper .unlink (filename )
371
371
self .assertEqual (c ._cookies ["www.acme.com" ]["/" ]["boo" ].value , None )
372
372
373
373
@unittest .skipIf (mswindows , "windows file permissions are incompatible with file modes" )
374
+ @os_helper .skip_unless_working_chmod
374
375
def test_lwp_filepermissions (self ):
375
376
# Cookie file should only be readable by the creator
376
377
filename = os_helper .TESTFN
377
378
c = LWPCookieJar ()
378
379
interact_netscape (c , "http://www.acme.com/" , 'boo' )
379
380
try :
380
381
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 )
384
384
finally :
385
- try : os .unlink (filename )
386
- except OSError : pass
385
+ os_helper .unlink (filename )
387
386
388
387
@unittest .skipIf (mswindows , "windows file permissions are incompatible with file modes" )
388
+ @os_helper .skip_unless_working_chmod
389
389
def test_mozilla_filepermissions (self ):
390
390
# Cookie file should only be readable by the creator
391
391
filename = os_helper .TESTFN
392
392
c = MozillaCookieJar ()
393
393
interact_netscape (c , "http://www.acme.com/" , 'boo' )
394
394
try :
395
395
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 )
398
398
finally :
399
- try : os .unlink (filename )
400
- except OSError : pass
399
+ os_helper .unlink (filename )
401
400
402
401
def test_bad_magic (self ):
403
402
# OSErrors (eg. file doesn't exist) are allowed to propagate
@@ -422,8 +421,7 @@ def test_bad_magic(self):
422
421
c = cookiejar_class ()
423
422
self .assertRaises (LoadError , c .load , filename )
424
423
finally :
425
- try : os .unlink (filename )
426
- except OSError : pass
424
+ os_helper .unlink (filename )
427
425
428
426
class CookieTests (unittest .TestCase ):
429
427
# XXX
@@ -527,7 +525,7 @@ def test_missing_value(self):
527
525
c = MozillaCookieJar (filename )
528
526
c .revert (ignore_expires = True , ignore_discard = True )
529
527
finally :
530
- os .unlink (c .filename )
528
+ os_helper .unlink (c .filename )
531
529
# cookies unchanged apart from lost info re. whether path was specified
532
530
self .assertEqual (
533
531
repr (c ),
@@ -1797,8 +1795,7 @@ def test_rejection(self):
1797
1795
c = LWPCookieJar (policy = pol )
1798
1796
c .load (filename , ignore_discard = True )
1799
1797
finally :
1800
- try : os .unlink (filename )
1801
- except OSError : pass
1798
+ os_helper .unlink (filename )
1802
1799
1803
1800
self .assertEqual (old , repr (c ))
1804
1801
@@ -1857,8 +1854,7 @@ def save_and_restore(cj, ignore_discard):
1857
1854
DefaultCookiePolicy (rfc2965 = True ))
1858
1855
new_c .load (ignore_discard = ignore_discard )
1859
1856
finally :
1860
- try : os .unlink (filename )
1861
- except OSError : pass
1857
+ os_helper .unlink (filename )
1862
1858
return new_c
1863
1859
1864
1860
new_c = save_and_restore (c , True )
0 commit comments