[issue20069] Add unit test for os.chown

Vajrasky Kok report at bugs.python.org
Tue Jun 24 17:49:36 CEST 2014


Vajrasky Kok added the comment:

Claudiu, I have revamped the test and put it in dedicated test class. Thanks!

1. About assertRaisesRegex, sorry, you're right. We can use it with "with" statement. Prior to this, I used it like this:

with self.assertRaisesRegex(PermissionError,
                                    "Operation not permitted"):
    bla
    bla

Then I realized I have to use it like this:

with self.assertRaisesRegex(PermissionError,
                                    "Operation not permitted") as _:
    bla
    bla

2. About this code, it is deliberate:

+        with self.assertRaises(PermissionError) as cx:
+            os.chown(support.TESTFN, uid_1, gid)
+            os.chown(support.TESTFN, uid_2, gid)

Normal user does not have permission to use chown to change the user of the file. Basically, I need to find the other user other than the user of support.TESTFN. By using chown with two users, it will be guaranteed the case will be tried.

There is other way though, iterating all users and check whether the user is not the owner of support.TESTFN or not. If you object it, I can use this way.

----------
Added file: http://bugs.python.org/file35771/add_unit_test_os_chown_v4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20069>
_______________________________________


More information about the Python-bugs-list mailing list