MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_chown

Method test_chown

Lib/test/test_shutil.py:2217–2307  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2215 @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
2216 @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
2217 def test_chown(self):
2218 dirname = self.mkdtemp()
2219 filename = tempfile.mktemp(dir=dirname)
2220 linkname = os.path.join(dirname, "chown_link")
2221 create_file(filename, 'testing chown function')
2222 os.symlink(filename, linkname)
2223
2224 with self.assertRaises(ValueError):
2225 shutil.chown(filename)
2226
2227 with self.assertRaises(LookupError):
2228 shutil.chown(filename, user='non-existing username')
2229
2230 with self.assertRaises(LookupError):
2231 shutil.chown(filename, group='non-existing groupname')
2232
2233 with self.assertRaises(TypeError):
2234 shutil.chown(filename, b'spam')
2235
2236 with self.assertRaises(TypeError):
2237 shutil.chown(filename, 3.14)
2238
2239 uid = os.getuid()
2240 gid = os.getgid()
2241
2242 def check_chown(path, uid=None, gid=None):
2243 s = os.stat(path)
2244 if uid is not None:
2245 self.assertEqual(uid, s.st_uid)
2246 if gid is not None:
2247 self.assertEqual(gid, s.st_gid)
2248
2249 shutil.chown(filename, uid, gid)
2250 check_chown(filename, uid, gid)
2251 shutil.chown(filename, uid)
2252 check_chown(filename, uid)
2253 shutil.chown(filename, user=uid)
2254 check_chown(filename, uid)
2255 shutil.chown(filename, group=gid)
2256 check_chown(filename, gid=gid)
2257
2258 shutil.chown(dirname, uid, gid)
2259 check_chown(dirname, uid, gid)
2260 shutil.chown(dirname, uid)
2261 check_chown(dirname, uid)
2262 shutil.chown(dirname, user=uid)
2263 check_chown(dirname, uid)
2264 shutil.chown(dirname, group=gid)
2265 check_chown(dirname, gid=gid)
2266
2267 try:
2268 user = pwd.getpwuid(uid)[0]
2269 group = grp.getgrgid(gid)[0]
2270 except KeyError:
2271 # On some systems uid/gid cannot be resolved.
2272 pass
2273 else:
2274 shutil.chown(filename, user, group)

Callers

nothing calls this directly

Calls 9

mkdtempMethod · 0.80
mktempMethod · 0.80
chownMethod · 0.80
addCleanupMethod · 0.80
basenameMethod · 0.80
create_fileFunction · 0.70
joinMethod · 0.45
assertRaisesMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected