def run_event_server(tmp_path, event_conf): conf_path = tmp_path / 'event.yaml' json.encode_file(event_conf, conf_path) proc = Process( ['python', '-m', 'hat.event.server', '--conf', str(conf_path)]) return proc
def wrapper(gateway_conf, ignore_stderr=False): conf_path = tmp_path / 'gateway.yaml' json.encode_file(gateway_conf, conf_path) proc = Process( ['python', '-m', 'hat.gateway', '--conf', str(conf_path)], ignore_stderr=ignore_stderr) wait_until(proc.is_running) return proc
def _rpc_save(self): conf = dict(common.default_conf, log=common.get_log_conf(self._data.data['settings']), settings=self._data.data['settings'], devices=[device.get_conf() for device in self._devices.values()]) self._conf_path.parent.mkdir(parents=True, exist_ok=True) json.encode_file(conf, self._conf_path) self._logger.log('configuration saved')
def monitor_process(tmp_path, monitor_conf, monitor_port): conf_path = tmp_path / 'monitor.yaml' json.encode_file(monitor_conf, conf_path) args = ['python', '-m', 'hat.monitor.server', '--conf', str(conf_path), '--ui-path', str(tmp_path)] with Process(args) as p: p.wait_connection(monitor_port, 5) yield p
def monitor_process(tmp_path, monitor_conf, monitor_port): conf_path = tmp_path / 'monitor.yaml' json.encode_file(monitor_conf, conf_path) with Process([ 'python', '-m', 'hat.monitor.server', '--conf', str(conf_path), '--ui-path', str(tmp_path) ]) as p: wait_until(p.listens_on, monitor_port) yield p
def run_monitor_subprocess(conf, conf_folder_path): conf_path = conf_folder_path / 'monitor.yaml' json.encode_file(conf, conf_path) creationflags = (subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == 'win32' else 0) return psutil.Popen([ sys.executable, '-m', 'hat.monitor.server.main', '--conf', str(conf_path), '--ui-path', '' ], creationflags=creationflags)
def test_init_repo_json(tmp_path): json_data = [[['TypeRef', 'Module', 'T1'], ['BooleanType']]] path = tmp_path / 'repo.json' json.encode_file(json_data, path) repo_file = asn1.Repository.from_json(path) repo_str = asn1.Repository.from_json(json_data) assert sorted(repo_file.to_json()) == sorted(repo_str.to_json()) assert sorted(repo_file.to_json()) == sorted(json_data)
def run_orchestrator_subprocess(conf, conf_folder_path): conf_path = conf_folder_path / "orchestrator.yaml" json.encode_file(conf, conf_path) creationflags = (subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == 'win32' else 0) return psutil.Popen([ 'python', '-m', 'hat.orchestrator', '--conf', str(conf_path), '--ui-path', str(conf_folder_path) ], creationflags=creationflags)
def _create_package_json(name, desc, deps): version = common.get_version(common.VersionType.SEMVER) dst_dir = _get_dst_dir(name) package = { 'name': name, 'version': version, 'description': desc, 'homepage': 'https://github.com/hat-open/hat-core', 'bugs': 'https://github.com/hat-open/hat-core/issues', 'license': 'Apache-2.0', 'main': 'index.js', 'repository': 'hat-open/hat-core', 'dependencies': deps } json.encode_file(package, dst_dir / 'package.json')
def test_encode_decode_file(tmp_path, format, indent, data): path = tmp_path / 'data' json.encode_file(data, path, format, indent) decoded = json.decode_file(path, format) assert data == decoded if format == json.Format.JSON: path = path.with_suffix('.json') elif format == json.Format.YAML: path = path.with_suffix('.yaml') else: raise NotImplementedError() json.encode_file(data, path, None, indent) decoded = json.decode_file(path, None) assert data == decoded
def wrapper(backend_conf, modules_conf, ignore_stderr=False): nonlocal last_server_id server_id = last_server_id + 1 last_server_id = server_id port = unused_tcp_port_factory() event_server_address = f'tcp+sbs://127.0.0.1:{port}' conf = {'type': 'event', 'log': {'version': 1}, 'monitor': {'name': 'event server {server_id}', 'group': 'event servers', 'monitor_address': monitor_address, 'component_address': event_server_address}, 'backend_engine': {'server_id': server_id, 'backend': backend_conf}, 'module_engine': {'modules': modules_conf}, 'communication': {'address': event_server_address}} conf_path = tmp_path / f'event_{server_id}.yaml' json.encode_file(conf, conf_path) return EventServerProcess(conf_path, port, ignore_stderr=ignore_stderr)
async def test_validate_conf(tmp_path): name = 'name' conf_path = tmp_path / 'conf.json' schema_path = tmp_path / 'schema.json' conf = { 'views': [{ 'name': name, 'view_path': str(tmp_path), 'conf_path': str(conf_path) }] } manager = await hat.gui.view.create_view_manager(conf) with pytest.raises(Exception): await manager.get(name) schema = {'id': 'test://schema', 'type': 'object', 'required': ['abc']} json.encode_file(schema, schema_path) with pytest.raises(Exception): await manager.get(name) data = {'cba': 123} json.encode_file(data, conf_path) with pytest.raises(Exception): await manager.get(name) data = {'abc': 321} json.encode_file(data, conf_path) view = await manager.get(name) assert view.name == name assert view.conf == data assert view.data == {conf_path.name: data, schema_path.name: schema} await manager.async_close()
def generate(): repo = asn1.Repository(*src_paths) data = repo.to_json() for dst_path in dst_paths: json.encode_file(data, dst_path, indent=None)
def conf_path(tmp_path, conf): path = tmp_path / 'syslog.yaml' json.encode_file(conf, path) return path
async def set_settings(self, settings): settings_path.parent.mkdir(parents=True, exist_ok=True) return json.encode_file(settings, settings_path)