-
Notifications
You must be signed in to change notification settings - Fork 24
Concept map JSON serialization #285
Concept map JSON serialization #285
Conversation
PR Review ChecklistDo not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed. Trivial Change
Code
Architecture
|
d0dfb6e
to
2cc6161
Compare
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A hamcrest matcher that essentially performs multiset comparisons. Since dict
s aren't hashable, we serialize each one in a well-defined way and compare the strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable hack.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable hack.
@@ -19,7 +19,7 @@ | |||
# under the License. | |||
# | |||
from abc import ABC, abstractmethod | |||
from typing import Mapping, Iterable, Tuple | |||
from typing import Iterable, Mapping, Tuple, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iterable
is unused I think, double-check the rest of the PR for dangling unused imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used on L34.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
2cc6161
to
59eae5d
Compare
What is the goal of this PR?
We implement the JSON serialization of concept maps according to typedb/typedb-behaviour#238.