def test_newly_created_file_not_user_modified():
    content = "lorem ipsum\n" * 10
    hm = {}

    write_file(ex_file, content, hm)

    assert not user_modified(ex_file, hm)
def test_write_file_register_hash():  # TODO less specific implementation
    txt = """
print 'toto'
print 'rev'
"""
    hm = {}
    write_file(ex_file, txt, hm)
    assert ex_file in hm
def test_tempering_detected():
    txt = """
print 'toto'
print 'rev'
"""
    hm = {}
    write_file(ex_file, txt, hm)
    assert not user_modified(ex_file, hm)
    txt = txt[:3] + '#' + txt[4:]
    with open(ex_file, 'w') as f:
        f.write(txt)

    assert user_modified(ex_file, hm)
Exemplo n.º 4
0
def copy_dir(cur_src_pth, cur_dst_pth, handlers, pkg_cfg):
    """ Parse cur_src_pth assumed to be a directory
    in repository and regenerate all files in it
    copy regenerated files in cur_dst_pth.

    Function called recursively on sub directories

    Does not make any test on the existence of cur_dst_pth
    Does not create any directory

    TODO: copy of regenerate_dir, not DRY

    args:
     - cur_src_pth (str): current pth to look into
     - cur_dst_pth (str): mirror of cur_src_pth on destination
     - handlers (dict of func): associate keys to handler functions
     - pkg_cfg (dict of (str: dict)): more information to pass to handlers
    """
    if basename(cur_src_pth) == "src":
        if 'base' in pkg_cfg:
            # check for namespace directory
            namespace = pkg_cfg['base']['namespace']
            if namespace is not None:
                cur_dst_pth = cur_dst_pth + "/" + namespace

            # create pkgname directory in src
            pkgname = pkg_cfg['base']['pkgname']
            cur_dst_pth = cur_dst_pth + "/" + pkgname

    items = ls(cur_src_pth)
    for name, is_dir_type in items:
        if is_dir_type:
            new_name = replace(name, handlers, pkg_cfg)
            if new_name not in ("", "_"):
                dst_dir = cur_dst_pth + "/" + new_name
                if exists(dst_dir):
                    copy_dir(cur_src_pth + "/" + name,
                             dst_dir,
                             handlers,
                             pkg_cfg)
        else:
            new_name = replace(name, handlers, pkg_cfg)
            if (new_name.split(".")[0] != "_" and
                  new_name[-3:] not in ("pyc", "pyo")):
                src_content = get(cur_src_pth + "/" + name)
                new_src_content = replace(src_content, handlers, pkg_cfg)
                # overwrite file without any warning
                write_file(cur_dst_pth + "/" + new_name, new_src_content)