8000 Add test. · python/cpython@c78971c · GitHub
[go: up one dir, main page]

Skip to content

Commit c78971c

Browse files
serhiy-storchakasoftins
authored andcommitted
Add test.
1 parent 3cd2974 commit c78971c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Lib/test/test_mailbox.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io
1010
import tempfile
1111
from test import support
12+
from test.support import import_helper
1213
from test.support import os_helper
1314
from test.support import refleak_helper
1415
from test.support import socket_helper
@@ -1081,6 +1082,47 @@ def test_permissions_after_flush(self):
10811082

10821083
self.assertEqual(os.stat(self._path).st_mode, mode)
10831084

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

10851127
class _TestMboxMMDF(_TestSingleFile):
10861128

0 commit comments

Comments
 (0)
0