def test_xxx(self): with ProcPid() as p: with self.assertRaises(FileNotFoundError): _ = p.xxx with self.assertRaises(FileNotFoundError): p = ProcPid(proc="/xxx") with self.assertRaises(ValueError): p = ProcPid("/xxx")
def test_ProcNet(self): with Proc() as p, ProcPid() as p_: net = p.net net_ = p_.net self.assertIsInstance(net, ProcNet) self.assertIsInstance(net_, ProcNet) self.assertEqual(p.net.tcp[0], p_.net.tcp[0])
def test_mounts(self): with Proc() as p, ProcPid() as p_: self.assertEqual(p.mounts, p_.mounts) self.assertIs(p.mounts, p['mounts']) del p.mounts self.assertIs(p.mounts, p['mounts']) del p['mounts'] self.assertEqual(p.data, {})
def test_personality(self): with ProcPid() as p: self.assertIs(p.personality, p['personality']) del p.personality self.assertIs(p.personality, p['personality']) del p['personality'] self.assertEqual(p.data, {}) self.assertIsInstance(int(p.personality, base=16), int)
def test_cmdline(self): with ProcPid() as p: self.assertIsInstance(p.cmdline, list) self.assertEqual(p.cmdline, ["a\\nb", "c"]) self.assertIs(p.cmdline, p['cmdline']) del p.cmdline self.assertIs(p.cmdline, p['cmdline']) del p['cmdline'] self.assertEqual(p.data, {})
def test_io(self): with ProcPid() as p: self.assertIsInstance(p.io, AttrDict) self.assertEqual(p.io, {'a': 1, 'b': 2}) self.assertIs(p.io, p['io']) del p.io self.assertIs(p.io, p['io']) del p['io'] self.assertEqual(p.data, {})
def test_comm(self): with ProcPid() as p: self.assertIsInstance(p.comm, str) self.assertEqual(p.comm, "ab") self.assertIs(p.comm, p['comm']) del p.comm self.assertIs(p.comm, p['comm']) del p['comm'] self.assertEqual(p.data, {})
def test_stat(self): with ProcPid() as p: self.assertIsInstance(p.stat, AttrDict) self.assertEqual(p.stat.comm, " a \\n b ") self.assertIs(p.stat, p['stat']) del p.stat self.assertIs(p.stat, p['stat']) del p['stat'] self.assertEqual(p.data, {})
def test_numa_maps(self): with ProcPid() as p: self.assertIsInstance(p.numa_maps, AttrDict) self.assertIs(p.numa_maps, p['numa_maps']) del p.numa_maps self.assertIs(p.numa_maps, p['numa_maps']) del p['numa_maps'] self.assertEqual(p.numa_maps['7f7f335d7000'].file, "/lib/x86_64-linux-gnu/ld-2.27.so") self.assertEqual(p.numa_maps['7ffc19d01000'].policy, "default")
def test_maps(self): with ProcPid() as p: self.assertIsInstance(p.maps[0], AttrDict) self.assertIs(p.maps, p['maps']) self.assertIs(p.maps[0].address, p['maps'][0]['address']) self.assertEqual(p.maps[0]['pathname'], "/usr/bin/cat") del p.maps self.assertIs(p.maps, p['maps']) del p['maps'] self.assertEqual(p.data, {})
def test_limits(self): with ProcPid() as p: self.assertIsInstance(p.limits, AttrDict) self.assertEqual(p.limits.stack.soft, 8388608) self.assertEqual(p['limits']['stack']['hard'], -1) self.assertIs(p.limits, p['limits']) del p.limits self.assertIs(p.limits, p['limits']) del p['limits'] self.assertEqual(p.data, {})
def test_environ1(self): with ProcPid() as p: self.assertIsInstance(p.environ, AttrDict) self.assertEqual(p.environ, os.environ) self.assertIs(p.environ, p['environ']) del p.environ self.assertIs(p.environ, p['environ']) self.assertIs(p.environ.PATH, p['environ']['PATH']) del p['environ'] self.assertEqual(p.data, {})
def test_mountinfo(self): with ProcPid() as p: self.assertIsInstance(p.mountinfo[0], AttrDict) self.assertEqual(p.mountinfo[0].major, "0") self.assertIs(p.mountinfo[0].super_options.size, p.mountinfo[0]['super_options']['size']) self.assertEqual(p.mountinfo[0].super_options.nr_inodes, 4088020) del p.mountinfo self.assertIs(p.mountinfo, p['mountinfo']) del p['mountinfo'] self.assertEqual(p.data, {})
def test_statm(self): with ProcPid() as p: self.assertIsInstance(p.statm, AttrDict) for value, key in enumerate( 'size resident shared text lib data dt'.split()): self.assertEqual(p.statm[key], value) self.assertIs(p.statm, p['statm']) del p.statm self.assertIs(p.statm, p['statm']) del p['statm'] self.assertEqual(p.data, {})
def test_status(self): with ProcPid() as p: self.assertIsInstance(p.status, AttrDict) self.assertIsInstance(p.status.Uid.real, Uid) self.assertIsInstance(p.status.Gid.real, Gid) self.assertIsInstance(p.status.Groups[0], Gid) for value, key in enumerate( 'real effective saved_set filesystem'.split()): self.assertEqual(p.status.Uid[key], value) self.assertEqual(p.status.Gid[key], value + 4) self.assertEqual(p.status.Groups[0].name, "root") self.assertIs(p.status, p['status']) del p.status self.assertIs(p.status, p['status']) del p['status'] self.assertEqual(p.data, {})
def test_mounts(self): with ProcPid() as p: self.assertIsInstance(p.mounts[0], AttrDict) self.assertEqual(p.mounts[0].spec, "tmpfs") self.assertEqual(p.mounts[0].file, "/dev/shm") self.assertEqual(p.mounts[0].vfstype, "tmpfs") self.assertEqual(p.mounts[0].mntops, p.mounts[0]['mntops']) self.assertEqual(p.mounts[0].mntops['foo'], 1) self.assertEqual(p.mounts[0].mntops.bar, "baz") self.assertEqual(p.mounts[0].freq, "0") self.assertEqual(p.mounts[0].passno, "0") self.assertIs(p.mounts, p['mounts']) del p.mounts self.assertIs(p.mounts, p['mounts']) del p['mounts'] self.assertEqual(p.data, {})
def test_smaps(self): with patch('_restartable.procfs.ProcPid._maps') as mock_maps: mock_maps.return_value = [ AttrDict({ 'address': '560646741000-560646745000', 'perms': 'r--p', 'offset': '00000000', 'dev': 'fe:01', 'inode': '7078353', 'pathname': '/usr/bin/cat' }) ] with ProcPid() as p: self.assertIsInstance(p.smaps[0], AttrDict) self.assertIs(p.smaps, p['smaps']) self.assertIs(p.smaps[0].address, p['smaps'][0]['address']) self.assertEqual(p.smaps[0]['pathname'], "/usr/bin/cat") self.assertIs(p.smaps[0].Size, p['smaps'][0]['Size']) self.assertEqual(p.smaps[0]['KernelPageSize'], 4) del p.smaps self.assertIs(p.smaps, p['smaps']) del p['smaps'] del p['maps'] self.assertEqual(p.data, {})
def test_ctime(self, *_): with ProcPid() as p: self.assertIsInstance(p.ctime, Time) self.assertEqual(p.ctime, 'Thu Jan 1 00:00:00 1970')
def test_environ2(self): with ProcPid() as p: self.assertIsNone(p.environ)
def test_task(self): with ProcPid() as p: self.assertIsInstance(p.task, list) self.assertIs(p.task, p['task']) self.assertIn(p.pid, p.task)
def test_fd(self, *_): with ProcPid() as p: self.assertIsInstance(p.task, list) self.assertIs(p.fd, p['fd']) self.assertEqual(p['fd/0'], "file")
def test_Proc(self): with Proc() as p, ProcPid() as p_: self.assertIsInstance(p, Proc) self.assertEqual(p.self.pid, p_.pid)
def test_ProcPid(self): with ProcPid() as p, ProcPid(os.getpid()) as p_: self.assertIsInstance(p, ProcPid) self.assertEqual(p.pid, p_.pid) self.assertEqual(p.ctime, p_.ctime)
def test_map_files(self): with ProcPid() as p: address = "-".join( map(lambda _: _.lstrip('0'), p.maps[0].address.split('-'))) self.assertIn(address, p.map_files)
def test_environ2(self): with ProcPid() as p: self.assertIsInstance(p.environ, bytes) self.assertEqual(p.environ, b'\xff\x00')