python类text()的实例源码

api_exception.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def api_exceptions(
        draw,
        status_codes=integers(min_value=400, max_value=599),
        titles=text(),
        details=text()
) -> APIExceptionInterface:
    return _APIException(
        draw(status_codes), draw(titles), draw(details)
    )
job.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def jobs(
        draw,
        ids=uuids(),
        statuses=sampled_from(JobInterface.JobStatus),
        parameters=dictionaries(text(), text()),
        results=dictionaries(text(), text()),
        dates_submitted=datetimes(),
        registration_schemas=dictionaries(text(), text()),
        result_schemas=dictionaries(text(), text())
) -> JobInterface:
    """

    :param draw: A function that can take a strategy and draw a datum from it
    :param ids: A hypothesis strategy (statisticians should read "random
        variable"), that represents the set of all valid job IDs
    :param statuses: A hypothesis strategy that samples from the set of all
        allowed job statuses
    :param parameters: A hypothesis strategy that samples from all job
        parameters
    :param results: A hypothesis strategy that represents the possible results
    :param dates_submitted: A hypothesis strategy that represents the
        possible dates that can be submitted
    :param registration_schemas: The possible job registration schemas
    :param result_schemas: The possible job result schemas
    :return: A randomly-generated implementation of :class:`JobInterface`
    """
    return Job(
        draw(ids), draw(statuses), draw(parameters), draw(results),
        draw(dates_submitted),
        draw(registration_schemas),
        draw(result_schemas)
    )
testhypo.py 文件源码 项目:tdda 作者: tdda 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def list_of_strings(draw):
        return [draw(text(min_size=1, average_size=70))
                for i in range(draw(integers(min_value=0, max_value=100)))]
_misc.py 文件源码 项目:stratisd-client-dbus 作者: stratis-storage 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _device_list(minimum):
    """
    Get a device generating strategy.

    :param int minimum: the minimum number of devices, must be at least 0
    """
    return strategies.lists(
       strategies.text(
          alphabet=string.ascii_letters + "/",
          min_size=1
       ),
       min_size=minimum
    )
testhypo.py 文件源码 项目:rexr 作者: noamross 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def list_of_strings(draw):
        return [draw(text(min_size=1, average_size=70))
                for i in range(draw(integers(min_value=0, max_value=100)))]
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def valid_identifier(**kwargs):
    """Return a strategy which generates a valid Python Identifier"""
    if 'min_size' not in kwargs:
        kwargs['min_size'] = 4
    return hs.text(alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", **kwargs)\
        .filter(lambda x: x[0].isalpha() and x.isidentifier() and not (iskeyword(x)))
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _parse_text(source: Union[str, NodeNG]) -> Tuple[astroid.Module, TypeInferer]:
    """Parse source code text and output an AST with type inference performed."""
    # TODO: apparently no literal syntax for empty set in Python3, also cannot do set()
    # TODO: Deal with special case later.
    # if isinstance(source, astroid.Set) and len(list(source.elts)) == 0:
    #     source = f'{set({})}'
    if not isinstance(source, str):  # It's an astroid node
        source = source.as_string()
    module = astroid.parse(source)
    type_inferer = TypeInferer()
    type_inferer.environment_transformer().visit(module)
    type_inferer.type_inference_transformer().visit(module)
    return module, type_inferer
strategies.py 文件源码 项目:txacme 作者: twisted 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def urls():
    """
    Strategy for generating ``twisted.python.url.URL``\s.
    """
    return s.builds(
        URL,
        scheme=s.just(u'https'),
        host=dns_names(),
        path=s.lists(s.text(
            max_size=64,
            alphabet=s.characters(blacklist_characters=u'/?#',
                                  blacklist_categories=('Cs',))
        ), min_size=1, max_size=10))
test_challenges.py 文件源码 项目:txacme 作者: twisted 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_start_responding(self, token):
        """
        Calling ``start_responding`` makes an appropriate resource available.
        """
        challenge = challenges.HTTP01(token=token)
        response = challenge.response(RSA_KEY_512)

        responder = HTTP01Responder()

        challenge_resource = Resource()
        challenge_resource.putChild(b'acme-challenge', responder.resource)
        root = Resource()
        root.putChild(b'.well-known', challenge_resource)
        client = StubTreq(root)

        encoded_token = challenge.encode('token')
        challenge_url = URL(host=u'example.com', path=[
            u'.well-known', u'acme-challenge', encoded_token]).asText()

        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(404))))

        responder.start_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url), succeeded(MatchesAll(
            MatchesStructure(
                code=Equals(200),
                headers=AfterPreprocessing(
                    methodcaller('getRawHeaders', b'content-type'),
                    Equals([b'text/plain']))),
            AfterPreprocessing(methodcaller('content'), succeeded(
                Equals(response.key_authorization.encode('utf-8'))))
        )))

        # Starting twice before stopping doesn't break things
        responder.start_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(200))))

        responder.stop_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(404))))
test_utils.py 文件源码 项目:badoo_scrapy_splash_redis 作者: Supe2015 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_headers_to_scrapy():
    assert headers_to_scrapy(None) == Headers()
    assert headers_to_scrapy({}) == Headers()
    assert headers_to_scrapy([]) == Headers()

    html_headers = Headers({'Content-Type': 'text/html'})

    assert headers_to_scrapy({'Content-Type': 'text/html'}) == html_headers
    assert headers_to_scrapy([('Content-Type', 'text/html')]) == html_headers
    assert headers_to_scrapy([{'name': 'Content-Type', 'value': 'text/html'}]) == html_headers
test_utils.py 文件源码 项目:badoo_scrapy_splash_redis 作者: Supe2015 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_headers_to_scrapy():
    assert headers_to_scrapy(None) == Headers()
    assert headers_to_scrapy({}) == Headers()
    assert headers_to_scrapy([]) == Headers()

    html_headers = Headers({'Content-Type': 'text/html'})

    assert headers_to_scrapy({'Content-Type': 'text/html'}) == html_headers
    assert headers_to_scrapy([('Content-Type', 'text/html')]) == html_headers
    assert headers_to_scrapy([{'name': 'Content-Type', 'value': 'text/html'}]) == html_headers
test_utils.py 文件源码 项目:badoo_scrapy_splash_redis 作者: Supe2015 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_headers_to_scrapy():
    assert headers_to_scrapy(None) == Headers()
    assert headers_to_scrapy({}) == Headers()
    assert headers_to_scrapy([]) == Headers()

    html_headers = Headers({'Content-Type': 'text/html'})

    assert headers_to_scrapy({'Content-Type': 'text/html'}) == html_headers
    assert headers_to_scrapy([('Content-Type', 'text/html')]) == html_headers
    assert headers_to_scrapy([{'name': 'Content-Type', 'value': 'text/html'}]) == html_headers
test_utils.py 文件源码 项目:pyMonet 作者: przemyslawjanpietrzak 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_identity_should_return_first_argument(text, integer):
    assert identity(text) is text
    assert identity(integer) is integer
test_utils.py 文件源码 项目:pyMonet 作者: przemyslawjanpietrzak 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_eq(text):
    assert eq(text, text)
    assert eq(text)(text)
test_semigroups.py 文件源码 项目:pyMonet 作者: przemyslawjanpietrzak 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_fold(integer, text, boolean):

    dictionary = {'key': 'value'}

    assert First(text).fold(identity) is text
    assert All(boolean).fold(identity) is boolean
    assert Sum(integers).fold(identity) is integers
    assert Map(dictionary).fold(identity) is dictionary
test_output.py 文件源码 项目:chandere2 作者: TsarFox 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_write(self, text):
        fake_stderr = FakeOutput()
        fake_stdout = FakeOutput()
        output = Console(output=fake_stdout, error=fake_stderr)

        output.write(*text)
        assert fake_stdout.last_received == " ".join(text) + "\n"

    # Asserts that write_debug only writes when output.debug is True.
test_output.py 文件源码 项目:chandere2 作者: TsarFox 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_write_if_debug(self, info, debug):
        fake_stderr = FakeOutput()
        fake_stdout = FakeOutput()
        output = Console(output=fake_stdout, error=fake_stderr)

        output.write(info)
        output.write_debug(debug)
        assert fake_stdout.last_received == info + "\n"

        output.debug = True
        output.write(info)
        output.write_debug(debug)
        assert fake_stdout.last_received == "DEBUG: %s\n" % debug

    # Asserts that the text is written to stderr with "ERROR: ".
test_output.py 文件源码 项目:chandere2 作者: TsarFox 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_write_stderr(self, text):
        fake_stderr = FakeOutput()
        fake_stdout = FakeOutput()
        output = Console(output=fake_stdout, error=fake_stderr)

        output.write_error(*text)
        assert fake_stderr.last_received == "ERROR: %s\n" % " ".join(text)

    # Asserts that an end is properly appended to all written text.
test_output.py 文件源码 项目:chandere2 作者: TsarFox 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_supply_end(self, text, end):
        fake_stderr = FakeOutput()
        fake_stdout = FakeOutput()
        output = Console(output=fake_stdout, error=fake_stderr)

        output.debug = True
        output.write(text, end=end)
        assert fake_stdout.last_received == text + end

        output.write_debug(text, end=end)
        assert fake_stdout.last_received == "DEBUG: " + text + end

        output.write_error(text, end=end)
        assert fake_stderr.last_received == "ERROR: " + text + end
test_attr_conversions.py 文件源码 项目:pycryptoki 作者: gemalto 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_to_long_fail(self, fail_val):
        """
        to_long() with incompatible params:
        :param fail_val: random data of known incompatible types (floats, text)
        """
        self.force_fail(fail_val, to_long, TypeError)


问题


面经


文章

微信
公众号

扫码关注公众号