def test_missing_serialized_keys(): config = get_config_for_test() serialized = {'type': 'SerializableTypes.GENERIC_DEPLOYMENT'} with pytest.raises(RuntimeError): deserialize_generic_deployment(config=config, serialized=serialized)
def test_invalid_serialized_type(): config = get_config_for_test() serialized = {'type': 'SerializableTypes.GENERIC_DEPLOYMENT2'} with pytest.raises(AssertionError): deserialize_generic_deployment(config=config, serialized=serialized)
def deserialize(config: ClusterConfig, serialized: dict) -> 'DaskWorkerDeployment': try: assert serialized['type'] == str( SerializableTypes.DASK_WORKER_DEPLOYMENT) deployment = deserialize_generic_deployment( config=config, serialized=serialized['deployment']) bokeh_tunnel = deployment.node.tunnel( there=serialized['bokeh_tunnel_there'], here=serialized['bokeh_tunnel_here']) return DaskWorkerDeployment(deployment=deployment, bokeh_tunnel=bokeh_tunnel) except KeyError as e: raise RuntimeError("Unable to deserialize.") from e
def deserialize_jupyter_deployment_impl( config: ClusterConfig, uuid: str, serialized: dict) -> JupyterDeploymentImpl: # noqa """Counterpart to :meth:`.JupyterDeploymentImpl.serialize`.""" try: assert serialized['type'] == str( SerializableTypes.JUPYTER_DEPLOYMENT_IMPL) deployment = deserialize_generic_deployment( config=config, serialized=serialized['deployment']) tunnel = deployment.node.tunnel(there=serialized['tunnel_there'], here=serialized['tunnel_here']) return JupyterDeploymentImpl(deployment=deployment, tunnel=tunnel, token=serialized['token'], uuid=uuid) except KeyError as e: raise RuntimeError("Unable to deserialize.") from e
def test_serialize_deserialize(): config = get_config_for_test() value = GenericDeployment(node=NodeImpl(config=config), pid=1, runtime_dir='/dir') serialized = value.serialize() assert serialized == {'type': 'SerializableTypes.GENERIC_DEPLOYMENT', 'node': {'type': 'SerializableTypes.NODE_IMPL', 'host': None, 'port': None, 'cores': None, 'memory': None, 'allocated_until': None}, 'pid': 1, 'runtime_dir': '/dir'} deserialized = deserialize_generic_deployment(config=config, serialized=serialized) assert deserialized == value