Module pygw.test.conftest
Source code
#
# Copyright (c) 2013-2022 Contributors to the Eclipse Foundation
#
# See the NOTICE file distributed with this work for additional information regarding copyright
# ownership. All rights reserved. This program and the accompanying materials are made available
# under the terms of the Apache License, Version 2.0 which accompanies this distribution and is
# available at http://www.apache.org/licenses/LICENSE-2.0.txt
# ===============================================================================================
import pytest
import os
import shutil
import time
from datetime import datetime
from shapely.geometry import Point
from pygw.base import CloseableIterator
from pygw.store import DataStoreFactory
from pygw.store.rocksdb import RocksDBOptions
from pygw.geotools import SimpleFeatureTypeBuilder
from pygw.geotools import AttributeDescriptor
from pygw.geotools import FeatureDataAdapter
from pygw.geotools import SimpleFeatureBuilder
# "Point" Type
POINT_TYPE_NAME = "TestPointType"
POINT_GEOMETRY_FIELD = "the_geom"
POINT_TIME_FIELD = "date"
POINT_NUMBER_FIELD = "flt"
POINT_COLOR_FIELD = "color"
POINT_SHAPE_FIELD = "shape"
_point_type_builder = SimpleFeatureTypeBuilder()
_point_type_builder.set_name(POINT_TYPE_NAME)
_point_type_builder.add(AttributeDescriptor.point(POINT_GEOMETRY_FIELD))
_point_type_builder.add(AttributeDescriptor.date(POINT_TIME_FIELD))
_point_type_builder.add(AttributeDescriptor.float(POINT_NUMBER_FIELD))
_point_type_builder.add(AttributeDescriptor.string(POINT_COLOR_FIELD))
_point_type_builder.add(AttributeDescriptor.string(POINT_SHAPE_FIELD))
POINT_TYPE = _point_type_builder.build_feature_type()
# "Point" Type Adapter
POINT_TYPE_ADAPTER = FeatureDataAdapter(POINT_TYPE)
# "Point" Feature builder
POINT_FEATURE_BUILDER = SimpleFeatureBuilder(POINT_TYPE)
COLORS = ['RED', 'GREEN', 'BLUE']
SHAPES = ['SQUARE', 'CIRCLE', 'TRIANGLE', 'RECTANGLE']
def _create_feature(fid, geometry, timestamp):
POINT_FEATURE_BUILDER.set_attr(POINT_GEOMETRY_FIELD, geometry)
POINT_FEATURE_BUILDER.set_attr(POINT_TIME_FIELD, datetime.utcfromtimestamp(timestamp))
POINT_FEATURE_BUILDER.set_attr(POINT_NUMBER_FIELD, timestamp)
POINT_FEATURE_BUILDER.set_attr(POINT_COLOR_FIELD, COLORS[timestamp % 3])
POINT_FEATURE_BUILDER.set_attr(POINT_SHAPE_FIELD, SHAPES[timestamp % 4])
return POINT_FEATURE_BUILDER.build(fid)
def latitude(lon_value):
if lon_value < 0:
return lon_value % -90
return lon_value % 90
TEST_DATA = [
_create_feature(id_, Point(i, latitude(i)), i) for
id_, i in enumerate(range(-180, 180))]
TEST_DATA_OFFSET = [
_create_feature(id_, Point(i+0.5, latitude(i+0.5)), i) for
id_, i in enumerate(range(-180, 180))]
# Test Directory
TEST_DIR = os.path.join(os.getcwd(), "test")
@pytest.fixture
def test_ds():
os.makedirs(TEST_DIR, exist_ok=True)
options = RocksDBOptions()
options.set_geowave_namespace("geowave.tests")
options.set_directory(os.path.join(TEST_DIR, "datastore"))
ds = DataStoreFactory.create_data_store(options)
yield ds
# teardown here
ds.delete_all()
shutil.rmtree(TEST_DIR)
while os.path.isdir(TEST_DIR):
time.sleep(0.01)
def write_test_data_offset(ds, *expected_indices):
write_test_data(ds, *expected_indices, data=TEST_DATA_OFFSET)
def write_test_data(ds, *expected_indices, data=TEST_DATA):
writer = ds.create_writer(POINT_TYPE_ADAPTER.get_type_name())
for pt in data:
results = writer.write(pt)
assert not results.is_empty()
written_indices = results.get_written_index_names()
assert len(written_indices) == len(expected_indices)
assert all([idx.get_name() in written_indices for idx in expected_indices])
writer.close()
def results_as_list(results):
assert isinstance(results, CloseableIterator)
res = [d for d in results]
results.close()
return res
Functions
def latitude(lon_value)
-
Source code
def latitude(lon_value): if lon_value < 0: return lon_value % -90 return lon_value % 90
def results_as_list(results)
-
Source code
def results_as_list(results): assert isinstance(results, CloseableIterator) res = [d for d in results] results.close() return res
def test_ds()
-
Source code
@pytest.fixture def test_ds(): os.makedirs(TEST_DIR, exist_ok=True) options = RocksDBOptions() options.set_geowave_namespace("geowave.tests") options.set_directory(os.path.join(TEST_DIR, "datastore")) ds = DataStoreFactory.create_data_store(options) yield ds # teardown here ds.delete_all() shutil.rmtree(TEST_DIR) while os.path.isdir(TEST_DIR): time.sleep(0.01)
def write_test_data(ds, *expected_indices, data=[pygw
=> SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-180 0), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:00 UTC 1969, SimpleFeatureImpl.Attribute: flt =-180.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-179 -89), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:01 UTC 1969, SimpleFeatureImpl.Attribute: flt =-179.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-178 -88), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:02 UTC 1969, SimpleFeatureImpl.Attribute: flt =-178.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-177 -87), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:03 UTC 1969, SimpleFeatureImpl.Attribute: flt =-177.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-176 -86), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:04 UTC 1969, SimpleFeatureImpl.Attribute: flt =-176.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-175 -85), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:05 UTC 1969, SimpleFeatureImpl.Attribute: flt =-175.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-174 -84), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:06 UTC 1969, SimpleFeatureImpl.Attribute: flt =-174.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-173 -83), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:07 UTC 1969, SimpleFeatureImpl.Attribute: flt =-173.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-172 -82), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:08 UTC 1969, SimpleFeatureImpl.Attribute: flt =-172.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-171 -81), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:09 UTC 1969, SimpleFeatureImpl.Attribute: flt =-171.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-170 -80), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:10 UTC 1969, SimpleFeatureImpl.Attribute: flt =-170.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-169 -79), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:11 UTC 1969, SimpleFeatureImpl.Attribute: flt =-169.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-168 -78), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:12 UTC 1969, SimpleFeatureImpl.Attribute: flt =-168.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-167 -77), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:13 UTC 1969, SimpleFeatureImpl.Attribute: flt =-167.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-166 -76), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:14 UTC 1969, SimpleFeatureImpl.Attribute: flt =-166.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-165 -75), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:15 UTC 1969, SimpleFeatureImpl.Attribute: flt =-165.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-164 -74), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:16 UTC 1969, SimpleFeatureImpl.Attribute: flt =-164.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-163 -73), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:17 UTC 1969, SimpleFeatureImpl.Attribute: flt =-163.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-162 -72), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:18 UTC 1969, SimpleFeatureImpl.Attribute: flt =-162.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-161 -71), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:19 UTC 1969, SimpleFeatureImpl.Attribute: flt =-161.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-160 -70), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:20 UTC 1969, SimpleFeatureImpl.Attribute: flt =-160.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-159 -69), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:21 UTC 1969, SimpleFeatureImpl.Attribute: flt =-159.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-158 -68), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:22 UTC 1969, SimpleFeatureImpl.Attribute: flt =-158.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-157 -67), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:23 UTC 1969, SimpleFeatureImpl.Attribute: flt =-157.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-156 -66), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:24 UTC 1969, SimpleFeatureImpl.Attribute: flt =-156.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-155 -65), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:25 UTC 1969, SimpleFeatureImpl.Attribute: flt =-155.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-154 -64), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:26 UTC 1969, SimpleFeatureImpl.Attribute: flt =-154.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-153 -63), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:27 UTC 1969, SimpleFeatureImpl.Attribute: flt =-153.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-152 -62), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:28 UTC 1969, SimpleFeatureImpl.Attribute: flt =-152.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-151 -61), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:29 UTC 1969, SimpleFeatureImpl.Attribute: flt =-151.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-150 -60), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:30 UTC 1969, SimpleFeatureImpl.Attribute: flt =-150.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-149 -59), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:31 UTC 1969, SimpleFeatureImpl.Attribute: flt =-149.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-148 -58), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:32 UTC 1969, SimpleFeatureImpl.Attribute: flt =-148.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-147 -57), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:33 UTC 1969, SimpleFeatureImpl.Attribute: flt =-147.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-146 -56), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:34 UTC 1969, SimpleFeatureImpl.Attribute: flt =-146.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-145 -55), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:35 UTC 1969, SimpleFeatureImpl.Attribute: flt =-145.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-144 -54), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:36 UTC 1969, SimpleFeatureImpl.Attribute: flt =-144.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-143 -53), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:37 UTC 1969, SimpleFeatureImpl.Attribute: flt =-143.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =CIRCLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-142 -52), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:38 UTC 1969, SimpleFeatureImpl.Attribute: flt =-142.0, SimpleFeatureImpl.Attribute: color =BLUE, SimpleFeatureImpl.Attribute: shape =TRIANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-141 -51), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:39 UTC 1969, SimpleFeatureImpl.Attribute: flt =-141.0, SimpleFeatureImpl.Attribute: color =RED, SimpleFeatureImpl.Attribute: shape =RECTANGLE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-140 -50), SimpleFeatureImpl.Attribute: date =Wed Dec 31 23:57:40 UTC 1969, SimpleFeatureImpl.Attribute: flt =-140.0, SimpleFeatureImpl.Attribute: color =GREEN, SimpleFeatureImpl.Attribute: shape =SQUARE], pygw => SimpleFeatureImpl:TestPointType=[SimpleFeatureImpl.Attribute: the_geom =POINT (-139 -49), SimpleFeatureImpl.Attribute: date