This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Concept map JSON serialization (#285)
## What is the goal of this PR? We implement the JSON serialization of concept maps according to typedb/typedb-behaviour#238.
- Loading branch information
1 parent
c24395f
commit e65a06b
Showing
9 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# Copyright (C) 2022 Vaticle | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
package(default_visibility = ["//tests/behaviour:__subpackages__"]) | ||
load("//tools:behave_rule.bzl", "typedb_behaviour_py_test") | ||
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") | ||
|
||
py_library( | ||
name = "steps", | ||
srcs = ["serialization_steps.py"], | ||
deps = [], | ||
) | ||
|
||
typedb_behaviour_py_test( | ||
name = "test", | ||
feats = ["@vaticle_typedb_behaviour//concept:serialization.feature"], | ||
background_core = ["//tests/behaviour/background:core"], | ||
background_cluster = ["//tests/behaviour/background:cluster"], | ||
steps = [ | ||
":steps", | ||
"//tests/behaviour/typeql:steps", | ||
"//tests/behaviour/connection:steps", | ||
"//tests/behaviour/connection/database:steps", | ||
"//tests/behaviour/connection/session:steps", | ||
"//tests/behaviour/connection/transaction:steps", | ||
], | ||
deps = [ | ||
"//:client_python", | ||
"//tests/behaviour:context", | ||
"//tests/behaviour/util:util", | ||
"//tests/behaviour/config:parameters", | ||
"//tests/behaviour/background", | ||
], | ||
native_typedb_artifact = "//tests:native-typedb-artifact", | ||
native_typedb_cluster_artifact = "//tests:native-typedb-cluster-artifact", | ||
size = "medium", | ||
) | ||
|
||
checkstyle_test( | ||
name = "checkstyle", | ||
include = glob(["*"]), | ||
license_type = "apache-header", | ||
size = "small", | ||
) |
55 changes: 55 additions & 0 deletions
55
tests/behaviour/concept/serialization/serialization_steps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# | ||
# Copyright (C) 2022 Vaticle | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import json | ||
from collections import Counter | ||
from hamcrest.core.base_matcher import BaseMatcher | ||
from typing import TypeVar, List, Generic | ||
|
||
from behave import * | ||
from hamcrest import * | ||
|
||
from tests.behaviour.context import Context | ||
|
||
T = TypeVar('T') | ||
|
||
|
||
class UnorderedEqualTo(BaseMatcher, Generic[T]): | ||
def __init__(self, expected: List[T]): | ||
self.expected = Counter([json.dumps(item, sort_keys=True) for item in expected]) | ||
|
||
def _matches(self, actual: List[T]) -> bool: | ||
actual = Counter([json.dumps(item, sort_keys=True) for item in actual]) | ||
return actual == self.expected | ||
|
||
def describe_to(self, description): | ||
description.append_text('is equal, in any order, to ').append_text(repr(self.expected)) | ||
|
||
|
||
def unordered_equal_to(expected: List[T]) -> UnorderedEqualTo[T]: | ||
return UnorderedEqualTo(expected) | ||
|
||
|
||
@step("JSON of answer concepts matches") | ||
def step_impl(context: Context): | ||
expected = json.loads(context.text) | ||
actual = [answer.json() for answer in context.answers] | ||
assert_that(actual, unordered_equal_to(expected)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters