Пример #1
0
 def test_process_apis(self):
     p = psutil.Process()
     ns = process_namespace(p)
     for fun, name in ns.iter(ns.getters + ns.setters):
         if WINDOWS:
             fun()
         self.execute(fun)
Пример #2
0
    def test_process_apis_nsp(self):
        def wrapper(fun):
            try:
                fun()
            except psutil.NoSuchProcess:
                pass

        p = psutil.Process(self.spawn_testproc().pid)
        p.terminate()
        p.wait()
        ns = process_namespace(p)
        for fun, name in ns.iter(ns.getters + ns.setters + ns.killers):
            if WINDOWS:
                wrapper(fun)
            self.execute(lambda: wrapper(fun))
Пример #3
0
def proc_info(pid):
    tcase = PsutilTestCase()

    def check_exception(exc, proc, name, ppid):
        tcase.assertEqual(exc.pid, pid)
        tcase.assertEqual(exc.name, name)
        if isinstance(exc, psutil.ZombieProcess):
            # XXX investigate zombie/ppid relation on POSIX
            # tcase.assertEqual(exc.ppid, ppid)
            pass
        elif isinstance(exc, psutil.NoSuchProcess):
            tcase.assertProcessGone(proc)
        str(exc)
        assert exc.msg

    def do_wait():
        if pid != 0:
            try:
                proc.wait(0)
            except psutil.Error as exc:
                check_exception(exc, proc, name, ppid)

    try:
        proc = psutil.Process(pid)
        d = proc.as_dict(['ppid', 'name'])
    except psutil.NoSuchProcess:
        return {}

    name, ppid = d['name'], d['ppid']
    info = {'pid': proc.pid}
    ns = process_namespace(proc)
    with proc.oneshot():
        for fun, fun_name in ns.iter(ns.getters, clear_cache=False):
            try:
                info[fun_name] = fun()
            except psutil.NoSuchProcess as exc:
                check_exception(exc, proc, name, ppid)
                do_wait()
                return info
            except psutil.AccessDenied as exc:
                check_exception(exc, proc, name, ppid)
                continue
        do_wait()
    return info
Пример #4
0
def proc_info(pid):
    tcase = PsutilTestCase()

    def check_exception(exc, proc, name, ppid):
        tcase.assertEqual(exc.pid, pid)
        tcase.assertEqual(exc.name, name)
        if isinstance(exc, psutil.ZombieProcess):
            if exc.ppid is not None:
                tcase.assertGreaterEqual(exc.ppid, 0)
                tcase.assertEqual(exc.ppid, ppid)
        elif isinstance(exc, psutil.NoSuchProcess):
            tcase.assertProcessGone(proc)
        str(exc)
        assert exc.msg

    def do_wait():
        if pid != 0:
            try:
                proc.wait(0)
            except psutil.Error as exc:
                check_exception(exc, proc, name, ppid)

    try:
        proc = psutil.Process(pid)
        d = proc.as_dict(['ppid', 'name'])
    except psutil.NoSuchProcess:
        return {}

    name, ppid = d['name'], d['ppid']
    info = {'pid': proc.pid}
    ns = process_namespace(proc)
    # We don't use oneshot() because in order not to fool
    # check_exception() in case of NSP.
    for fun, fun_name in ns.iter(ns.getters, clear_cache=False):
        try:
            info[fun_name] = fun()
        except psutil.Error as exc:
            check_exception(exc, proc, name, ppid)
            continue
    do_wait()
    return info
Пример #5
0
 def test_process_namespace(self):
     p = psutil.Process()
     ns = process_namespace(p)
     fun = [x for x in ns.iter(ns.getters) if x[1] == 'ppid'][0][0]
     self.assertEqual(fun(), p.ppid())
Пример #6
0
 def test_coverage(self):
     ns = process_namespace(None)
     ns.test_class_coverage(self, ns.getters + ns.setters)
Пример #7
0
 def test_coverage(self):
     p = psutil.Process()
     ns = process_namespace(p)
     for fun, name in ns.iter(ns.getters + ns.setters):
         assert hasattr(self, "test_" + name), name