Updated types
This commit is contained in:
parent
24119609b3
commit
93b602a0eb
3 changed files with 18 additions and 71 deletions
|
|
@ -3,13 +3,13 @@ from typing import Any, List, Tuple, Optional, Union
|
|||
import uuid
|
||||
|
||||
primitive_types = (int, float, str, bool)
|
||||
INTEGER = {"type": "Integer"}
|
||||
FLOAT = {"type": "Float"}
|
||||
STRING = {"type": "String"}
|
||||
BOOLEAN = {"type": "Boolean"}
|
||||
TYPE = {"type": "Type"}
|
||||
NODE = {"type": "Node"}
|
||||
EDGE = {"type": "Edge"}
|
||||
INTEGER = ("Integer",)
|
||||
FLOAT = ("Float",)
|
||||
STRING = ("String",)
|
||||
BOOLEAN = ("Boolean",)
|
||||
TYPE = ("Type",)
|
||||
NODE = ("Node",)
|
||||
EDGE = ("Edge",)
|
||||
type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE)
|
||||
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ class State(ABC):
|
|||
Returns:
|
||||
True if value type is supported, False otherwise.
|
||||
"""
|
||||
if isinstance(value, dict) and value in type_values:
|
||||
if isinstance(value, tuple) and value in type_values:
|
||||
return True
|
||||
if not isinstance(value, primitive_types):
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ class DevState(PyState):
|
|||
for n in sorted(self.nodes):
|
||||
if n in self.values:
|
||||
x = self.values[n]
|
||||
if isinstance(x, dict):
|
||||
x = f"{x.get('type')}"
|
||||
if isinstance(x, tuple):
|
||||
x = f"{x[0]}"
|
||||
else:
|
||||
x = repr(x)
|
||||
f.write("\"a_%s\" [label=\"%s\"];\n" % (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
from state.base import INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
|
|
@ -123,69 +124,15 @@ def test_create_nodevalue_junk(state):
|
|||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_type_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Type"})
|
||||
def test_create_nodevalue_type(state):
|
||||
for t in {INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE}:
|
||||
id1 = state.create_nodevalue(t)
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Type"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_integer_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Integer"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Integer"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_float_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Float"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Float"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_boolean_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Boolean"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Boolean"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_string_type(state):
|
||||
id1 = state.create_nodevalue({"type": "String"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "String"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_node_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Node"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Node"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_edge_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Edge"})
|
||||
assert id1 is not None
|
||||
|
||||
v = state.read_value(id1)
|
||||
assert v == {"type": "Edge"}
|
||||
|
||||
assert v == t
|
||||
|
||||
@pytest.mark.usefixtures("state")
|
||||
def test_create_nodevalue_invalid_type(state):
|
||||
id1 = state.create_nodevalue({"type": "Class"})
|
||||
id1 = state.create_nodevalue(("Class",))
|
||||
assert id1 is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue