Skip to content

Commit

Permalink
Merge pull request #161 from singnet/angelo/#160/syncing-tests-with-n…
Browse files Browse the repository at this point in the history
…ew-atomdb

[#160] syncing tests with the new Atom DB
  • Loading branch information
levisingularity authored Oct 31, 2024
2 parents be5c477 + d7caf63 commit 2851cc2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 85 deletions.
19 changes: 12 additions & 7 deletions das-query-engine/tests/integration/handle/test_get_atom_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from actions import ActionType
from hyperon_das_atomdb.database import Link, Node
from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher
from tests.integration.handle.base_test_action import BaseTestHandlerAction, human, symbol

Expand Down Expand Up @@ -32,15 +33,19 @@ def test_get_atom_action(
assert (
status_code == expected_status_code
), f"Unexpected status code: {status_code}. Expected: {expected_status_code}"
assert isinstance(body, dict), "body must be a dictionary"
assert isinstance(body.get("handle"), str), "'handle' in body must be a string."
assert isinstance(body, (Node, Link)), "body must be an Atom instance (Node or Link)."
assert isinstance(body.handle, str), "'handle' in body must be a string."
assert isinstance(
body.get("composite_type_hash"), str
body.composite_type_hash, str
), "'composite_type_hash' in body must be a string."
assert isinstance(body.get("name"), str), "'name' in body must be a string."
assert isinstance(body.get("named_type"), str), "'named_type' in body must be a string."
assert isinstance(body.get("type"), str), "'type' in body must be a string."
assert isinstance(body.get("is_literal"), bool), "'is_literal' in body must be a boolean."
assert isinstance(body.name, str), "'name' in body must be a string."
assert isinstance(body.named_type, str), "'named_type' in body must be a string."

# TODO: Uncomment when 'is_literal' is added as a custom attribute to Atom
# See: https://github.com/singnet/das-query-engine/issues/358
# assert isinstance(
# body.custom_attributes.get("is_literal"), bool
# ), "'is_literal' in custom attributes must be a boolean."

def test_malformed_payload(self, malformed_event):
self.assert_payload_malformed(malformed_event)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from actions import ActionType
from hyperon_das_atomdb.database import Link, Node
from hyperon_das_atomdb.utils.expression_hasher import ExpressionHasher
from tests.integration.handle.base_test_action import BaseTestHandlerAction, human, symbol

Expand Down Expand Up @@ -38,55 +39,45 @@ def test_incoming_links_action(
assert len(items) == 8, "body must contain eight elements."

for item in items:
assert isinstance(item, dict), "Each item in body must be a dict."
# assert len(item) == x, "List in body must contain x elements."
assert isinstance(item, Link), "Each item in body must be a Link instance."

assert isinstance(item.handle, str), "'handle' in item must be a string."
assert isinstance(
item.get("handle"), str
), "'handle' in item must be a string."
assert isinstance(item.get("type"), str), "'type' in item must be a string."
assert isinstance(
item.get("composite_type_hash"), str
item.composite_type_hash, str
), "'composite_type_hash' in item must be a string."
assert isinstance(item.is_toplevel, bool), "'is_toplevel' in item must be a boolean."
assert isinstance(
item.get("is_toplevel"), bool
), "'is_toplevel' in item must be a boolean."
assert isinstance(
item.get("composite_type"), list
item.composite_type, list
), "'composite_type' in item must be a list of strings."
assert all(
isinstance(item, str) for item in item.get("composite_type")
isinstance(item, str) for item in item.composite_type
), "'composite_type' elements in item must be strings."
assert isinstance(item.named_type, str), "'named_type' in item must be a string."
assert isinstance(
item.get("named_type"), str
), "'named_type' in item must be a string."
assert isinstance(
item.get("named_type_hash"), str
item.named_type_hash, str
), "'named_type_hash' in item must be a string."
assert isinstance(
item.get("targets"), list
), "'targets' in item must be a list of strings."
assert isinstance(item.targets, list), "'targets' in item must be a list of strings."
assert all(
isinstance(item, str) for item in item.get("targets")
isinstance(item, str) for item in item.targets
), "'targets' elements in item must be strings."
assert isinstance(
item.get("targets_document"), list
), "'targets_document' in item must be a list of dictionaries."
item.targets_documents, list
), "'targets_documents' in item must be a list of Atoms instances (Nodes or Links)."

for atom in item.get("targets_document"):
assert isinstance(atom, dict), f"{type(atom)} is not a dictionary."
assert isinstance(atom.get("handle"), str), "'handle' in atom must be a string."
assert isinstance(atom.get("type"), str), "'type' in atom must be a string."
for atom in item.targets_documents:
assert isinstance(atom, (Node, Link)), f"{type(atom)} is not a Node or Link."
assert isinstance(atom.handle, str), "'handle' in atom must be a string."
assert isinstance(
atom.get("composite_type_hash"), str
atom.composite_type_hash, str
), "'composite_type_hash' in atom must be a string."
assert isinstance(atom.get("name"), str), "'name' in atom must be a string."
assert isinstance(
atom.get("named_type"), str
), "'named_type' in atom must be a string."
assert isinstance(
atom.get("is_literal"), bool
), "'is_literal' in atom must be a boolean."
assert isinstance(atom.name, str), "'name' in atom must be a string."
assert isinstance(atom.named_type, str), "'named_type' in atom must be a string."

# TODO: Uncomment when 'is_literal' is added as a custom attribute to Atom
# See: https://github.com/singnet/das-query-engine/issues/358
# assert isinstance(
# atom.custom_attributes.get("is_literal"), bool
# ), "'is_literal' in custom attributes must be a boolean."

def test_malformed_payload(self, malformed_event):
self.assert_payload_malformed(malformed_event)
Expand Down
27 changes: 11 additions & 16 deletions das-query-engine/tests/integration/handle/test_get_link_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from actions import ActionType
from hyperon_das_atomdb.database import Link
from tests.integration.handle.base_test_action import BaseTestHandlerAction, expression


Expand Down Expand Up @@ -34,31 +35,25 @@ def test_get_link_action(
assert (
status_code == expected_status_code
), f"Unexpected status code: {status_code}. Expected: {expected_status_code}"
assert isinstance(body, dict), "body must be a dictionary"
assert isinstance(body.get("handle"), str), "'handle' in body must be a string."
assert isinstance(body, Link), "body must be a Link instance"
assert isinstance(body.handle, str), "'handle' in body must be a string."
assert isinstance(
body.get("composite_type_hash"), str
body.composite_type_hash, str
), "'composite_type_hash' in body must be a string."
assert isinstance(body.get("is_toplevel"), bool), "'is_toplevel' in body must be a boolean."
assert isinstance(
body.get("composite_type"), list
), "'composite_type' in body must be a list."
assert isinstance(body.is_toplevel, bool), "'is_toplevel' in body must be a boolean."
assert isinstance(body.composite_type, list), "'composite_type' in body must be a list."
assert all(
isinstance(item, str) for item in body["composite_type"]
isinstance(item, str) for item in body.composite_type
), "'composite_type' elements in body must be strings."

assert isinstance(body.get("named_type"), str), "'named_type' in body must be a string."
assert isinstance(
body.get("named_type_hash"), str
), "'named_type_hash' in body must be a string."
assert isinstance(body.named_type, str), "'named_type' in body must be a string."
assert isinstance(body.named_type_hash, str), "'named_type_hash' in body must be a string."

assert isinstance(body.get("targets"), list), "'targets' in body must be a list."
assert isinstance(body.targets, list), "'targets' in body must be a list."
assert all(
isinstance(item, str) for item in body["targets"]
isinstance(item, str) for item in body.targets
), "'targets' elements in body must be strings."

assert isinstance(body.get("type"), str), "'type' in body must be a string."

def test_malformed_payload(self, malformed_event):
self.assert_payload_malformed(malformed_event)

Expand Down
32 changes: 15 additions & 17 deletions das-query-engine/tests/integration/handle/test_get_links_action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import hyperon_das.link_filters as link_filter
import pytest
from actions import ActionType
from hyperon_das_atomdb.database import Link
from tests.integration.handle.base_test_action import BaseTestHandlerAction, expression, symbol
import hyperon_das.link_filters as link_filter


class TestGetLinksAction(BaseTestHandlerAction):
Expand All @@ -24,7 +25,7 @@ def valid_event(self, action_type):
symbol,
symbol,
],
"targets": []
"targets": [],
}
},
}
Expand All @@ -43,29 +44,26 @@ def test_get_links_action(

assert isinstance(body, list)
assert len(body) > 0
assert all(isinstance(item, dict) for item in body), "elements in body must be dicts."
assert all(
isinstance(item, Link) for item in body
), "elements in body must be Link instances."

link = body[0]

assert isinstance(link.get("handle"), str), "'handle' in link must be a string."
assert isinstance(link.get("type"), str), "'type' in link must be a string."
assert isinstance(link.handle, str), "'handle' in link must be a string."
assert isinstance(
link.get("composite_type_hash"), str
link.composite_type_hash, str
), "'composite_type_hash' in link must be a string."
assert isinstance(link.get("is_toplevel"), bool), "'is_toplevel' in link must be a boolean."
assert isinstance(
link.get("composite_type"), list
), "'composite_type' in link must be a list."
assert isinstance(link.is_toplevel, bool), "'is_toplevel' in link must be a boolean."
assert isinstance(link.composite_type, list), "'composite_type' in link must be a list."
assert all(
isinstance(item, str) for item in link.get("composite_type")
isinstance(item, str) for item in link.composite_type
), "'composite_type' elements in link must be strings."
assert isinstance(link.get("named_type"), str), "'named_type' in link must be a string."
assert isinstance(
link.get("named_type_hash"), str
), "'named_type_hash' in link must be a string."
assert isinstance(link.get("targets"), list), "'targets' in link must be a list."
assert isinstance(link.named_type, str), "'named_type' in link must be a string."
assert isinstance(link.named_type_hash, str), "'named_type_hash' in link must be a string."
assert isinstance(link.targets, list), "'targets' in link must be a list."
assert all(
isinstance(item, str) for item in link.get("targets")
isinstance(item, str) for item in link.targets
), "'targets' elements in link must be strings."

def test_malformed_payload(self, malformed_event):
Expand Down
19 changes: 12 additions & 7 deletions das-query-engine/tests/integration/handle/test_get_node_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from actions import ActionType
from hyperon_das_atomdb.database import Node
from tests.integration.handle.base_test_action import BaseTestHandlerAction, human, symbol


Expand Down Expand Up @@ -27,15 +28,19 @@ def test_get_node_action(
assert (
status_code == expected_status_code
), f"Unexpected status code: {status_code}. Expected: {expected_status_code}"
assert isinstance(body, dict), "body must be a dictionary"
assert isinstance(body.get("handle"), str), "'handle' in body must be a string."
assert isinstance(body, Node), "body must be a Node instance"
assert isinstance(body.handle, str), "'handle' in body must be a string."
assert isinstance(
body.get("composite_type_hash"), str
body.composite_type_hash, str
), "'composite_type_hash' in body must be a string."
assert isinstance(body.get("name"), str), "'name' in body must be a string."
assert isinstance(body.get("named_type"), str), "'named_type' in body must be a string."
assert isinstance(body.get("type"), str), "'type' in body must be a string."
assert isinstance(body.get("is_literal"), bool), "'is_literal' in body must be a boolean."
assert isinstance(body.name, str), "'name' in body must be a string."
assert isinstance(body.named_type, str), "'named_type' in body must be a string."

# TODO: Uncomment when 'is_literal' is added as a custom attribute to Atom
# See: https://github.com/singnet/das-query-engine/issues/358
# assert isinstance(
# body.custom_attributes.get("is_literal"), bool
# ), "'is_literal' in custom_attributes must be a boolean."

def test_malformed_payload(self, malformed_event):
self.assert_payload_malformed(malformed_event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from tests.integration.handle.base_test_action import (
BaseTestHandlerAction,
expression,
inheritance,
similarity,
human,
inheritance,
mammal,
similarity,
symbol,
)

Expand Down Expand Up @@ -35,7 +35,7 @@ def valid_event(self, action_type):
},
}
}

@pytest.fixture
def query_list(self, action_type):
return {
Expand All @@ -60,7 +60,7 @@ def query_list(self, action_type):
{"atom_type": "variable", "name": "$v1"},
{"atom_type": "node", "type": symbol, "name": human},
],
}
},
]
},
}
Expand Down

0 comments on commit 2851cc2

Please sign in to comment.