Skip to content

Commit

Permalink
perf: Additional benchmarks for get_operation_by_reference
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
  • Loading branch information
Stranger6667 committed May 15, 2024
1 parent dff97d4 commit 66e847f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 20 additions & 7 deletions benches/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def test_get_operation(raw_schema, key):

# Schemas with pre-populated cache
BBCI_OPERATION_ID = "Get_Categories_"
BBCI_SCHEMA_FOR_OPERATION_ID = schemathesis.from_dict(BBCI)
BBCI_SCHEMA_FOR_OPERATION_ID.get_operation_by_id(BBCI_OPERATION_ID)
BBCI_SCHEMA_WITH_OPERATIONS_CACHE = schemathesis.from_dict(BBCI)
BBCI_SCHEMA_WITH_OPERATIONS_CACHE.get_operation_by_id(BBCI_OPERATION_ID)
VMWARE_OPERATION_ID = "listProblemEvents"
VMWARE_SCHEMA_FOR_OPERATION_ID = schemathesis.from_dict(VMWARE)
VMWARE_SCHEMA_FOR_OPERATION_ID.get_operation_by_id(VMWARE_OPERATION_ID)
VMWARE_SCHEMA_WITH_OPERATIONS_CACHE = schemathesis.from_dict(VMWARE)
VMWARE_SCHEMA_WITH_OPERATIONS_CACHE.get_operation_by_id(VMWARE_OPERATION_ID)


@pytest.mark.benchmark
Expand All @@ -79,8 +79,8 @@ def test_get_operation_by_id_single(raw_schema, key):
@pytest.mark.parametrize(
"schema, key",
[
(BBCI_SCHEMA_FOR_OPERATION_ID, BBCI_OPERATION_ID),
(VMWARE_SCHEMA_FOR_OPERATION_ID, VMWARE_OPERATION_ID),
(BBCI_SCHEMA_WITH_OPERATIONS_CACHE, BBCI_OPERATION_ID),
(VMWARE_SCHEMA_WITH_OPERATIONS_CACHE, VMWARE_OPERATION_ID),
],
ids=("bbci", "vmware"),
)
Expand All @@ -97,11 +97,24 @@ def test_get_operation_by_id_repeatedly(schema, key):
],
ids=("bbci", "vmware"),
)
def test_get_operation_by_reference(raw_schema, key):
def test_get_operation_by_reference_single(raw_schema, key):
schema = schemathesis.from_dict(raw_schema)
_ = schema.get_operation_by_reference(key)


@pytest.mark.benchmark
@pytest.mark.parametrize(
"schema, key",
[
(BBCI_SCHEMA_WITH_OPERATIONS_CACHE, "#/paths/~1categories/get"),
(VMWARE_SCHEMA_WITH_OPERATIONS_CACHE, "#/paths/~1entities~1problems/get"),
],
ids=("bbci", "vmware"),
)
def test_get_operation_by_reference_repeatedly(schema, key):
_ = schema.get_operation_by_reference(key)


@pytest.mark.benchmark
@pytest.mark.parametrize("operations", [BBCI_OPERATIONS, VMWARE_OPERATIONS], ids=("bbci", "vmware"))
def test_as_json_schema(operations):
Expand Down
15 changes: 8 additions & 7 deletions test/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,18 @@ def test_schema_error_on_path(simple_schema):


@pytest.mark.parametrize(
"operation_id, path, method",
"operation_id, reference, path, method",
(
("getFoo", "/foo", "GET"),
("postBar", "/bar", "POST"),
("getFoo", "#/paths/~1foo/get", "/foo", "GET"),
("postBar", "#/paths/~1bar/post", "/bar", "POST"),
),
)
def test_get_operation_by_id(operation_id, path, method):
def test_get_operation(operation_id, reference, path, method):
schema = schemathesis.from_dict(SCHEMA)
operation = schema.get_operation_by_id(operation_id)
assert operation.path == path
assert operation.method.upper() == method
for getter, key in ((schema.get_operation_by_id, operation_id), (schema.get_operation_by_reference, reference)):
operation = getter(key)
assert operation.path == path
assert operation.method.upper() == method


def test_get_operation_by_id_in_referenced_path(empty_open_api_3_schema):
Expand Down

0 comments on commit 66e847f

Please sign in to comment.