当前位置: 首页>>代码示例>>Python>>正文


Python _compat.u函数代码示例

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


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

示例1: _cleanup_files

def _cleanup_files():
    DEVNULL.close()
    for name in os.listdir(u('.')):
        if name.startswith(u(TESTFILE_PREFIX)):
            try:
                safe_rmpath(name)
            except Exception:
                traceback.print_exc()
    for path in _testfiles_created:
        try:
            safe_rmpath(path)
        except Exception:
            traceback.print_exc()
开发者ID:mabuaita,项目名称:ops,代码行数:13,代码来源:__init__.py

示例2: test_proc_cmdline_mocked

 def test_proc_cmdline_mocked(self):
     # see: https://github.com/giampaolo/psutil/issues/639
     p = psutil.Process()
     fake_file = io.StringIO(u('foo\x00bar\x00'))
     with mock.patch('psutil._pslinux.open',
                     return_value=fake_file, create=True) as m:
         p.cmdline() == ['foo', 'bar']
         assert m.called
     fake_file = io.StringIO(u('foo\x00bar\x00\x00'))
     with mock.patch('psutil._pslinux.open',
                     return_value=fake_file, create=True) as m:
         p.cmdline() == ['foo', 'bar', '']
         assert m.called
开发者ID:dpavlenkov,项目名称:psutil,代码行数:13,代码来源:_linux.py

示例3: _cleanup_files

def _cleanup_files():
    DEVNULL.close()
    for name in os.listdir(u('.')):
        if isinstance(name, unicode):
            prefix = u(TESTFILE_PREFIX)
        else:
            prefix = TESTFILE_PREFIX
        if name.startswith(prefix):
            try:
                safe_rmpath(name)
            except Exception:
                traceback.print_exc()
    for path in _testfiles_created:
        try:
            safe_rmpath(path)
        except Exception:
            traceback.print_exc()
开发者ID:jomann09,项目名称:psutil,代码行数:17,代码来源:__init__.py

示例4: expect_exact_path_match

 def expect_exact_path_match(cls):
     # Do not expect psutil to correctly handle unicode paths on
     # Python 2 if os.listdir() is not able either.
     if PY3:
         return True
     else:
         here = '.' if isinstance(cls.funky_name, str) else u('.')
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             return cls.funky_name in os.listdir(here)
开发者ID:marcinkuzminski,项目名称:psutil,代码行数:10,代码来源:test_unicode.py

示例5: cleanup_test_files

def cleanup_test_files():
    logstderr("executing cleanup_test_files() atexit function")
    DEVNULL.close()
    for name in os.listdir(u('.')):
        if isinstance(name, unicode):
            prefix = u(TESTFILE_PREFIX)
        else:
            prefix = TESTFILE_PREFIX
        if name.startswith(prefix):
            logstderr("removing temporary test file %r" % name)
            try:
                safe_rmpath(name)
            except Exception:
                traceback.print_exc()
    for path in _testfiles_created:
        logstderr("removing temporary test file %r" % path)
        try:
            safe_rmpath(path)
        except Exception:
            traceback.print_exc()
开发者ID:eomsoft,项目名称:teleport,代码行数:20,代码来源:__init__.py

示例6: open_mock

        def open_mock(name, *args, **kwargs):
            if name == '/proc/partitions':
                return io.StringIO(textwrap.dedent(u"""\
                    major minor  #blocks  name

                       8        0  488386584 hda
                    """))
            elif name == '/proc/diskstats':
                return io.StringIO(
                    u("   3    1   hda 1 2 3 4"))
            else:
                return orig_open(name, *args, **kwargs)
            return orig_open(name, *args)
开发者ID:Alren-huang,项目名称:psutil,代码行数:13,代码来源:test_linux.py

示例7: test_disk_partitions_mocked

 def test_disk_partitions_mocked(self):
     # Test that ZFS partitions are returned.
     with open("/proc/filesystems", "r") as f:
         data = f.read()
     if 'zfs' in data:
         for part in psutil.disk_partitions():
             if part.fstype == 'zfs':
                 break
         else:
             self.fail("couldn't find any ZFS partition")
     else:
         # No ZFS partitions on this system. Let's fake one.
         fake_file = io.StringIO(u("nodev\tzfs\n"))
         with mock.patch('psutil._pslinux.open',
                         return_value=fake_file, create=True) as m1:
             with mock.patch(
                     'psutil._pslinux.cext.disk_partitions',
                     return_value=[('/dev/sdb3', '/', 'zfs', 'rw')]) as m2:
                 ret = psutil.disk_partitions()
                 assert m1.called
                 assert m2.called
                 assert ret
                 self.assertEqual(ret[0].fstype, 'zfs')
开发者ID:dpavlenkov,项目名称:psutil,代码行数:23,代码来源:_linux.py

示例8: u

# the timeout used in functions which have to wait
GLOBAL_TIMEOUT = 3
# test output verbosity
VERBOSITY = 1 if os.getenv('SILENT') or TOX else 2
# be more tolerant if we're on travis / appveyor in order to avoid
# false positives
if TRAVIS or APPVEYOR:
    NO_RETRIES *= 3
    GLOBAL_TIMEOUT *= 3

# --- files

TESTFILE_PREFIX = '$testfn'
TESTFN = os.path.join(os.path.realpath(os.getcwd()), TESTFILE_PREFIX)
_TESTFN = TESTFN + '-internal'
TESTFN_UNICODE = TESTFN + u("-ƒőő")
ASCII_FS = sys.getfilesystemencoding().lower() in ('ascii', 'us-ascii')

# --- paths

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')
HERE = os.path.abspath(os.path.dirname(__file__))

# --- support

HAS_CPU_AFFINITY = hasattr(psutil.Process, "cpu_affinity")
HAS_CPU_FREQ = hasattr(psutil, "cpu_freq")
HAS_CONNECTIONS_UNIX = POSIX and not SUNOS
HAS_ENVIRON = hasattr(psutil.Process, "environ")
HAS_PROC_IO_COUNTERS = hasattr(psutil.Process, "io_counters")
开发者ID:mabuaita,项目名称:ops,代码行数:31,代码来源:__init__.py

示例9: open_mock

 def open_mock(name, *args, **kwargs):
     if name == ('/proc/partitions'):
         return orig_open(name, *args, **kwargs)
     else:
         return io.StringIO(u("8       1 sda1 2 2 2 2\n"))
     return orig_open(name, *args)
开发者ID:a-d-j-i,项目名称:psutil,代码行数:6,代码来源:test_linux.py


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