Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 376aa6b

Browse files
JSON serialization fixes (#287)
## What is the goal of this PR? We update serialization API from `json()` to more canonical `to_json()` and update the BDD test steps to reflect the changes in typedb-behaviour (typedb/typedb-behaviour#240).
1 parent e65a06b commit 376aa6b

File tree

9 files changed

+72
-42
lines changed

9 files changed

+72
-42
lines changed

dependencies/vaticle/repositories.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def vaticle_typedb_behaviour():
3939
git_repository(
4040
name = "vaticle_typedb_behaviour",
4141
remote = "https://github.com/vaticle/typedb-behaviour",
42-
commit = "46619244d5f1773505eeacf6d5bd0ae71781f8e8" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
42+
commit = "ff4f58b4db2200b907c60b28a2b8ee661449e9c0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
4343
)

tests/behaviour/concept/serialization/BUILD

-32
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,8 @@
2020
#
2121

2222
package(default_visibility = ["//tests/behaviour:__subpackages__"])
23-
load("//tools:behave_rule.bzl", "typedb_behaviour_py_test")
2423
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
2524

26-
py_library(
27-
name = "steps",
28-
srcs = ["serialization_steps.py"],
29-
deps = [],
30-
)
31-
32-
typedb_behaviour_py_test(
33-
name = "test",
34-
feats = ["@vaticle_typedb_behaviour//concept:serialization.feature"],
35-
background_core = ["//tests/behaviour/background:core"],
36-
background_cluster = ["//tests/behaviour/background:cluster"],
37-
steps = [
38-
":steps",
39-
"//tests/behaviour/typeql:steps",
40-
"//tests/behaviour/connection:steps",
41-
"//tests/behaviour/connection/database:steps",
42-
"//tests/behaviour/connection/session:steps",
43-
"//tests/behaviour/connection/transaction:steps",
44-
],
45-
deps = [
46-
"//:client_python",
47-
"//tests/behaviour:context",
48-
"//tests/behaviour/util:util",
49-
"//tests/behaviour/config:parameters",
50-
"//tests/behaviour/background",
51-
],
52-
native_typedb_artifact = "//tests:native-typedb-artifact",
53-
native_typedb_cluster_artifact = "//tests:native-typedb-cluster-artifact",
54-
size = "medium",
55-
)
56-
5725
checkstyle_test(
5826
name = "checkstyle",
5927
include = glob(["*"]),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# Copyright (C) 2022 Vaticle
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
# KIND, either express or implied. See the License for the
18+
# specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
22+
package(default_visibility = ["//tests/behaviour:__subpackages__"])
23+
load("//tools:behave_rule.bzl", "typedb_behaviour_py_test")
24+
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
25+
26+
py_library(
27+
name = "steps",
28+
srcs = ["json_steps.py"],
29+
deps = [],
30+
)
31+
32+
typedb_behaviour_py_test(
33+
name = "test",
34+
feats = ["@vaticle_typedb_behaviour//concept/serialization:json.feature"],
35+
background_core = ["//tests/behaviour/background:core"],
36+
background_cluster = ["//tests/behaviour/background:cluster"],
37+
steps = [
38+
":steps",
39+
"//tests/behaviour/typeql:steps",
40+
"//tests/behaviour/connection:steps",
41+
"//tests/behaviour/connection/database:steps",
42+
"//tests/behaviour/connection/session:steps",
43+
"//tests/behaviour/connection/transaction:steps",
44+
],
45+
deps = [
46+
"//:client_python",
47+
"//tests/behaviour:context",
48+
"//tests/behaviour/util:util",
49+
"//tests/behaviour/config:parameters",
50+
"//tests/behaviour/background",
51+
],
52+
native_typedb_artifact = "//tests:native-typedb-artifact",
53+
native_typedb_cluster_artifact = "//tests:native-typedb-cluster-artifact",
54+
size = "medium",
55+
)
56+
57+
checkstyle_test(
58+
name = "checkstyle",
59+
include = glob(["*"]),
60+
license_type = "apache-header",
61+
size = "small",
62+
)

tests/behaviour/concept/serialization/serialization_steps.py renamed to tests/behaviour/concept/serialization/json/json_steps.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def unordered_equal_to(expected: List[T]) -> UnorderedEqualTo[T]:
4848
return UnorderedEqualTo(expected)
4949

5050

51-
@step("JSON of answer concepts matches")
51+
@step("JSON serialization of answers matches")
5252
def step_impl(context: Context):
5353
expected = json.loads(context.text)
54-
actual = [answer.json() for answer in context.answers]
54+
actual = [answer.to_json() for answer in context.answers]
5555
assert_that(actual, unordered_equal_to(expected))

typedb/api/answer/concept_map.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def get(self, variable: str) -> Concept:
4242
def explainables(self) -> "ConceptMap.Explainables":
4343
pass
4444

45-
def json(self) -> Mapping[str, Mapping[str, Union[str, int, float, bool]]]:
45+
def to_json(self) -> Mapping[str, Mapping[str, Union[str, int, float, bool]]]:
4646
return {
47-
var: concept.json()
47+
var: concept.to_json()
4848
for var, concept in self._map.items()
4949
}
5050

typedb/api/concept/concept.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def is_remote(self) -> bool:
108108
pass
109109

110110
@abstractmethod
111-
def json(self) -> Mapping[str, Union[str, int, float, bool]]:
111+
def to_json(self) -> Mapping[str, Union[str, int, float, bool]]:
112112
pass
113113

114114

typedb/api/concept/thing/attribute.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def is_datetime(self):
6262
def as_remote(self, transaction: "TypeDBTransaction") -> "RemoteAttribute":
6363
pass
6464

65-
def json(self) -> Mapping[str, Union[str, int, float, bool]]:
65+
def to_json(self) -> Mapping[str, Union[str, int, float, bool]]:
6666
return {
6767
"type": self.get_type().get_label().name(),
6868
"value_type": str(self.get_type().get_value_type()),
@@ -182,7 +182,7 @@ def get_value(self) -> datetime:
182182
def as_remote(self, transaction: "TypeDBTransaction") -> "RemoteDateTimeAttribute":
183183
pass
184184

185-
def json(self) -> Mapping[str, Union[str, int, float, bool]]:
185+
def to_json(self) -> Mapping[str, Union[str, int, float, bool]]:
186186
return {
187187
"type": self.get_type().get_label().name(),
188188
"value_type": str(self.get_type().get_value_type()),

typedb/api/concept/thing/thing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def is_thing(self) -> bool:
5252
def as_remote(self, transaction: "TypeDBTransaction") -> "RemoteThing":
5353
pass
5454

55-
def json(self) -> Mapping[str, str]:
55+
def to_json(self) -> Mapping[str, str]:
5656
return {"type": self.get_type().get_label().name()}
5757

5858

typedb/api/concept/type/type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def is_type(self) -> bool:
4949
def as_remote(self, transaction: "TypeDBTransaction") -> "RemoteType":
5050
pass
5151

52-
def json(self) -> Mapping[str, str]:
52+
def to_json(self) -> Mapping[str, str]:
5353
return {"label": self.get_label().scoped_name()}
5454

5555

0 commit comments

Comments
 (0)