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


Python procutils.which方法代码示例

本文整理汇总了Python中twisted.python.procutils.which方法的典型用法代码示例。如果您正苦于以下问题:Python procutils.which方法的具体用法?Python procutils.which怎么用?Python procutils.which使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.procutils的用法示例。


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

示例1: doNotFailOnNetworkError

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def doNotFailOnNetworkError(func):
    """
    A decorator which makes APIBuilder tests not fail because of intermittent
    network failures -- mamely, APIBuilder being unable to get the "object
    inventory" of other projects.

    @param func: The function to decorate.

    @return: A decorated function which won't fail if the object inventory
        fetching fails.
    """
    @functools.wraps(func)
    def wrapper(*a, **kw):
        try:
            func(*a, **kw)
        except FailTest as e:
            if e.args[0].startswith("'Failed to get object inventory from "):
                raise SkipTest(
                    ("This test is prone to intermittent network errors. "
                     "See ticket 8753. Exception was: {!r}").format(e))
            raise
    return wrapper 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_release.py

示例2: test_findFeatures

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_findFeatures(self):
        """
        When called with L{NewsBuilder._FEATURE}, L{NewsBuilder._findChanges}
        returns a list of bugfix ticket numbers and descriptions as a list of
        two-tuples.
        """
        features = self.builder._findChanges(
            self.project, self.builder._FEATURE)
        self.assertEqual(
            features,
            [(5, "We now support the web."),
             (12, "The widget is more robust."),
             (15,
              "A very long feature which takes many words to describe with "
              "any accuracy was introduced so that the line wrapping behavior "
              "of the news generating code could be verified."),
             (16, "A simpler feature described on multiple lines was added.")]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_release.py

示例3: test_remoteToLocalForwarding

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_remoteToLocalForwarding(self):
        """
        Test that we can use whatever client to forward a port from the server
        to a port locally.
        """
        localPort = self._getFreePort()
        process = ConchTestForwardingProcess(localPort, b'test\n')
        d = self.execute('', process,
                         sshArgs='-N -R %i:127.0.0.1:%i'
                         % (localPort, self.echoPort))
        d.addCallback(self.assertEqual, b'test\n')
        return d



# Conventionally there is a separate adapter object which provides ISession for
# the user, but making the user provide ISession directly works too. This isn't
# a full implementation of ISession though, just enough to make these tests
# pass. 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_conch.py

示例4: test_oldSingleDigitDayOfMonth

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_oldSingleDigitDayOfMonth(self):
        """
        A file with a high-resolution timestamp which falls on a day of the
        month which can be represented by one decimal digit is formatted with
        one padding 0 to preserve the columns which come after it.
        """
        # A point about 7 months in the past, tweaked to fall on the first of a
        # month so we test the case we want to test.
        then = self.now - (60 * 60 * 24 * 31 * 7) + (60 * 60 * 24 * 5)
        stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))

        self.assertEqual(
            self._lsInTimezone('America/New_York', stat),
            '!---------    0 0        0               0 May 01  1973 foo')
        self.assertEqual(
            self._lsInTimezone('Pacific/Auckland', stat),
            '!---------    0 0        0               0 May 02  1973 foo') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_cftp.py

示例5: test_newSingleDigitDayOfMonth

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_newSingleDigitDayOfMonth(self):
        """
        A file with a high-resolution timestamp which falls on a day of the
        month which can be represented by one decimal digit is formatted with
        one padding 0 to preserve the columns which come after it.
        """
        # A point about three months in the past, tweaked to fall on the first
        # of a month so we test the case we want to test.
        then = self.now - (60 * 60 * 24 * 31 * 3) + (60 * 60 * 24 * 4)
        stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))

        self.assertEqual(
            self._lsInTimezone('America/New_York', stat),
            '!---------    0 0        0               0 Sep 01 17:33 foo')
        self.assertEqual(
            self._lsInTimezone('Pacific/Auckland', stat),
            '!---------    0 0        0               0 Sep 02 09:33 foo') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_cftp.py

示例6: parseChunks

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def parseChunks(self, chunks):
        """
        Parse the output from the process to which this protocol was
        connected, which is a single unterminated line of \\0-separated
        strings giving key value pairs of the environment from that process.
        Return this as a dictionary.
        """
        environString = b''.join(chunks)
        if not environString:
            return {}
        environ = iter(environString.split(b'\0'))
        d = {}
        while 1:
            try:
                k = next(environ)
            except StopIteration:
                break
            else:
                v = next(environ)
                d[k] = v
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_process.py

示例7: test_echo

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_echo(self):
        """
        A spawning a subprocess which echoes its stdin to its stdout via
        L{IReactorProcess.spawnProcess} will result in that echoed output being
        delivered to outReceived.
        """
        finished = defer.Deferred()
        p = EchoProtocol(finished)

        scriptPath = b"twisted.test.process_echoer"
        reactor.spawnProcess(p, pyExe, [pyExe, b'-u', b"-m", scriptPath],
                             env=properEnv)

        def asserts(ignored):
            self.assertFalse(p.failure, p.failure)
            self.assertTrue(hasattr(p, 'buffer'))
            self.assertEqual(len(p.buffer), len(p.s * p.n))

        def takedownProcess(err):
            p.transport.closeStdin()
            return err

        return finished.addCallback(asserts).addErrback(takedownProcess) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_process.py

示例8: test_encodableUnicodeEnvironment

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_encodableUnicodeEnvironment(self):
        """
        Test C{os.environ} (inherited by every subprocess on Windows) that
        contains an ascii-encodable Unicode string. This is different from
        passing Unicode environment explicitly to spawnProcess (which is not
        supported on Python 2).
        """
        os.environ[self.goodKey] = self.goodValue
        self.addCleanup(operator.delitem, os.environ, self.goodKey)

        p = GetEnvironmentDictionary.run(reactor, [], properEnv)
        def gotEnvironment(environ):
            self.assertEqual(
                environ[self.goodKey.encode('ascii')],
                self.goodValue.encode('ascii'))
        return p.getResult().addCallback(gotEnvironment) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_process.py

示例9: assert_has_paths

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def assert_has_paths(test_case, expected_paths, parent_path):
    """
    Fail if any of the ``expected_paths`` are not existing relative paths of
    ``parent_path``.

    :param TestCase test_case: The ``TestCase`` with which to make assertions.
    :param list expected_paths: A ``list`` of ``bytes`` relative path names
        which are expected to exist beneath ``parent_path``.
    :param FilePath parent_path: The root ``FilePath`` in which to search for
        ``expected_paths``.
    """
    missing_paths = []
    for path in expected_paths:
        if not parent_path.preauthChild(path).exists():
            missing_paths.append(path)
        if missing_paths:
            test_case.fail('Missing paths: {}'.format(missing_paths)) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:19,代码来源:test_packaging.py

示例10: test_dockerfiles

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_dockerfiles(self):
        """
        Directories in the ``admin/build_targets/`` sub-directory of the path
        passed to ``available_distributions`` which themselves contain a
        ``Dockerfile`` are considered distributions and included in the result.
        """
        root = FilePath(self.mktemp())
        build_targets = root.descendant([b"admin", b"build_targets"])
        build_targets.makedirs()
        build_targets.child(b"foo").setContent(b"bar")
        greatos = build_targets.child(b"greatos")
        greatos.makedirs()
        greatos.child(b"Dockerfile").setContent(
            b"MAINTAINER example@example.invalid\n"
        )
        nothing = build_targets.child(b"nothing")
        nothing.makedirs()

        self.assertEqual(
            {b"greatos"},
            available_distributions(root),
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_packaging.py

示例11: help_problems

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def help_problems(command_name, help_text):
    """Identify and return a list of help text problems.

    :param unicode command_name: The name of the command which should appear in
        the help text.
    :param bytes help_text: The full help text to be inspected.
    :return: A list of problems found with the supplied ``help_text``.
    :rtype: list
    """
    problems = []
    expected_start = u'Usage: {command}'.format(
        command=command_name).encode('utf8')
    if not help_text.startswith(expected_start):
        problems.append(
            'Does not begin with {expected}. Found {actual} instead'.format(
                expected=repr(expected_start),
                actual=repr(help_text[:len(expected_start)])
            )
        )
    return problems 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:__init__.py

示例12: find_free_port

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def find_free_port(interface='127.0.0.1', socket_family=socket.AF_INET,
                   socket_type=socket.SOCK_STREAM):
    """
    Ask the platform to allocate a free port on the specified interface, then
    release the socket and return the address which was allocated.

    Copied from ``twisted.internet.test.connectionmixins.findFreePort``.

    :param bytes interface: The local address to try to bind the port on.
    :param int socket_family: The socket family of port.
    :param int socket_type: The socket type of the port.

    :return: A two-tuple of address and port, like that returned by
        ``socket.getsockname``.
    """
    address = socket.getaddrinfo(interface, 0)[0][4]
    probe = socket.socket(socket_family, socket_type)
    try:
        probe.bind(address)
        return probe.getsockname()
    finally:
        probe.close() 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:__init__.py

示例13: assertContainsAll

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def assertContainsAll(haystack, needles, test_case):
    """
    Assert that all the terms in the needles list are found in the haystack.

    :param test_case: The ``TestCase`` instance on which to call assertions.
    :param list needles: A list of terms to search for in the ``haystack``.
    :param haystack: An iterable in which to search for the terms in needles.
    """
    for needle in reversed(needles):
        if needle in haystack:
            needles.remove(needle)

    if needles:
        test_case.fail(
            '{haystack} did not contain {needles}'.format(
                haystack=haystack, needles=needles
            )
        )


# Skip decorators for tests: 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:23,代码来源:__init__.py

示例14: test_eventual_success

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_eventual_success(self):
        """
        If the configuration changes between when listing and creation occurs
        the operation is retried until it succeeds.
        """
        d = conditional_create(self.client, self.reactor, lambda config: None,
                               primary=self.node_id)
        # Change configuration in between listing and condition check:
        self.successResultOf(self.client.create_dataset(primary=self.node_id))
        # Creation, which should fail with ConfigurationChanged:
        self.advance()
        # List again:
        self.advance()
        # Create again:
        self.advance()
        self.assertIn(self.successResultOf(d),
                      self.successResultOf(
                          self.client.list_datasets_configuration())) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:20,代码来源:test_client.py

示例15: test_eventual_condition_violation

# 需要导入模块: from twisted.python import procutils [as 别名]
# 或者: from twisted.python.procutils import which [as 别名]
def test_eventual_condition_violation(self):
        """
        If a conflict occurs and the condition is violated in a later
        iteration then creation is aborted and the raised exception is
        returned.
        """
        d = conditional_create(self.client, self.reactor,
                               self.unique_key(u"llave"),
                               primary=self.node_id)
        # Change configuration in between listing and condition check:
        self.successResultOf(self.client.create_dataset(primary=self.node_id))
        # Creation, which should fail with ConfigurationChanged:
        self.advance()
        # List again:
        self.advance()
        # Create dataset which will violate the condition:
        self.successResultOf(self.client.create_dataset(
            primary=self.node_id, metadata={u"key": u"llave"}))
        # Create again, which should fail with ConfigurationChanged:
        self.advance()
        # List again, which should fail condition:
        self.advance()
        self.failureResultOf(d, CustomException) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:25,代码来源:test_client.py


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