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

Concept map JSON serialization #285

Merged
merged 15 commits into from
Mar 24, 2023

Conversation

dmitrii-ubskii
Copy link
Member

@dmitrii-ubskii dmitrii-ubskii commented Mar 21, 2023

What is the goal of this PR?

We implement the JSON serialization of concept maps according to typedb/typedb-behaviour#238.

@typedb-bot
Copy link
Member

typedb-bot commented Mar 21, 2023

PR Review Checklist

Do 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

  • This change is trivial and does not require a code or architecture review.

Code

  • Packages, classes, and methods have a single domain of responsibility.
  • Packages, classes, and methods are grouped into cohesive and consistent domain model.
  • The code is canonical and the minimum required to achieve the goal.
  • Modules, libraries, and APIs are easy to use, robust (foolproof and not errorprone), and tested.
  • Logic and naming has clear narrative that communicates the accurate intent and responsibility of each module (e.g. method, class, etc.).
  • The code is algorithmically efficient and scalable for the whole application.

Architecture

  • Any required refactoring is completed, and the architecture does not introduce technical debt incidentally.
  • Any required build and release automations are updated and/or implemented.
  • Any new components follows a consistent style with respect to the pre-existing codebase.
  • The architecture intuitively reflects the application domain, and is easy to understand.
  • The architecture has a well-defined hierarchy of encapsulated components.
  • The architecture is extensible and scalable.

@dmitrii-ubskii dmitrii-ubskii changed the title json serialization + BDD Concept map JSON serialization Mar 23, 2023
@dmitrii-ubskii dmitrii-ubskii marked this pull request as ready for review March 23, 2023 16:26
@typedb-bot typedb-bot removed the request for review from benjaminasmall March 23, 2023 16:28
@typedb-bot typedb-bot removed the request for review from benjaminasmall March 23, 2023 16:28
@typedb-bot typedb-bot requested review from benjaminasmall and removed request for benjaminasmall March 23, 2023 16:28
@typedb-bot typedb-bot requested review from benjaminasmall and removed request for benjaminasmall March 23, 2023 16:28
Comment on lines +35 to +44
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))
Copy link
Member Author

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 dicts aren't hashable, we serialize each one in a well-defined way and compare the strings.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable hack.

Comment on lines +35 to +44
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))

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
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@alexjpwalker alexjpwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@dmitrii-ubskii dmitrii-ubskii merged commit e65a06b into typedb:master Mar 24, 2023
@dmitrii-ubskii dmitrii-ubskii deleted the concept-map-json branch March 27, 2023 10:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants