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
|
import uuid
|
||||||
|
|
||||||
primitive_types = (int, float, str, bool)
|
primitive_types = (int, float, str, bool)
|
||||||
INTEGER = {"type": "Integer"}
|
INTEGER = ("Integer",)
|
||||||
FLOAT = {"type": "Float"}
|
FLOAT = ("Float",)
|
||||||
STRING = {"type": "String"}
|
STRING = ("String",)
|
||||||
BOOLEAN = {"type": "Boolean"}
|
BOOLEAN = ("Boolean",)
|
||||||
TYPE = {"type": "Type"}
|
TYPE = ("Type",)
|
||||||
NODE = {"type": "Node"}
|
NODE = ("Node",)
|
||||||
EDGE = {"type": "Edge"}
|
EDGE = ("Edge",)
|
||||||
type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE)
|
type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ class State(ABC):
|
||||||
Returns:
|
Returns:
|
||||||
True if value type is supported, False otherwise.
|
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
|
return True
|
||||||
if not isinstance(value, primitive_types):
|
if not isinstance(value, primitive_types):
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ class DevState(PyState):
|
||||||
for n in sorted(self.nodes):
|
for n in sorted(self.nodes):
|
||||||
if n in self.values:
|
if n in self.values:
|
||||||
x = self.values[n]
|
x = self.values[n]
|
||||||
if isinstance(x, dict):
|
if isinstance(x, tuple):
|
||||||
x = f"{x.get('type')}"
|
x = f"{x[0]}"
|
||||||
else:
|
else:
|
||||||
x = repr(x)
|
x = repr(x)
|
||||||
f.write("\"a_%s\" [label=\"%s\"];\n" % (
|
f.write("\"a_%s\" [label=\"%s\"];\n" % (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from state.base import INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("state")
|
@pytest.mark.usefixtures("state")
|
||||||
|
|
@ -123,69 +124,15 @@ def test_create_nodevalue_junk(state):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("state")
|
@pytest.mark.usefixtures("state")
|
||||||
def test_create_nodevalue_type_type(state):
|
def test_create_nodevalue_type(state):
|
||||||
id1 = state.create_nodevalue({"type": "Type"})
|
for t in {INTEGER, FLOAT, STRING, BOOLEAN, TYPE, NODE, EDGE}:
|
||||||
assert id1 is not None
|
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"}
|
|
||||||
|
|
||||||
|
v = state.read_value(id1)
|
||||||
|
assert v == t
|
||||||
|
|
||||||
@pytest.mark.usefixtures("state")
|
@pytest.mark.usefixtures("state")
|
||||||
def test_create_nodevalue_invalid_type(state):
|
def test_create_nodevalue_invalid_type(state):
|
||||||
id1 = state.create_nodevalue({"type": "Class"})
|
id1 = state.create_nodevalue(("Class",))
|
||||||
assert id1 is None
|
assert id1 is None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue