def test_can_produce_multilayer_config_from_dict(self): schema_low = SchemaBuilder() \ .add('options', dict) \ .build() schema_mid = SchemaBuilder() \ .add('desc', lambda: Config(schema=schema_low)) \ .build() schema_top = SchemaBuilder() \ .add('container', lambda: DefaultConfig( lambda v: Config(v, schema=schema_mid))) \ .build() value = 1 source = Config( {'container': { 'elem': { 'desc': { 'options': { 'k': value } } } }}, schema=schema_top) self.assertEqual(value, source.container['elem'].desc.options['k'])
def test_can_copy_recursively(self): # will be copied shallow, because uses plain dict schema_low = SchemaBuilder() \ .add('options', dict) \ .build() # will be copied deeply, because uses DictConfig schema_top = SchemaBuilder() \ .add('container', lambda: DictConfig( lambda v: Config(v, schema=schema_low))) \ .build() src_conf = Config({ 'container': { 'x': { 'options': { 'k': 1 } } } }, schema=schema_top) copied_conf = Config(src_conf, schema=schema_top) copied_conf['container']['y'] = {'options': {'k': 2} } self.assertNotEqual(copied_conf, src_conf)
def test_cant_set_incorrect_value(self): schema = SchemaBuilder() \ .add('k', int) \ .build() with self.assertRaises(ValueError): Config({ 'k': 'srf' }, schema=schema)
def test_cant_set_incorrect_key(self): schema = SchemaBuilder() \ .add('k', int) \ .build() with self.assertRaises(KeyError): Config({ 'v': 11 }, schema=schema)
def test_can_save_and_load(self): with TestDir() as test_dir: schema_low = SchemaBuilder() \ .add('options', dict) \ .build() schema_mid = SchemaBuilder() \ .add('desc', lambda: Config(schema=schema_low)) \ .build() schema_top = SchemaBuilder() \ .add('container', lambda: DictConfig( lambda v: Config(v, schema=schema_mid))) \ .build() source = Config({ 'container': { 'elem': { 'desc': { 'options': { 'k': (1, 2, 3), 'd': 'asfd', } } } } }, schema=schema_top) p = osp.join(test_dir, 'f.yaml') source.dump(p) loaded = Config.parse(p, schema=schema_top) self.assertTrue(isinstance( loaded.container['elem'].desc.options['k'], list)) loaded.container['elem'].desc.options['k'] = \ tuple(loaded.container['elem'].desc.options['k']) self.assertEqual(source, loaded)
import getpass import json import os import os.path as osp from collections import OrderedDict import requests from cvat.utils.cli.core import CLI as CVAT_CLI from cvat.utils.cli.core import CVAT_API_V1 from datumaro.components.config import Config, SchemaBuilder from datumaro.components.extractor import SourceExtractor, DatasetItem from datumaro.util.image import Image, lazy_image, load_image CONFIG_SCHEMA = SchemaBuilder() \ .add('task_id', int) \ .add('server_url', str) \ .build() class cvat_rest_api_task_images(SourceExtractor): def _image_local_path(self, item_id): task_id = self._config.task_id return osp.join( self._cache_dir, 'task_{}_frame_{:06d}.jpg'.format(task_id, int(item_id))) def _make_image_loader(self, item_id): return lazy_image(item_id, lambda item_id: self._image_loader(item_id, self)) def _is_image_cached(self, item_id):