예제 #1
0
    def test_from_json_object_additional_properties_is_schema(self):
        Person = namedtuple('Person', ['name', 'age', 'deleted'])

        person_schema = JsonObjectSchema(
            properties=dict(name=JsonStringSchema(),
                            age=JsonIntegerSchema(),
                            deleted=JsonBooleanSchema(default=False)),
            factory=Person,
        )

        schema = JsonObjectSchema(additional_properties=person_schema, )

        value = {
            'p1': {
                'name': 'Bibo',
                'age': 15,
                'deleted': True
            },
            'p2': {
                'name': 'Ernie',
                'age': 12,
                'deleted': False
            },
        }

        self.assertEqual(
            {
                'p1': Person(name='Bibo', age=15, deleted=True),
                'p2': Person(name='Ernie', age=12, deleted=False),
            }, schema.from_instance(value))
예제 #2
0
 def get_write_data_params_schema(self) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         group=JsonStringSchema(
             description='Group path. (a.k.a. path in zarr terminology.).',
             min_length=1,
         ),
         encoding=JsonObjectSchema(
             description='Nested dictionary with variable names as keys and '
             'dictionaries of variable specific encodings as values.',
             examples=[{
                 'my_variable': {
                     'dtype': 'int16',
                     'scale_factor': 0.1,
                 }
             }],
             additional_properties=True,
         ),
         consolidated=JsonBooleanSchema(
             description='If True, apply zarr’s consolidate_metadata() '
             'function to the store after writing.'),
         append_dim=JsonStringSchema(
             description=
             'If set, the dimension on which the data will be appended.',
             min_length=1,
         )),
                             required=[],
                             additional_properties=False)
예제 #3
0
파일: response.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             dataset_descriptor=DatasetDescriptor.get_schema(),
             size_estimation=JsonObjectSchema(additional_properties=True)),
         required=['dataset_descriptor', 'size_estimation'],
         additional_properties=True,
         factory=cls)
예제 #4
0
 def get_open_data_params_schema(self,
                                 data_id: str = None) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         group=JsonStringSchema(
             description='Group path. (a.k.a. path in zarr terminology.).',
             min_length=1,
         ),
         chunks=JsonObjectSchema(
             description=
             'Optional chunk sizes along each dimension. Chunk size values may '
             'be None, "auto" or an integer value.',
             examples=[{
                 'time': None,
                 'lat': 'auto',
                 'lon': 90
             }, {
                 'time': 1,
                 'y': 512,
                 'x': 512
             }],
             additional_properties=True,
         ),
         decode_cf=JsonBooleanSchema(
             description=
             'Whether to decode these variables, assuming they were saved '
             'according to CF conventions.',
             default=True,
         ),
         mask_and_scale=JsonBooleanSchema(
             description=
             'If True, replace array values equal to attribute "_FillValue" with NaN. '
             'Use "scaling_factor" and "add_offset" attributes to compute actual values.',
             default=True,
         ),
         decode_times=JsonBooleanSchema(
             description=
             'If True, decode times encoded in the standard NetCDF datetime format '
             'into datetime objects. Otherwise, leave them encoded as numbers.',
             default=True,
         ),
         decode_coords=JsonBooleanSchema(
             description=
             'If True, decode the \"coordinates\" attribute to identify coordinates in '
             'the resulting dataset.',
             default=True,
         ),
         drop_variables=JsonArraySchema(
             items=JsonStringSchema(min_length=1), ),
         consolidated=JsonBooleanSchema(
             description=
             'Whether to open the store using zarr\'s consolidated metadata '
             'capability. Only works for stores that have already been consolidated.',
             default=False,
         ),
     ),
                             required=[],
                             additional_properties=False)
예제 #5
0
    def test_from_json_object_object(self):
        person_schema = JsonObjectSchema(
            properties=dict(name=JsonStringSchema(),
                            age=JsonIntegerSchema(),
                            deleted=JsonBooleanSchema(default=False)))
        schema = JsonObjectSchema(properties=dict(person=person_schema))

        value = {'person': {'name': 'Bibo', 'age': 15}}

        self.assertEqual(
            {'person': {
                'name': 'Bibo',
                'age': 15,
                'deleted': False
            }}, schema.from_instance(value))

        Assignment = namedtuple('Assignment', ['person'])
        schema.factory = Assignment
        self.assertEqual(
            Assignment(person={
                'name': 'Bibo',
                'age': 15,
                'deleted': False
            }), schema.from_instance(value))

        Person = namedtuple('Person', ['name', 'age', 'deleted'])
        person_schema.factory = Person
        self.assertEqual(
            Assignment(person=Person(name='Bibo', age=15, deleted=False)),
            schema.from_instance(value))
예제 #6
0
파일: descriptor.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         name=JsonStringSchema(min_length=1),
         dtype=JsonStringSchema(min_length=1),
         dims=JsonArraySchema(items=JsonStringSchema(min_length=1)),
         chunks=JsonArraySchema(items=JsonIntegerSchema(minimum=0)),
         attrs=JsonObjectSchema(additional_properties=True),
     ),
                             required=['name', 'dtype', 'dims'],
                             additional_properties=False,
                             factory=cls)
예제 #7
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         succeeded=JsonIntegerSchema(nullable=True),
         failed=JsonIntegerSchema(nullable=True),
         active=JsonIntegerSchema(nullable=True),
         start_time=JsonStringSchema(nullable=True),
         completion_time=JsonStringSchema(nullable=True),
         conditions=JsonArraySchema(
             items=JsonObjectSchema(additional_properties=True),
             nullable=True)),
                             additional_properties=True,
                             factory=cls)
예제 #8
0
 def test_to_dict(self):
     schema = JsonObjectSchema(properties=dict(
         consolidated=JsonBooleanSchema()))
     self.assertEqual(
         {
             'type': 'object',
             'properties': {
                 'consolidated': {
                     'type': 'boolean'
                 }
             },
         }, schema.to_dict())
예제 #9
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             store_id=JsonStringSchema(min_length=1),
             opener_id=JsonStringSchema(min_length=1),
             data_id=JsonStringSchema(min_length=1),
             store_params=JsonObjectSchema(additional_properties=True),
             open_params=JsonObjectSchema(additional_properties=True)),
         additional_properties=False,
         required=['data_id'],
         factory=cls,
     )
예제 #10
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=DataStoreDatasetConfig,
         required=['Path'],
         properties=dict(
             Identifier=IdentifierSchema,
             Path=PathSchema,
             StoreInstanceId=IdentifierSchema,  # will be set by server
             StoreOpenParams=JsonObjectSchema(additional_properties=True),
             **_get_common_dataset_properties()),
         additional_properties=False,
     )
예제 #11
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=StyleConfig,
         required=[
             'Identifier',
             'ColorMappings',
         ],
         properties=dict(
             Identifier=JsonStringSchema(min_length=1),
             ColorMappings=JsonObjectSchema(
                 additional_properties=ColorMapping.get_schema())),
         additional_properties=False,
     )
예제 #12
0
 def get_schema(cls) -> JsonObjectSchema:
     """Get the JSON schema for CodeConfig objects."""
     return JsonObjectSchema(
         properties=dict(
             callable_ref=JsonStringSchema(min_length=1),
             callable_params=JsonObjectSchema(additional_properties=True),
             inline_code=JsonStringSchema(min_length=1),
             file_set=FileSet.get_schema(),
             install_required=JsonBooleanSchema(),
         ),
         additional_properties=False,
         factory=cls,
     )
예제 #13
0
 def get_schema(cls):
     return JsonObjectSchema(
         properties=dict(
             store_id=JsonStringSchema(min_length=1),
             writer_id=JsonStringSchema(min_length=1),
             data_id=JsonStringSchema(default=None),
             store_params=JsonObjectSchema(additional_properties=True),
             write_params=JsonObjectSchema(additional_properties=True),
             replace=JsonBooleanSchema(default=False),
         ),
         additional_properties=False,
         required=[],
         factory=cls,
     )
예제 #14
0
파일: response.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             status=JsonStringSchema(enum=STATUS_IDS),
             status_code=JsonIntegerSchema(),
             result=cls.get_result_schema(),
             message=JsonStringSchema(),
             output=JsonArraySchema(items=JsonStringSchema()),
             traceback=JsonArraySchema(items=JsonStringSchema()),
             versions=JsonObjectSchema(additional_properties=True)),
         required=['status'],
         additional_properties=True,
         factory=cls,
     )
예제 #15
0
파일: fileset.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     """Get the JSON-schema for FileSet objects."""
     return JsonObjectSchema(
         properties=dict(
             path=JsonStringSchema(min_length=1),
             sub_path=JsonStringSchema(min_length=1),
             storage_params=JsonObjectSchema(additional_properties=True),
             includes=JsonArraySchema(items=JsonStringSchema(min_length=1)),
             excludes=JsonArraySchema(items=JsonStringSchema(min_length=1)),
         ),
         additional_properties=False,
         required=['path'],
         factory=cls,
     )
예제 #16
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=Authentication,
         required=[
             'Path',
             'Function',
         ],
         properties=dict(
             Path=PathSchema,
             Function=IdentifierSchema,
             InputParameters=JsonObjectSchema(additional_properties=True, ),
         ),
         additional_properties=False,
     )
예제 #17
0
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         access_token=JsonStringSchema(min_length=1),
         token_type=JsonStringSchema(min_length=1)),
                             required=['access_token', 'token_type'],
                             additional_properties=False,
                             factory=cls)
예제 #18
0
파일: descriptor.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     schema = super().get_schema()
     schema.properties.update(
         dims=JsonObjectSchema(additional_properties=JsonIntegerSchema(
             minimum=0)),
         spatial_res=JsonNumberSchema(exclusive_minimum=0.0),
         coords=JsonObjectSchema(
             additional_properties=VariableDescriptor.get_schema()),
         data_vars=JsonObjectSchema(
             additional_properties=VariableDescriptor.get_schema()),
         attrs=JsonObjectSchema(additional_properties=True),
     )
     schema.required = ['data_id', 'data_type']
     schema.additional_properties = False
     schema.factory = cls
     return schema
예제 #19
0
파일: store.py 프로젝트: dcs4cop/xcube
 def get_data_store_params_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(properties=dict(
         root=JsonStringSchema(default=''),
         max_depth=JsonIntegerSchema(nullable=True, default=1),
         read_only=JsonBooleanSchema(default=False),
     ),
                             additional_properties=False)
예제 #20
0
파일: response.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(data_id=JsonStringSchema(min_length=1), ),
         required=['data_id'],
         additional_properties=False,
         factory=cls,
     )
예제 #21
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=DataStoreConfig,
         required=[
             'Identifier',
             'StoreId',
         ],
         properties=dict(
             Identifier=IdentifierSchema,
             StoreId=IdentifierSchema,
             StoreParams=JsonObjectSchema(additional_properties=True, ),
             Datasets=JsonArraySchema(
                 items=DataStoreDatasetConfig.get_schema(), ),
         ),
         additional_properties=False,
     )
예제 #22
0
파일: store.py 프로젝트: micder/xcube
 def get_data_store_params_schema(cls) -> JsonObjectSchema:
     """
     Get descriptions of parameters that must or can be used to instantiate a new DataStore object.
     Parameters are named and described by the properties of the returned JSON object schema.
     The default implementation returns JSON object schema that can have any properties.
     """
     return JsonObjectSchema()
예제 #23
0
 def _get_open_data_params_schema(
         dsd: DatasetDescriptor = None) -> JsonObjectSchema:
     min_date = dsd.time_range[0] if dsd and dsd.time_range else None
     max_date = dsd.time_range[1] if dsd and dsd.time_range else None
     # noinspection PyUnresolvedReferences
     cube_params = dict(
         variable_names=JsonArraySchema(items=JsonStringSchema(
             enum=dsd.data_vars.keys() if dsd and dsd.data_vars else None)),
         time_range=JsonDateSchema.new_range(min_date, max_date))
     if dsd and (('lat' in dsd.dims and 'lon' in dsd.dims) or
                 ('latitude' in dsd.dims and 'longitude' in dsd.dims)):
         min_lon = dsd.bbox[0] if dsd and dsd.bbox else -180
         min_lat = dsd.bbox[1] if dsd and dsd.bbox else -90
         max_lon = dsd.bbox[2] if dsd and dsd.bbox else 180
         max_lat = dsd.bbox[3] if dsd and dsd.bbox else 90
         bbox = JsonArraySchema(
             items=(JsonNumberSchema(minimum=min_lon, maximum=max_lon),
                    JsonNumberSchema(minimum=min_lat, maximum=max_lat),
                    JsonNumberSchema(minimum=min_lon, maximum=max_lon),
                    JsonNumberSchema(minimum=min_lat, maximum=max_lat)))
         cube_params['bbox'] = bbox
     cci_schema = JsonObjectSchema(properties=dict(**cube_params),
                                   required=[],
                                   additional_properties=False)
     return cci_schema
예제 #24
0
 def _get_default_open_params_schema(self) -> JsonObjectSchema:
     params = dict(
         dataset_name=JsonStringSchema(min_length=1,
                                       enum=list(
                                           self._handler_registry.keys())),
         variable_names=JsonArraySchema(
             items=(JsonStringSchema(min_length=0)), unique_items=True),
         crs=JsonStringSchema(),
         # W, S, E, N
         bbox=JsonArraySchema(
             items=(JsonNumberSchema(minimum=-180, maximum=180),
                    JsonNumberSchema(minimum=-90, maximum=90),
                    JsonNumberSchema(minimum=-180, maximum=180),
                    JsonNumberSchema(minimum=-90, maximum=90))),
         spatial_res=JsonNumberSchema(),
         time_range=JsonDateSchema.new_range(),
         time_period=JsonStringSchema(),
     )
     required = [
         'variable_names',
         'bbox',
         'spatial_res',
         'time_range',
     ]
     return JsonObjectSchema(properties=params, required=required)
예제 #25
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         properties=dict(
             IsSubstitute=JsonBooleanSchema(),
             RequiredScopes=JsonArraySchema(items=IdentifierSchema)),
         additional_properties=False,
     )
예제 #26
0
    def test_from_json_object_array_object(self):
        person_schema = JsonObjectSchema(
            properties=dict(name=JsonStringSchema(),
                            age=JsonIntegerSchema(),
                            deleted=JsonBooleanSchema(default=False)))

        schema = JsonObjectSchema(properties=dict(persons=JsonArraySchema(
            items=person_schema)))

        value = {
            'persons': [{
                'name': 'Bibo',
                'age': 15
            }, {
                'name': 'Ernie',
                'age': 12
            }]
        }

        self.assertEqual(
            {
                'persons': [{
                    'name': 'Bibo',
                    'age': 15,
                    'deleted': False
                }, {
                    'name': 'Ernie',
                    'age': 12,
                    'deleted': False
                }]
            }, schema.from_instance(value))

        Assignment = namedtuple('Assignment', ['persons'])
        schema.factory = Assignment
        self.assertEqual(
            Assignment(persons=[{
                'name': 'Bibo',
                'age': 15,
                'deleted': False
            }, {
                'name': 'Ernie',
                'age': 12,
                'deleted': False
            }]), schema.from_instance(value))

        Person = namedtuple('Person', ['name', 'age', 'deleted'])
        person_schema.factory = Person
        self.assertEqual(
            Assignment(persons=[
                Person(name='Bibo', age=15, deleted=False),
                Person(name='Ernie', age=12, deleted=False)
            ]), schema.from_instance(value))
예제 #27
0
 def get_schema(cls):
     return JsonObjectSchema(
         properties=dict(api_uri=JsonStringSchema(min_length=1),
                         access_token=JsonStringSchema(min_length=1)),
         additional_properties=False,
         required=["api_uri", "access_token"],
         factory=cls,
     )
예제 #28
0
파일: descriptor.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     schema = super().get_schema()
     schema.properties.update(
         feature_schema=JsonObjectSchema(additional_properties=True), )
     schema.required = ['data_id']
     schema.additional_properties = False
     schema.factory = cls
     return schema
예제 #29
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=PlaceGroupConfig,
         required=[
             'Identifier',
             'Path',
         ],
         properties=dict(
             Identifier=IdentifierSchema,
             Title=StringSchema,
             Path=PathSchema,
             Join=PlaceGroupJoin.get_schema(),
             PropertyMapping=JsonObjectSchema(
                 additional_properties=PathSchema, ),
         ),
         additional_properties=False,
     )
예제 #30
0
파일: config.py 프로젝트: dcs4cop/xcube
 def get_schema(cls) -> JsonObjectSchema:
     return JsonObjectSchema(
         factory=DatasetConfig,
         required=['Identifier', 'Path'],
         properties=dict(
             Identifier=IdentifierSchema,
             Path=PathSchema,
             FileSystem=FileSystemSchema,
             Anonymous=BooleanSchema,
             Endpoint=UrlSchema,
             Region=IdentifierSchema,
             Function=IdentifierSchema,
             InputDatasets=JsonArraySchema(items=IdentifierSchema),
             InputParameters=JsonObjectSchema(additional_properties=True, ),
             **_get_common_dataset_properties(),
         ),
         additional_properties=False,
     )