當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。