def test_modify_no_function(): # Given a structure structure = {"a": {"b": "0"}} # When the modify helper is called with an update rule but no modifier structure = helpers.modify(structure, "a/b", update_rule=helpers.NO_CREATE) # Then the content should remain the same # But the flag should change assert structure["a"]["b"] == ("0", helpers.NO_CREATE)
def modify_setupcfg(struct, opts): """Modify setup.cfg to add install_requires and pytest settings Args: struct (dict): project representation as (possibly) nested :obj:`dict`. opts (dict): given options, see :obj:`create_project` for an extensive list. Returns: struct, opts: updated project representation and options """ opts["namespace"] = [PYSCAFFOLDEXT_NS] setupcfg_path = [opts["project"], "setup.cfg"] struct = helpers.modify(struct, setupcfg_path, add_install_requires) struct = helpers.modify(struct, setupcfg_path, add_pytest_requirements) struct = helpers.modify(struct, setupcfg_path, lambda x: add_entry_point(x, opts)) return struct, opts
def test_modify_non_existent(): # Given the original structure does not contain a leaf # that is targeted by the modify method, structure = {"a": {"b": "0"}} # When the modify is called # Then the argument passed should be None def _modifier(old): assert old is None return "1" structure = helpers.modify(structure, Path("a", "c"), _modifier) # But the result of the modifier function should be included in the tree assert structure["a"]["c"] == "1"