def dump(obj: Properties, fp: TextIO, *args, **kwargs) -> None: """ Serialize ``obj`` as a :py:class:`~Pegasus.api.properties.Properties` formatted stream to ``fp`` (a ``.write()``-supporting file-like object). :param obj: Properties to serialize :type obj: Properties :param fp: file like object to serialize to :type fp: TextIO :rtype: NoReturn """ obj.write(fp)
def dumps(obj: Properties, *args, **kwargs) -> str: """ Serialize ``obj`` to a :py:class:`~Pegasus.api.properties.Properties` formatted ``str``. :param obj: Properties to serialize :type obj: Properties :return: Properties serialized as a string :rtype: str """ with io.StringIO() as s: obj.write(s) return s.getvalue()
def loads(s: str, *args, **kwargs) -> Properties: """ Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance containing a Properties document) to a :py:class:`~Pegasus.api.properties.Properties` object. :param s: string to load from :type s: str :return: deserialized Properties object :rtype: Properties """ conf = ConfigParser() conf.read_string("[{}]\n".format(DEFAULTSECT) + s) props = Properties() props._conf = conf return props
def load(fp: TextIO, *args, **kwargs) -> Properties: """ Deserialize ``fp`` (a ``.read()``-supporting file-like object containing a Properties document) to a :py:class:`~Pegasus.api.properties.Properties` object. :param fp: file like object to load from :type fp: TextIO :return: deserialized Properties object :rtype: Properties """ conf = ConfigParser() conf.read_string("[{}]\n".format(DEFAULTSECT) + fp.read()) props = Properties() props._conf = conf return props
def test_dump(): props = Properties() props["a"] = "b" props["c"] = "d" with TemporaryFile(mode="w+") as f: dump(props, f) f.seek(0) assert f.read() == "a = b\nc = d\n\n"
def test_ls(self, capsys, props): try: Properties.ls("pegasus.pmc") captured = capsys.readouterr().out assert ( captured == "pegasus.pmc_priority\npegasus.pmc_request_cpus\npegasus.pmc_request_memory\npegasus.pmc_task_arguments\n" ) Properties.ls() Properties.ls("nothing") props.ls() except: pytest.raises("should not have failed")
def test_dumps(): props = Properties() props["a"] = "b" props["c"] = "d" assert dumps(props) == "a = b\nc = d\n\n"
def props(): return Properties()