this module has the mock object definitions used to hold reference geometry for the geos and gdal tests path where reference test data is located base testing object turns keyword args into attributes object for testing gdal data sources shapefile is default extension unless specified otherwise testing object used for wrapping reference geometry data in geosgdal tests converting lists to tuples of certain keyword args so coordinate test cases will match json has no concept of tuple each attribute of this object is a list of testgeom instances mixin used for geosgdal test cases that defines a geometries property which returns andor loads the reference geometry data load up the test geometry data from fixture into global path where reference test data is located base testing object turns keyword args into attributes object for testing gdal data sources shapefile is default extension unless specified otherwise testing object used for wrapping reference geometry data in geos gdal tests converting lists to tuples of certain keyword args so coordinate test cases will match json has no concept of tuple each attribute of this object is a list of testgeom instances mixin used for geos gdal test cases that defines a geometries property which returns and or loads the reference geometry data load up the test geometry data from fixture into global
import json
import os

from django.utils.functional import cached_property


TEST_DATA = os.path.join(os.path.dirname(__file__), "data")


def tuplize(seq):
    "Turn all nested sequences to tuples in given sequence."
    if isinstance(seq, (list, tuple)):
        return tuple(tuplize(i) for i in seq)
    return seq


def strconvert(d):
    "Converts all keys in dictionary to str type."
    return {str(k): v for k, v in d.items()}


def get_ds_file(name, ext):
    return os.path.join(TEST_DATA, name, name + ".%s" % ext)


class TestObj:
    

    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)


class TestDS(TestObj):
    

    def __init__(self, name, *, ext="shp", **kwargs):
        
        self.name = name
        self.ds = get_ds_file(name, ext)
        super().__init__(**kwargs)


class TestGeom(TestObj):
    

    def __init__(self, *, coords=None, centroid=None, ext_ring_cs=None, **kwargs):
        
        
        
        if coords:
            self.coords = tuplize(coords)
        if centroid:
            self.centroid = tuple(centroid)
        self.ext_ring_cs = ext_ring_cs and tuplize(ext_ring_cs)
        super().__init__(**kwargs)


class TestGeomSet:
    

    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, [TestGeom(**strconvert(kw)) for kw in value])


class TestDataMixin:
    

    @cached_property
    def geometries(self):
        
        with open(os.path.join(TEST_DATA, "geometries.json")) as f:
            geometries = json.load(f)
        return TestGeomSet(**strconvert(geometries))