def test_all_partition_attribs(flush): "Verifies device, mountpoint, fstype and opts for all partitions" psutil_partitions = psutil.disk_partitions(True) pslib_partitions = P.disk_partitions(0) for i in range(pslib_partitions.nitems): device = ffi.string(pslib_partitions.partitions[i].device) mountpoint = ffi.string(pslib_partitions.partitions[i].mountpoint) fstype = ffi.string(pslib_partitions.partitions[i].fstype) opts = ffi.string(pslib_partitions.partitions[i].opts) found = False for part in psutil_partitions: if all([part.mountpoint == mountpoint, part.device == device, part.fstype == fstype, part.opts == opts]): found = True assert found, """No match for Partition(mountpoint = '{}', device = '{}', fstype = '{}', opts = '{}')""".format( mountpoint, device, fstype, opts )
def test_get_users(flush): psutil_users = psutil.users() pslib_users = P.get_users() for i in range(pslib_users.nitems): username = ffi.string(pslib_users.users[i].username) tty = ffi.string(pslib_users.users[i].tty) hostname = ffi.string(pslib_users.users[i].hostname) tstamp = pslib_users.users[i].tstamp found = False for part in psutil_users: if all([part.name == username, part.terminal == tty, part.host == hostname or (part.host is None and hostname == ''), # special case for behavior on osx part.started == tstamp]): found = True assert found, """No match for User(username = '******', tty = '{}', hostname = '{}', tstamp = '{}')""".format(username, tty, hostname, tstamp)
def test_process(flush): cpid = os.getpid() psu = psutil.Process(cpid) psl = P.get_process(cpid) assert psu.pid == psl.pid assert psu.ppid() == psl.ppid assert psu.name() == ffi.string(psl.name) assert psu.exe() == ffi.string(psl.exe) assert " ".join(psu.cmdline()) == ffi.string(psl.cmdline) assert psu.create_time() == psl.create_time uids = psu.uids() assert uids.real == psl.uid assert uids.effective == psl.euid assert uids.saved == psl.suid gids = psu.gids() assert gids.real == psl.gid assert gids.effective == psl.egid assert gids.saved == psl.sgid assert psu.username() == ffi.string(psl.username) assert psu.terminal() == ffi.string(psl.terminal)
def test_all_partition_attribs(flush): "Verifies device, mountpoint, fstype and opts for all partitions" psutil_partitions = psutil.disk_partitions(True) pslib_partitions = P.disk_partitions(0) for i in range(pslib_partitions.nitems): device = ffi.string(pslib_partitions.partitions[i].device) mountpoint = ffi.string(pslib_partitions.partitions[i].mountpoint) fstype = ffi.string(pslib_partitions.partitions[i].fstype) opts = ffi.string(pslib_partitions.partitions[i].opts) found = False for part in psutil_partitions: if all([ part.mountpoint == mountpoint, part.device == device, part.fstype == fstype, part.opts == opts ]): found = True assert found, """No match for Partition(mountpoint = '{}', device = '{}', fstype = '{}', opts = '{}')""".format( mountpoint, device, fstype, opts)
def test_get_users(flush): psutil_users = psutil.users() pslib_users = P.get_users() for i in range(pslib_users.nitems): username = ffi.string(pslib_users.users[i].username) tty = ffi.string(pslib_users.users[i].tty) hostname = ffi.string(pslib_users.users[i].hostname) tstamp = pslib_users.users[i].tstamp found = False for part in psutil_users: if all([ part.name == username, part.terminal == tty, part.host == hostname or (part.host is None and hostname == ''), # special case for behavior on osx part.started == tstamp ]): found = True assert found, """No match for User(username = '******', tty = '{}', hostname = '{}', tstamp = '{}')""".format( username, tty, hostname, tstamp)
def test_disk_io_counters(flush): psutil_counters = psutil.disk_io_counters(True) pslib_counter_info = P.disk_io_counters() for p in range(pslib_counter_info.nitems): name = ffi.string(pslib_counter_info.iocounters[p].name) readbytes = pslib_counter_info.iocounters[p].readbytes writebytes = pslib_counter_info.iocounters[p].writebytes reads = pslib_counter_info.iocounters[p].reads writes = pslib_counter_info.iocounters[p].writes readtime = pslib_counter_info.iocounters[p].readtime writetime = pslib_counter_info.iocounters[p].writetime assert psutil_counters[name].read_bytes == readbytes assert psutil_counters[name].read_count == reads assert psutil_counters[name].read_time == readtime assert psutil_counters[name].write_bytes == writebytes assert psutil_counters[name].write_count == writes assert psutil_counters[name].write_time == writetime
def test_net_io_counters(flush): psutil_counters = psutil.net_io_counters(True) pslib_counter_info = P.net_io_counters() for p in range(pslib_counter_info.nitems): name = ffi.string(pslib_counter_info.iocounters[p].name) bytes_sent = pslib_counter_info.iocounters[p].bytes_sent bytes_recv = pslib_counter_info.iocounters[p].bytes_recv packets_sent = pslib_counter_info.iocounters[p].packets_sent packets_recv = pslib_counter_info.iocounters[p].packets_recv errin = pslib_counter_info.iocounters[p].errin errout = pslib_counter_info.iocounters[p].errout dropin = pslib_counter_info.iocounters[p].dropin dropout = pslib_counter_info.iocounters[p].dropout assert psutil_counters[name].bytes_sent == bytes_sent assert psutil_counters[name].bytes_recv == bytes_recv assert psutil_counters[name].packets_sent == packets_sent assert psutil_counters[name].packets_recv == packets_recv assert psutil_counters[name].errin == errin assert psutil_counters[name].errout == errout assert psutil_counters[name].dropin == dropin assert psutil_counters[name].dropout == dropout