def to_yaml(self) -> str: """ Output the run description as a yaml string """ yaml = YAML() with io.StringIO() as stream: yaml.dump(self.serialize(), stream=stream) output = stream.getvalue() return output
def to_yaml_for_storage(desc: current.RunDescriber) -> str: """ Serialize the given RunDescriber to YAML as a RunDescriber of the version for storage """ yaml = YAML() with io.StringIO() as stream: yaml.dump(to_dict_for_storage(desc), stream=stream) output = stream.getvalue() return output
def test_station_config_can_be_loaded_from_snapshot(example_station): assert station_config_has_been_loaded(example_station) # ensure that we can correctly dump config which is a subclass of UserDict configdump = json.dumps(example_station.config, cls=NumpyJSONEncoder) # as this is now a regular dict we can load it back loaded_config = json.loads(configdump) # now lets ensure that we can recreate the # station from the loaded config # first we need to get a yaml repr of the data yaml = YAML() with StringIO() as output: yaml.dump(loaded_config, output) yaml_repr = output.getvalue() # which we can then reload into the station new_station = Station(default=False) new_station.load_config(yaml_repr) assert example_station.config == new_station.config