-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
gremlin-python/src/main/python/tests/structure/io/model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import datetime | ||
import uuid | ||
from gremlin_python.statics import timestamp, short, long, bigint, BigDecimal, SingleByte, SingleChar, ByteBufferType | ||
from gremlin_python.structure.graph import Vertex, Edge, Property, VertexProperty, Path | ||
from gremlin_python.structure.io.graphbinaryV4 import GraphBinaryWriter, GraphBinaryReader | ||
from gremlin_python.process.traversal import Barrier, Binding, Bytecode, Merge, Direction, Traverser, T | ||
from gremlin_python.structure.io.util import HashableDict, Marker | ||
|
||
unsupported = {"tinker-graph", "max-offsetdatetime", "min-offsetdatetime"} | ||
model = {} | ||
|
||
model["pos-bigdecimal"] = BigDecimal(33, 123456789987654321123456789987654321) | ||
model["neg-bigdecimal"] = BigDecimal(33, -123456789987654321123456789987654321) | ||
model["pos-biginteger"] = bigint(123456789987654321123456789987654321) | ||
model["neg-biginteger"] = bigint(-123456789987654321123456789987654321) | ||
model["min-byte"] = SingleByte(-128) | ||
model["max-byte"] = SingleByte(127) | ||
model["empty-binary"] = ByteBufferType("", "utf8") | ||
model["str-binary"] = ByteBufferType("some bytes for you", "utf8") | ||
model["max-double"] = 1.7976931348623157E308 | ||
model["min-double"] = 4.9E-324 | ||
model["neg-max-double"] = -1.7976931348623157E308 | ||
model["neg-min-double"] = -4.9E-324 | ||
model["nan-double"] = float('nan') | ||
model["pos-inf-double"] = float('inf') | ||
model["neg-inf-double"] = float('-inf') | ||
model["neg-zero-double"] = -0.0 | ||
model["zero-duration"] = datetime.timedelta() | ||
#model["forever-duration"] = datetime.timedelta(seconds=2**63-1, microseconds=999999999) | ||
model["traversal-edge"] = Edge( | ||
13, | ||
Vertex(1, 'person'), | ||
"develops", | ||
Vertex(10, "software"), | ||
[Property("since", 2009, None)] | ||
) | ||
model["no-prop-edge"] = Edge( | ||
13, | ||
Vertex(1, 'person'), | ||
"develops", | ||
Vertex(10, "software") | ||
) | ||
model["max-float"] = float(3.4028235E38) | ||
model["min-float"] = float(1.4E-45) | ||
model["neg-max-float"] = float(-3.4028235E38) | ||
model["neg-min-float"] = float(-1.4E-45) | ||
model["nan-float"] = float('nan') | ||
model["pos-inf-float"] = float('inf') | ||
model["neg-inf-float"] = float('-inf') | ||
model["neg-zero-float"] = float(-0.0) | ||
model["max-int"] = 2147483647 | ||
model["min-int"] = -2**31 | ||
model["max-long"] = long(2**63-1) | ||
model["min-long"] = long(-2**63) | ||
model["var-type-list"] = [1, "person", True, None] | ||
model["empty-list"] = [] | ||
model["var-type-map"] = { | ||
"test": 123, | ||
datetime.datetime.fromtimestamp(1481295): "red", | ||
(1,2,3): datetime.datetime.fromtimestamp(1481295), | ||
None: None | ||
} | ||
model["empty-map"] = {} | ||
model["traversal-path"] = Path( | ||
[{}, {}, {}], | ||
[Vertex(1, "person"), Vertex(10, "software"), Vertex(11, "software")] | ||
) | ||
model["empty-path"] = Path([], []) | ||
model["prop-path"] = Path( | ||
[{}, {}, {}], | ||
[ | ||
Vertex(1, "person", VertexProperty( | ||
123, | ||
"name", | ||
"stephen", | ||
[ | ||
VertexProperty(0, "name", "marko", None), | ||
VertexProperty(6, "location", [], None) | ||
] | ||
)), | ||
Vertex(10, "software"), | ||
Vertex(11, "software") | ||
] | ||
) | ||
model["edge-property"] = Property("since", 2009, None) | ||
model["null-property"] = Property("", None, None) | ||
model["var-type-set"] = {1, "person", True, None} | ||
model["empty-set"] = set() | ||
model["max-short"] = short(32767) | ||
model["min-short"] = short(-32768) | ||
# model["vertex-traverser"] | ||
model["bulked-traverser"] = Traverser(Vertex(11, "software", [VertexProperty(5, "name", "tinkergraph", None)]), 7) | ||
model["empty-traverser"] = Traverser(None, 0) | ||
model["specified-uuid"] = uuid.UUID("41d2e28a-20a4-4ab0-b379-d810dede3786") | ||
model["nil-uuid"] = uuid.UUID(int = 0) | ||
#model["traversal-vertex"] | ||
model["no-prop-vertex"] = Vertex(1, "person") | ||
model["id-t"] = T.id | ||
model["out-direction"] = Direction.OUT | ||
#model["zero-date"] = datetime.datetime(1970, 1, 1) |
224 changes: 224 additions & 0 deletions
224
gremlin-python/src/main/python/tests/structure/io/test_graphbinaryv4model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
from gremlin_python.structure.io.graphbinaryV4 import GraphBinaryWriter, GraphBinaryReader | ||
from os import environ | ||
|
||
from .model import model, unsupported | ||
|
||
gremlin_test_dir = "gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/graphbinary/" | ||
test_resource_directory = environ.get('IO_TEST_DIRECTORY', '../' + gremlin_test_dir) | ||
writer = GraphBinaryWriter() | ||
reader = GraphBinaryReader() | ||
|
||
def get_entry(title): | ||
return model[title] | ||
|
||
def read_file_by_name(resource_name): | ||
full_name = test_resource_directory + resource_name + "-" + "v4" + ".gbin" | ||
with open(full_name, 'rb') as resource_file: | ||
return bytearray(resource_file.read()) | ||
|
||
|
||
def test_pos_bigdecimal(): | ||
resource_name = "pos-bigdecimal" | ||
resource_bytes = read_file_by_name(resource_name) | ||
|
||
model = get_entry(resource_name) | ||
read = reader.read_object(resource_bytes) | ||
assert model.scale == read.scale | ||
assert model.unscaled_value == read.unscaled_value | ||
|
||
written = writer.write_object(model) | ||
assert resource_bytes == written | ||
|
||
def test_neg_bigdecimal(): | ||
resource_name = "pos-bigdecimal" | ||
resource_bytes = read_file_by_name(resource_name) | ||
|
||
model = get_entry(resource_name) | ||
read = reader.read_object(resource_bytes) | ||
assert model.scale == read.scale | ||
assert model.unscaled_value == read.unscaled_value | ||
|
||
written = writer.write_object(model) | ||
assert resource_bytes == written | ||
|
||
def test_pos_biginteger(): | ||
run("pos-biginteger") | ||
|
||
def test_neg_biginteger(): | ||
run("neg-biginteger") | ||
|
||
def test_min_byte(): | ||
run("min-byte") | ||
|
||
def test_max_byte(): | ||
run("max-byte") | ||
|
||
def test_empty_binary(): | ||
run("empty-binary") | ||
|
||
def test_str_binary(): | ||
run("str-binary") | ||
|
||
def test_max_double(): | ||
run("max-double") | ||
|
||
def test_min_double(): | ||
run("min-double") | ||
|
||
def test_neg_max_double(): | ||
run("neg-max-double") | ||
|
||
def test_neg_min_double(): | ||
run("neg-min-double") | ||
|
||
def test_nan_double(): | ||
run("nan-double") | ||
|
||
def test_pos_inf_double(): | ||
run("pos-inf-double") | ||
|
||
def test_neg_inf_double(): | ||
run("neg-inf-double") | ||
|
||
def test_neg_zero_double(): | ||
run("neg-zero-double") | ||
|
||
def test_zero_duration(): | ||
run("zero-duration") | ||
|
||
#def test_forever_duration(): | ||
# run("forever-duration") | ||
|
||
def test_traversal_edge(): | ||
run("traversal-edge") | ||
|
||
def test_no_prop_edge(): | ||
run("no-prop-edge") | ||
|
||
def test_max_float(): | ||
run("max-float") | ||
|
||
def test_min_float(): | ||
run("min-float") | ||
|
||
def test_neg_max_float(): | ||
run("neg-max-float") | ||
|
||
def test_neg_min_float(): | ||
run("neg-min-float") | ||
|
||
def test_nan_float(): | ||
run("nan-float") | ||
|
||
def test_pos_inf_float(): | ||
run("pos-inf-float") | ||
|
||
def test_neg_inf_float(): | ||
run("neg-inf-float") | ||
|
||
def test_neg_zero_float(): | ||
run("neg-zero-float") | ||
|
||
def test_max_int(): | ||
run("max-int") | ||
|
||
def test_min_int(): | ||
run("min-int") | ||
|
||
def test_max_long(): | ||
run("max-long") | ||
|
||
def test_min_long(): | ||
run("min-long") | ||
|
||
def test_var_type_list(): | ||
run("var-type-list") | ||
|
||
def test_empty_list(): | ||
run("empty-list") | ||
|
||
def test_var_type_map(): | ||
run("var-type-map") | ||
|
||
def test_empty_map(): | ||
run("empty-map") | ||
|
||
def test_max_offsetdatetime(): | ||
run("max-offsetdatetime") | ||
|
||
def test_min_offsetdatetime(): | ||
run("min-offsetdatetime") | ||
|
||
def test_traversal_path(): | ||
run("traversal-path") | ||
|
||
#TODO: come back | ||
def test_empty_path(): | ||
run("empty-path") | ||
|
||
def test_prop_path(): | ||
run("prop-path") | ||
|
||
def test_zero_date(): | ||
run("zero-date") | ||
|
||
def test_edge_property(): | ||
run("edge-property") | ||
|
||
def test_null_property(): | ||
run("null-property") | ||
|
||
def test_var_type_set(): | ||
run("var-type-set") | ||
|
||
def test_empty_set(): | ||
run("empty-set") | ||
|
||
def test_max_short(): | ||
run("max-short") | ||
|
||
def test_min_short(): | ||
run("min-short") | ||
|
||
def test_tinker_graph(): | ||
run("tinker-graph") | ||
|
||
def test_vertex_traverser(): | ||
run("vertex-traverser") | ||
|
||
def test_bulked_traverser(): | ||
run("bulked-traverser") | ||
|
||
def test_empty_traverser(): | ||
run("empty-traverser") | ||
|
||
def test_specified_uuid(): | ||
run("specified-uuid") | ||
|
||
def test_nil_uuid(): | ||
run("nil-uuid") | ||
|
||
def test_no_prop_vertex(): | ||
run("no-prop-vertex") | ||
|
||
def test_id_t(): | ||
run("id-t") | ||
|
||
def test_out_direction(): | ||
run("out-direction") | ||
|
||
def run(resource_name): | ||
if resource_name in unsupported: | ||
return | ||
|
||
resource_bytes = read_file_by_name(resource_name) | ||
|
||
model = get_entry(resource_name) | ||
read = reader.read_object(resource_bytes) | ||
assert model == read | ||
|
||
written = writer.write_object(model) | ||
assert resource_bytes == written | ||
|
||
round_tripped = writer.write_object(reader.read_object(resource_bytes)) | ||
assert resource_bytes == round_tripped |