def test_load_yaml1(tmpdir): with open(os.path.join(cur_dir, 'yaml/test-driver.yml'), encoding='utf8') as fp: a = yaml.load(fp) assert isinstance(a[0], KVSearchDriver) assert isinstance(a[1], ControlReqDriver) assert isinstance(a[2], BaseDriver) with open(os.path.join(tmpdir, 'test_driver.yml'), 'w', encoding='utf8') as fp: yaml.dump(a[0], fp) with open(os.path.join(tmpdir, 'test_driver.yml'), encoding='utf8') as fp: b = yaml.load(fp) assert isinstance(b, KVSearchDriver) assert b._executor_name == a[0]._executor_name
def test_load_yaml1(self): with open(os.path.join(cur_dir, 'yaml/test-driver.yml'), encoding='utf8') as fp: a = yaml.load(fp) self.assertTrue(isinstance(a[0], KVSearchDriver)) self.assertTrue(isinstance(a[1], ControlReqDriver)) self.assertTrue(isinstance(a[2], BaseDriver)) with open('test_driver.yml', 'w', encoding='utf8') as fp: yaml.dump(a[0], fp) with open('test_driver.yml', encoding='utf8') as fp: b = yaml.load(fp) self.assertTrue(isinstance(b, KVSearchDriver)) assert b._executor_name == a[0]._executor_name self.add_tmpfile('test_driver.yml')
def export_api(args): from .export import api_to_dict from jina import __version__ from jina.logging import default_logger if args.yaml_path: for yp in args.yaml_path: f_name = (yp % __version__) if '%s' in yp else yp from jina.helper import yaml with open(f_name, 'w', encoding='utf8') as fp: yaml.dump(api_to_dict(), fp) default_logger.info(f'API is exported to {f_name}') if args.json_path: for jp in args.json_path: f_name = (jp % __version__) if '%s' in jp else jp import json with open(f_name, 'w', encoding='utf8') as fp: json.dump(api_to_dict(), fp, sort_keys=True) default_logger.info(f'API is exported to {f_name}')