• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tests.sh函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中psutil.tests.sh函数的典型用法代码示例。如果您正苦于以下问题:Python sh函数的具体用法?Python sh怎么用?Python sh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sh函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_virtual_memory

    def test_virtual_memory(self):
        out = sh('/usr/bin/svmon -O unit=KB')
        re_pattern = "memory\s*"
        for field in ("size inuse free pin virtual available mmode").split():
            re_pattern += "(?P<%s>\S+)\s+" % (field,)
        matchobj = re.search(re_pattern, out)

        self.assertIsNotNone(
            matchobj, "svmon command returned unexpected output")

        KB = 1024
        total = int(matchobj.group("size")) * KB
        available = int(matchobj.group("available")) * KB
        used = int(matchobj.group("inuse")) * KB
        free = int(matchobj.group("free")) * KB

        psutil_result = psutil.virtual_memory()

        # MEMORY_TOLERANCE from psutil.tests is not enough. For some reason
        # we're seeing differences of ~1.2 MB. 2 MB is still a good tolerance
        # when compared to GBs.
        MEMORY_TOLERANCE = 2 * KB * KB   # 2 MB
        self.assertEqual(psutil_result.total, total)
        self.assertAlmostEqual(
            psutil_result.used, used, delta=MEMORY_TOLERANCE)
        self.assertAlmostEqual(
            psutil_result.available, available, delta=MEMORY_TOLERANCE)
        self.assertAlmostEqual(
            psutil_result.free, free, delta=MEMORY_TOLERANCE)
开发者ID:Colorado4Wheeler,项目名称:Mac-Commander,代码行数:29,代码来源:test_aix.py


示例2: test_get_kernel_version

 def test_get_kernel_version(self):
     if not POSIX:
         self.assertEqual(get_kernel_version(), tuple())
     else:
         kernel = get_kernel_version()
         assert kernel, kernel
         self.assertIn('.'.join(map(str, kernel)), sh("uname -a"))
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:7,代码来源:test_testutils.py


示例3: test_process_create_time

 def test_process_create_time(self):
     output = sh("ps -o lstart -p %s" % self.pid)
     start_ps = output.replace('STARTED', '').strip()
     start_psutil = psutil.Process(self.pid).create_time()
     start_psutil = time.strftime("%a %b %e %H:%M:%S %Y",
                                  time.localtime(start_psutil))
     self.assertEqual(start_ps, start_psutil)
开发者ID:jomann09,项目名称:psutil,代码行数:7,代码来源:test_bsd.py


示例4: test_memory_maps

 def test_memory_maps(self):
     src = textwrap.dedent("""
         import time
         with open("%s", "w") as f:
             time.sleep(10)
         """ % TESTFN)
     sproc = pyrun(src)
     self.addCleanup(reap_children)
     call_until(lambda: os.listdir('.'), "'%s' not in ret" % TESTFN)
     p = psutil.Process(sproc.pid)
     time.sleep(.1)
     maps = p.memory_maps(grouped=False)
     pmap = sh('pmap -x %s' % p.pid).split('\n')
     # get rid of header
     del pmap[0]
     del pmap[0]
     while maps and pmap:
         this = maps.pop(0)
         other = pmap.pop(0)
         addr, _, rss, dirty, mode, path = other.split(None, 5)
         if not path.startswith('[') and not path.endswith(']'):
             self.assertEqual(path, os.path.basename(this.path))
         self.assertEqual(int(rss) * 1024, this.rss)
         # test only rwx chars, ignore 's' and 'p'
         self.assertEqual(mode[:3], this.perms[:3])
开发者ID:Alren-huang,项目名称:psutil,代码行数:25,代码来源:test_linux.py


示例5: test_cpu_stats

    def test_cpu_stats(self):
        out = sh('/usr/bin/mpstat -a')

        re_pattern = "ALL\s*"
        for field in ("min maj mpcs mpcr dev soft dec ph cs ics bound rq "
                      "push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd "
                      "sysc").split():
            re_pattern += "(?P<%s>\S+)\s+" % (field,)
        matchobj = re.search(re_pattern, out)

        self.assertIsNotNone(
            matchobj, "mpstat command returned unexpected output")

        # numbers are usually in the millions so 1000 is ok for tolerance
        CPU_STATS_TOLERANCE = 1000
        psutil_result = psutil.cpu_stats()
        self.assertAlmostEqual(
            psutil_result.ctx_switches,
            int(matchobj.group("cs")),
            delta=CPU_STATS_TOLERANCE)
        self.assertAlmostEqual(
            psutil_result.syscalls,
            int(matchobj.group("sysc")),
            delta=CPU_STATS_TOLERANCE)
        self.assertAlmostEqual(
            psutil_result.interrupts,
            int(matchobj.group("dev")),
            delta=CPU_STATS_TOLERANCE)
        self.assertAlmostEqual(
            psutil_result.soft_interrupts,
            int(matchobj.group("soft")),
            delta=CPU_STATS_TOLERANCE)
开发者ID:Colorado4Wheeler,项目名称:Mac-Commander,代码行数:32,代码来源:test_aix.py


示例6: test_swapmem_total

 def test_swapmem_total(self):
     out = sh('sysctl vm.swapusage')
     out = out.replace('vm.swapusage: ', '')
     total, used, free = re.findall('\d+.\d+\w', out)
     psutil_smem = psutil.swap_memory()
     self.assertEqual(psutil_smem.total, human2bytes(total))
     self.assertEqual(psutil_smem.used, human2bytes(used))
     self.assertEqual(psutil_smem.free, human2bytes(free))
开发者ID:4sp1r3,项目名称:psutil,代码行数:8,代码来源:test_osx.py


示例7: test_sensors_battery

 def test_sensors_battery(self):
     out = sh("pmset -g batt")
     percent = re.search("(\d+)%", out).group(1)
     drawing_from = re.search("Now drawing from '([^']+)'", out).group(1)
     power_plugged = drawing_from == "AC Power"
     psutil_result = psutil.sensors_battery()
     self.assertEqual(psutil_result.power_plugged, power_plugged)
     self.assertEqual(psutil_result.percent, int(percent))
开发者ID:eomsoft,项目名称:teleport,代码行数:8,代码来源:test_osx.py


示例8: free_swap

def free_swap():
    """Parse 'free' cmd and return swap memory's s total, used and free
    values.
    """
    lines = sh('free').split('\n')
    for line in lines:
        if line.startswith('Swap'):
            _, total, used, free = line.split()
    return (int(total) * 1024, int(used) * 1024, int(free) * 1024)
开发者ID:a-d-j-i,项目名称:psutil,代码行数:9,代码来源:test_linux.py


示例9: test_users

 def test_users(self):
     out = sh("who")
     lines = out.split('\n')
     users = [x.split()[0] for x in lines]
     terminals = [x.split()[1] for x in lines]
     self.assertEqual(len(users), len(psutil.users()))
     for u in psutil.users():
         self.assertIn(u.name, users)
         self.assertIn(u.terminal, terminals)
开发者ID:jomann09,项目名称:psutil,代码行数:9,代码来源:test_posix.py


示例10: df

 def df(device):
     out = sh("df -k %s" % device).strip()
     line = out.split('\n')[1]
     fields = line.split()
     total = int(fields[1]) * 1024
     used = int(fields[2]) * 1024
     free = int(fields[3]) * 1024
     percent = float(fields[4].replace('%', ''))
     return (total, used, free, percent)
开发者ID:jomann09,项目名称:psutil,代码行数:9,代码来源:test_posix.py


示例11: test_nic_names

 def test_nic_names(self):
     out = sh('ipconfig /all')
     nics = psutil.net_io_counters(pernic=True).keys()
     for nic in nics:
         if "pseudo-interface" in nic.replace(' ', '-').lower():
             continue
         if nic not in out:
             self.fail(
                 "%r nic wasn't found in 'ipconfig /all' output" % nic)
开发者ID:Colorado4Wheeler,项目名称:Mac-Commander,代码行数:9,代码来源:test_windows.py


示例12: vm_stat

def vm_stat(field):
    """Wrapper around 'vm_stat' cmdline utility."""
    out = sh('vm_stat')
    for line in out.split('\n'):
        if field in line:
            break
    else:
        raise ValueError("line not found")
    return int(re.search(r'\d+', line).group(0)) * PAGESIZE
开发者ID:eomsoft,项目名称:teleport,代码行数:9,代码来源:test_osx.py


示例13: test_users

 def test_users(self):
     out = sh("who")
     lines = out.split('\n')
     users = [x.split()[0] for x in lines]
     self.assertEqual(len(users), len(psutil.users()))
     terminals = [x.split()[1] for x in lines]
     for u in psutil.users():
         self.assertTrue(u.name in users, u.name)
         self.assertTrue(u.terminal in terminals, u.terminal)
开发者ID:DipoChiang,项目名称:DjangoCourse,代码行数:9,代码来源:test_posix.py


示例14: muse

def muse(field):
    """Thin wrapper around 'muse' cmdline utility."""
    out = sh('muse')
    for line in out.split('\n'):
        if line.startswith(field):
            break
    else:
        raise ValueError("line not found")
    return int(line.split()[1])
开发者ID:adwalvekar,项目名称:personal-website,代码行数:9,代码来源:test_bsd.py


示例15: test_net_if_stats

 def test_net_if_stats(self):
     for name, stats in psutil.net_if_stats().items():
         try:
             out = sh("ifconfig %s" % name)
         except RuntimeError:
             pass
         else:
             self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
             self.assertEqual(stats.mtu,
                              int(re.findall(r'mtu (\d+)', out)[0]))
开发者ID:eomsoft,项目名称:teleport,代码行数:10,代码来源:test_osx.py


示例16: sysctl

def sysctl(cmdline):
    """Expects a sysctl command with an argument and parse the result
    returning only the value of interest.
    """
    out = sh(cmdline)
    result = out.split()[1]
    try:
        return int(result)
    except ValueError:
        return result
开发者ID:eomsoft,项目名称:teleport,代码行数:10,代码来源:test_osx.py


示例17: test_nic_names

 def test_nic_names(self):
     output = sh("ifconfig -a")
     for nic in psutil.net_io_counters(pernic=True).keys():
         for line in output.split():
             if line.startswith(nic):
                 break
         else:
             self.fail(
                 "couldn't find %s nic in 'ifconfig -a' output\n%s" % (
                     nic, output))
开发者ID:jomann09,项目名称:psutil,代码行数:10,代码来源:test_posix.py


示例18: free_physmem

def free_physmem():
    """Parse 'free' cmd and return physical memory's total, used
    and free values.
    """
    lines = sh('free').split('\n')
    for line in lines:
        if line.startswith('Mem'):
            total, used, free, shared, buffers, cached = \
                [int(x) * 1024 for x in line.split()[1:]]
    return (total, used, free, shared, buffers, cached)
开发者ID:a-d-j-i,项目名称:psutil,代码行数:10,代码来源:test_linux.py


示例19: df

 def df(path):
     out = sh('df -P -B 1 "%s"' % path).strip()
     lines = out.split('\n')
     lines.pop(0)
     line = lines.pop(0)
     dev, total, used, free = line.split()[:4]
     if dev == 'none':
         dev = ''
     total, used, free = int(total), int(used), int(free)
     return dev, total, used, free
开发者ID:Alren-huang,项目名称:psutil,代码行数:10,代码来源:test_linux.py


示例20: free_swap

def free_swap():
    """Parse 'free' cmd and return swap memory's s total, used and free
    values.
    """
    lines = sh('free').split('\n')
    for line in lines:
        if line.startswith('Swap'):
            _, total, used, free = line.split()
            return (int(total) * 1024, int(used) * 1024, int(free) * 1024)
    raise ValueError(
        "can't find 'Swap' in 'free' output:\n%s" % '\n'.join(lines))
开发者ID:Alren-huang,项目名称:psutil,代码行数:11,代码来源:test_linux.py



注:本文中的psutil.tests.sh函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mock.patch函数代码示例发布时间:2022-05-25
下一篇:
Python tests.reap_children函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap