MCPcopy Index your code
hub / github.com/python/cpython / test_ownership_after_flush

Method test_ownership_after_flush

Lib/test/test_mailbox.py:1092–1127  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1090 @requires_root_user
1091 @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
1092 def test_ownership_after_flush(self):
1093 # See issue gh-117467
1094
1095 pwd = import_helper.import_module('pwd')
1096 grp = import_helper.import_module('grp')
1097 st = os.stat(self._path)
1098
1099 for e in pwd.getpwall():
1100 if e.pw_uid != st.st_uid:
1101 other_uid = e.pw_uid
1102 break
1103 else:
1104 self.skipTest("test needs more than one user")
1105
1106 for e in grp.getgrall():
1107 if e.gr_gid != st.st_gid:
1108 other_gid = e.gr_gid
1109 break
1110 else:
1111 self.skipTest("test needs more than one group")
1112
1113 os.chown(self._path, other_uid, other_gid)
1114 # Change permissions as in test_permissions_after_flush.
1115 mode = st.st_mode | 0o666
1116 os.chmod(self._path, mode)
1117
1118 self._box.add(self._template % 0)
1119 i = self._box.add(self._template % 1)
1120 # Need to remove one message to make flush() create a new file
1121 self._box.remove(i)
1122 self._box.flush()
1123
1124 st = os.stat(self._path)
1125 self.assertEqual(st.st_uid, other_uid)
1126 self.assertEqual(st.st_gid, other_gid)
1127 self.assertEqual(st.st_mode, mode)
1128
1129 def test_context_manager_locks_and_closes(self):
1130 # Context manager locks/unlocks and closes.

Callers

nothing calls this directly

Calls 9

skipTestMethod · 0.80
chownMethod · 0.80
import_moduleMethod · 0.45
statMethod · 0.45
chmodMethod · 0.45
addMethod · 0.45
removeMethod · 0.45
flushMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected