Ejemplo n.º 1
0
def test_utilities():
    # sub_path()
    a = "abc/def/file.txt"
    base = "abc"
    assert sub_path(a, base) == "def/file.txt"
    # archive_path()
    assert archive_path("a", r"b\\c\d", "e") == "a/b/c/d/e"
Ejemplo n.º 2
0
def one_way_compare(d1, d2, visited=None):
    """
    Compare directory *d2* against *d1* for removal and changes.

    Raise an error if a file present in *d1* is not found or is different from
    the one found in *d2*, but ignores files present in *d2* and not in *d1*.
    """
    if visited is None:
        visited = {}
    for base, dirs, files in os.walk(d1):
        sub_dir = sub_path(base, d1)
        for file in files:
            sub_file = join(sub_dir, file)
            f1 = join(d1, sub_file)
            f2 = join(d2, sub_file)
            if sub_file in visited:
                continue
            assert isfile(f2)
            assert control_sum(f1) == control_sum(f2)
            assert os.stat(f1).st_mode == os.stat(f2).st_mode
            visited[sub_file] = None