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


Python hypothesis.settings方法代码示例

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


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

示例1: state_machine

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def state_machine(
    rules_object: type, *args: Any, settings: Optional[dict] = None, **kwargs: Any
) -> None:

    machine = _generate_state_machine(rules_object)
    if hasattr(rules_object, "__init__"):
        # __init__ is treated as a class method
        rules_object.__init__(machine, *args, **kwargs)  # type: ignore
    brownie.rpc.snapshot()

    try:
        sf.run_state_machine_as_test(lambda: machine(), settings=hp_settings(**settings or {}))
    finally:
        if hasattr(machine, "teardown_final"):
            # teardown_final is also a class method
            machine.teardown_final(machine)  # type: ignore 
开发者ID:eth-brownie,项目名称:brownie,代码行数:18,代码来源:stateful.py

示例2: get_single_example

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def get_single_example(strategy: st.SearchStrategy[Case]) -> Case:
    @hypothesis.given(strategy)  # type: ignore
    @hypothesis.settings(  # type: ignore
        database=None,
        max_examples=1,
        deadline=None,
        verbosity=hypothesis.Verbosity.quiet,
        phases=(hypothesis.Phase.generate,),
        suppress_health_check=hypothesis.HealthCheck.all(),
    )
    def example_generating_inner_function(ex: Case) -> None:
        examples.append(ex)

    examples: List[Case] = []
    example_generating_inner_function()
    return examples[0] 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:18,代码来源:_hypothesis.py

示例3: _run_tests

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def _run_tests(  # pylint: disable=too-many-arguments
        self,
        maker: Callable,
        template: Callable,
        settings: hypothesis.settings,
        seed: Optional[int],
        recursion_level: int = 0,
        **kwargs: Any,
    ) -> Generator[events.ExecutionEvent, None, None]:
        """Run tests and recursively run additional tests."""
        if recursion_level > self.stateful_recursion_limit:
            return
        for endpoint, test in maker(template, settings, seed):
            feedback = Feedback(self.stateful, endpoint)
            for event in run_test(endpoint, test, feedback=feedback, recursion_level=recursion_level, **kwargs):
                yield event
                if isinstance(event, events.Interrupted):
                    return
            # Additional tests, generated via the `feedback` instance
            yield from self._run_tests(
                feedback.get_stateful_tests, template, settings, seed, recursion_level=recursion_level + 1, **kwargs
            ) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:24,代码来源:core.py

示例4: _get_worker_kwargs

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def _get_worker_kwargs(self, tasks_queue: Queue, events_queue: Queue, results: TestResultSet) -> Dict[str, Any]:
        return {
            "tasks_queue": tasks_queue,
            "events_queue": events_queue,
            "checks": self.checks,
            "targets": self.targets,
            "settings": self.hypothesis_settings,
            "seed": self.seed,
            "results": results,
            "stateful": self.stateful,
            "stateful_recursion_limit": self.stateful_recursion_limit,
            "kwargs": {
                "auth": self.auth,
                "auth_type": self.auth_type,
                "headers": self.headers,
                "store_interactions": self.store_interactions,
            },
        } 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:20,代码来源:threadpool.py

示例5: test_app_with_parametrize

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_app_with_parametrize(testdir):
    # Regression - missed argument inside "wrapper" in `BaseSchema.parametrize`
    testdir.makepyfile(
        """
    import schemathesis
    from test.apps._flask.app import app
    from hypothesis import settings

    schema = schemathesis.from_wsgi("/schema.yaml", app)

    called = False

    @schema.parametrize()
    @settings(max_examples=1)
    def test(case):
        global called
        called = True
        assert case.endpoint.schema.app is app

    def test_two():
        assert called
"""
    )
    result = testdir.runpytest()
    result.assert_outcomes(passed=3) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:27,代码来源:test_wsgi.py

示例6: test_multiple_hooks_per_spec

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_multiple_hooks_per_spec(schema):
    @schema.hooks.register("before_generate_query")
    def first_hook(context, strategy):
        return strategy.filter(lambda x: x["id"].isdigit())

    @schema.hooks.register("before_generate_query")
    def second_hook(context, strategy):
        return strategy.filter(lambda x: int(x["id"]) % 2 == 0)

    assert schema.hooks.get_all_by_name("before_generate_query") == [first_hook, second_hook]

    strategy = schema.endpoints["/custom_format"]["GET"].as_strategy()

    @given(case=strategy)
    @settings(max_examples=3)
    def test(case):
        assert case.query["id"].isdigit()
        assert int(case.query["id"]) % 2 == 0

    test() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:22,代码来源:test_hooks.py

示例7: test_global_fixup

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_global_fixup(testdir, fast_api_schema):
    # When all fixups are enabled globally
    testdir.makepyfile(
        """
import schemathesis
from hypothesis import settings

schemathesis.fixups.install()
schema = schemathesis.from_dict({schema})

def teardown_module(module):
    schemathesis.fixups.uninstall()
    assert schemathesis.hooks.get_all_by_name("before_load_schema") == []

@schema.parametrize()
@settings(max_examples=1)
def test(case):
    assert 0 < case.query["value"] < 10
    """.format(
            schema=fast_api_schema
        ),
    )
    # Then Fast API schemas that are not compliant should be processed
    result = testdir.runpytest("-s")
    result.assert_outcomes(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:27,代码来源:test_fixups.py

示例8: test_invalid_body_in_get_disable_validation

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_invalid_body_in_get_disable_validation(simple_schema):
    schema = schemathesis.from_dict(simple_schema, validate_schema=False)
    endpoint = Endpoint(
        path="/foo",
        method="GET",
        definition=EndpointDefinition({}, {}, "foo"),
        schema=schema,
        body={"required": ["foo"], "type": "object", "properties": {"foo": {"type": "string"}}},
    )
    strategy = get_case_strategy(endpoint)

    @given(strategy)
    @settings(max_examples=1)
    def test(case):
        assert case.body is not None

    test() 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:19,代码来源:test_hypothesis.py

示例9: test_body

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_body(testdir):
    # When parameter is specified for "body"
    testdir.make_test(
        """
@schema.parametrize(method="POST")
@settings(max_examples=3, deadline=None)
def test_(case):
    assert_int(case.body)
    assert_requests_call(case)
        """,
        paths={
            "/users": {
                "post": {
                    "parameters": [{"name": "id", "in": "body", "required": True, "schema": {"type": "integer"}}],
                    "responses": {"200": {"description": "OK"}},
                }
            }
        },
    )
    # Then the generated test case should contain it in its `body` attribute
    testdir.run_and_assert(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:23,代码来源:test_parameters.py

示例10: test_path

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_path(testdir):
    # When parameter is specified for "path"
    testdir.make_test(
        """
@schema.parametrize(endpoint="/users/{user_id}")
@settings(max_examples=3, deadline=None)
def test_(case):
    assert_int(case.path_parameters["user_id"])
    assert_requests_call(case)
        """,
        paths={
            "/users/{user_id}": {
                "get": {
                    "parameters": [{"name": "user_id", "required": True, "in": "path", "type": "integer"}],
                    "responses": {"200": {"description": "OK"}},
                }
            }
        },
    )
    # Then the generated test case should contain it its `path_parameters` attribute
    testdir.run_and_assert(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:23,代码来源:test_parameters.py

示例11: test_security_definitions_api_key

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_security_definitions_api_key(testdir, schema, location):
    # When schema contains "apiKeySecurity" security definition
    # And it is in query or header
    location = "headers" if location == "header" else location
    testdir.make_test(
        f"""
@schema.parametrize()
@settings(max_examples=1, deadline=None)
def test_(case):
    assert_str(case.{location}["api_key"])
    assert_requests_call(case)
        """,
        schema=schema,
    )
    # Then the generated test case should contain API key in a proper place
    testdir.run_and_assert(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:18,代码来源:test_parameters.py

示例12: test_security_definitions_api_key_cookie

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_security_definitions_api_key_cookie(testdir, simple_openapi):
    # When schema contains "apiKeySecurity" security definition
    # And it is in cookie
    schema = deepcopy(simple_openapi)
    components = schema.setdefault("components", {})
    components["securitySchemes"] = {"api_key": {"type": "apiKey", "name": "api_key", "in": "cookie"}}
    schema["security"] = [{"api_key": []}]
    testdir.make_test(
        """
@schema.parametrize()
@settings(max_examples=1, deadline=None)
def test_(case):
    assert_str(case.cookies["api_key"])
    assert_requests_call(case)
        """,
        schema=schema,
    )
    # Then the generated test case should contain API key in a proper place
    testdir.run_and_assert(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:21,代码来源:test_parameters.py

示例13: test_security_definitions_basic_auth

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_security_definitions_basic_auth(testdir, basic_auth_schema):
    # When schema is using HTTP Basic Auth
    testdir.make_test(
        """
import base64

@schema.parametrize()
@settings(max_examples=1, deadline=None)
def test_(case):
    assert "Authorization" in case.headers
    auth = case.headers["Authorization"]
    assert auth.startswith("Basic ")
    assert isinstance(base64.b64decode(auth[6:]), bytes)
    assert_requests_call(case)
        """,
        schema=basic_auth_schema,
    )
    # Then the generated data should contain a valid "Authorization" header
    testdir.run_and_assert(passed=1) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:21,代码来源:test_parameters.py

示例14: test_bitslist_nested_user_strategy

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_bitslist_nested_user_strategy():
  type_ = [ [Bits10, Bits11, Bits12], Bits13 ]
  limit_dict = {
    1: pst.bits(13, min_value=0, max_value=10)
  }
  print("")
  @hypothesis.given(
    blist = pst.bitslists(type_, limit_dict)
  )
  @hypothesis.settings( max_examples=16 )
  def actual_test( blist ):
    assert blist[0][0].nbits == 10
    assert blist[0][1].nbits == 11
    assert blist[0][2].nbits == 12
    assert blist[1].nbits == 13
    assert 0 <= blist[1] <= 10
    print(blist)

  actual_test() 
开发者ID:pymtl,项目名称:pymtl3,代码行数:21,代码来源:strategies_test.py

示例15: test_nested_point_limited

# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import settings [as 别名]
def test_nested_point_limited():
  limit_dict = {
    'p1': {
      'x': range(0xe0,0xf0),
    },
    'p2': {
      'y': range(0xf0,0x100),
    }
  }

  print("")
  @hypothesis.given(
    bs = pst.bitstructs(NestedPoint, limit_dict)
  )
  @hypothesis.settings( max_examples=16 )
  def actual_test( bs ):
    assert isinstance( bs, NestedPoint )
    assert 0xe0 <= bs.p1.x <= 0xef
    assert 0xf0 <= bs.p2.y <= 0xff
    print( bs )

  actual_test() 
开发者ID:pymtl,项目名称:pymtl3,代码行数:24,代码来源:strategies_test.py


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