Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_reject_without_ancestor():
# Given a defined structure,
structure = {"a": {"b": {"c": "0"}}}
# when someone tries to remove a file using the reject method
# but one of its ancestor does not exist in the structure,
structure = helpers.reject(structure, "a/b/x/c")
# then the structure should be the same
assert structure["a"]["b"]["c"] == "0"
assert len(structure["a"]["b"]["c"]) == 1
assert len(structure["a"]["b"]) == 1
assert len(structure["a"]) == 1
def test_reject_without_file():
# Given a defined structure,
structure = {"a": {"b": {"c": "0"}}}
# when someone tries to remove a file using the reject method
# but one of its ancestor does not exist in the structure,
structure = helpers.reject(structure, "a/b/x")
# then the structure should be the same
assert structure["a"]["b"]["c"] == "0"
assert len(structure["a"]["b"]["c"]) == 1
assert len(structure["a"]["b"]) == 1
assert len(structure["a"]) == 1
def test_reject():
# When the original structure contain a leaf
structure = {"a": {"b": {"c": "0"}}}
# that is removed using the reject method,
structure = helpers.reject(structure, Path("a", "b", "c"))
# then the structure should not contain the file
assert "c" not in structure["a"]["b"]
path = [opts["project"], "models", ".gitignore"]
struct = helpers.ensure(struct, path, gitignore_all, helpers.NO_OVERWRITE)
path = [opts["project"], "references", ".gitignore"]
struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)
path = [opts["project"], "reports", "figures", ".gitignore"]
struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)
path = [opts["project"], "environment.yaml"]
environment_yaml = templates.environment_yaml(opts)
struct = helpers.ensure(struct, path, environment_yaml, helpers.NO_OVERWRITE)
path = [opts["project"], "requirements.txt"]
struct = helpers.reject(struct, path)
path = [opts["project"], "configs", ".gitignore"]
struct = helpers.ensure(struct, path, "", helpers.NO_OVERWRITE)
return struct, opts
"""Replace the readme.md of the markdown extension by our own
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
"""
# let the markdown extension do its job first
struct, opts = MarkDown("markdown").markdown(struct, opts)
file_path = [opts["project"], "README.md"]
struct = helpers.reject(struct, file_path)
readme = templates.readme_md(opts)
struct = helpers.ensure(struct, file_path, readme, helpers.NO_OVERWRITE)
return struct, opts