Esempio n. 1
0
def test_ensure_file_op():
    # When the ensure method is called with a file_op and no content
    struct = {"a": {"b": "0"}}
    struct = structure.ensure(struct, "a/b", file_op=NO_OVERWRITE)
    # Then the content should remain the same
    # But the file_op should change
    assert struct["a"]["b"] == ("0", NO_OVERWRITE)
Esempio n. 2
0
def test_ensure_overriden():
    # When the original struct contains a leaf
    struct = {"a": {"b": "0"}}
    # that is overridden using the ensure method,
    struct = structure.ensure(struct, Path("a", "b"), content="1")
    # and the file content should be overridden
    assert struct["a"]["b"] == ("1", operations.create)
Esempio n. 3
0
    def add_files(struct, opts):
        nov, sou = operations.no_overwrite(), operations.skip_on_update()
        struct = structure.ensure(struct, "tests/file0", "new")
        struct = structure.ensure(struct, "tests/file1", "new", nov)
        struct = structure.ensure(struct, "tests/file2", "new", sou)
        struct = structure.merge(
            struct,
            {
                "tests": {
                    "file3": ("new", nov),
                    "file4": ("new", sou),
                    "file5": ("new", operations.create),
                    "file6": "new",
                }
            },
        )

        return struct, opts
Esempio n. 4
0
def test_ensure_nested():
    # When the original struct does not contain a leaf
    struct = {"a": {"b": "0"}}
    # that is added using the ensure method,
    struct = structure.ensure(struct,
                              Path("a", "c", "d", "e", "f"),
                              content="1")
    # then all the necessary parent folder should be included
    assert isinstance(struct["a"]["c"], dict)
    assert isinstance(struct["a"]["c"]["d"], dict)
    assert isinstance(struct["a"]["c"]["d"]["e"], dict)
    # and the file itself
    assert struct["a"]["c"]["d"]["e"]["f"] == ("1", operations.create)
def replace_readme(struct: Structure, opts: ScaffoldOpts) -> ActionParams:
    """Replace the readme.md of the markdown extension by our own
    See :obj:`pyscaffold.actions.Action`
    """
    return ensure(struct, "README.md", readme_md, NO_OVERWRITE), opts
Esempio n. 6
0
def test_ensure_path():
    # When the ensure method is called with an string path
    struct = {}
    struct = structure.ensure(struct, "a/b/c/d", content="1")
    # Then the effect should be the same as if it were split
    assert struct["a"]["b"]["c"]["d"] == ("1", operations.create)
Esempio n. 7
0
    def add_files(struct, opts):
        struct = structure.ensure(struct, "tests/extra.file", "content")
        struct = structure.merge(struct, {"tests": {"another.file": "content"}})

        return struct, opts