Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_inflate():
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
def test_inflate():
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
"""
Tests that the marshalling from neo4j to neomodel data types works as expected.
:return:
"""
# Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
# The test is repeatable enough to try and standardise it. The same test is repeated with the assertions in
# `basic_type_assertions` and different messages to be able to localise the exception.
#
# Array of points to inflate and messages when things go wrong
values_from_db = [(neo4j.v1.spatial.CartesianPoint((0.0, 0.0)),
'Expected Neomodel 2d cartesian point when inflating 2d cartesian neo4j point'),
(neo4j.v1.spatial.CartesianPoint((0.0, 0.0, 0.0)),
'Expected Neomodel 3d cartesian point when inflating 3d cartesian neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0)),
'Expected Neomodel 2d geographical point when inflating 2d geographical neo4j point'),
(neo4j.v1.spatial.WGS84Point((0.0, 0.0, 0.0)),
'Expected Neomodel 3d geographical point inflating 3d geographical neo4j point')]
# Run the above tests
for a_value in values_from_db:
expected_point = neomodel.contrib.spatial_properties.NeomodelPoint(tuple(a_value[0]),
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid])
inflated_point = neomodel.contrib.spatial_properties.PointProperty(
crs=neomodel.contrib.spatial_properties.SRID_TO_CRS[a_value[0].srid]).inflate(a_value[0])
basic_type_assertions(expected_point, inflated_point, '{}, received {}'.format(a_value[1], inflated_point))
:param value: The point that was assigned as value to a property in the model
:type value: NeomodelPoint
:return: Neo4J POINT
"""
if not isinstance(value, NeomodelPoint):
raise TypeError('Invalid datatype to deflate. Expected NeomodelPoint, received {}'.format(type(value)))
if not value.crs == self._crs:
raise ValueError('Invalid CRS. '
'Expected NeomodelPoint defined over {}, '
'received NeomodelPoint defined over {}'.format(self._crs, value.crs))
if value.crs == 'cartesian-3d':
return neo4j.v1.spatial.CartesianPoint((value.x, value.y, value.z))
elif value.crs == 'cartesian':
return neo4j.v1.spatial.CartesianPoint((value.x,value.y))
elif value.crs == 'wgs-84':
return neo4j.v1.spatial.WGS84Point((value.longitude, value.latitude))
elif value.crs == 'wgs-84-3d':
return neo4j.v1.spatial.WGS84Point((value.longitude, value.latitude, value.height))