@@ -232,10 +232,20 @@ def test_mknod(self):
232232 else :
233233 self .assertTrue (stat .S_ISFIFO (posix .stat (support .TESTFN ).st_mode ))
234234
235- def _test_all_chown_common (self , chown_func , first_param ):
235+ def _test_all_chown_common (self , chown_func , first_param , stat_func ):
236236 """Common code for chown, fchown and lchown tests."""
237+ def check_stat ():
238+ if stat_func is not None :
239+ stat = stat_func (first_param )
240+ self .assertEqual (stat .st_uid , os .getuid ())
241+ self .assertEqual (stat .st_gid , os .getgid ())
237242 # test a successful chown call
238243 chown_func (first_param , os .getuid (), os .getgid ())
244+ check_stat ()
245+ chown_func (first_param , - 1 , os .getgid ())
246+ check_stat ()
247+ chown_func (first_param , os .getuid (), - 1 )
248+ check_stat ()
239249
240250 if os .getuid () == 0 :
241251 try :
@@ -255,8 +265,12 @@ def _test_all_chown_common(self, chown_func, first_param):
255265 "behavior" )
256266 else :
257267 # non-root cannot chown to root, raises OSError
258- self .assertRaises (OSError , chown_func ,
259- first_param , 0 , 0 )
268+ self .assertRaises (OSError , chown_func , first_param , 0 , 0 )
269+ check_stat ()
270+ self .assertRaises (OSError , chown_func , first_param , - 1 , 0 )
271+ check_stat ()
272+ self .assertRaises (OSError , chown_func , first_param , 0 , - 1 )
273+ check_stat ()
260274
261275 @unittest .skipUnless (hasattr (posix , 'chown' ), "test needs os.chown()" )
262276 def test_chown (self ):
@@ -266,7 +280,8 @@ def test_chown(self):
266280
267281 # re-create the file
268282 open (support .TESTFN , 'w' ).close ()
269- self ._test_all_chown_common (posix .chown , support .TESTFN )
283+ self ._test_all_chown_common (posix .chown , support .TESTFN ,
284+ getattr (posix , 'stat' , None ))
270285
271286 @unittest .skipUnless (hasattr (posix , 'fchown' ), "test needs os.fchown()" )
272287 def test_fchown (self ):
@@ -276,7 +291,8 @@ def test_fchown(self):
276291 test_file = open (support .TESTFN , 'w' )
277292 try :
278293 fd = test_file .fileno ()
279- self ._test_all_chown_common (posix .fchown , fd )
294+ self ._test_all_chown_common (posix .fchown , fd ,
295+ getattr (posix , 'fstat' , None ))
280296 finally :
281297 test_file .close ()
282298
@@ -285,7 +301,8 @@ def test_lchown(self):
285301 os .unlink (support .TESTFN )
286302 # create a symlink
287303 os .symlink (_DUMMY_SYMLINK , support .TESTFN )
288- self ._test_all_chown_common (posix .lchown , support .TESTFN )
304+ self ._test_all_chown_common (posix .lchown , support .TESTFN ,
305+ getattr (posix , 'lstat' , None ))
289306
290307 def test_chdir (self ):
291308 if hasattr (posix , 'chdir' ):
0 commit comments