Exemple #1
0
def test_uniquemove():
    settings = core.Settings(False, True, os.path.abspath(RESULT_DIR),
                             [os.path.abspath(path) for path in [SOURCE_1]],
                             False, True)
    fd = core.FilepathDict()
    for el in settings.source:
        core._scan_duplicates(os.path.abspath(el), fd)
    fd = core._move_uniques(fd, settings.source, settings.dest_path,
                            settings.op_test)
    report_buffer = io.StringIO()
    fd._save_uniques_(target=report_buffer)
    report = report_buffer.getvalue()
    report_buffer.close()

    fulltext_templates = [
        UNIQUE_NAME_1, UNIQUE_NAME_2, UNIQUE_NAME_3, UNIQUE_NAME_4,
        UNIQUE_NAME_5, UNIQUE_NAME_6, UNIQUE_NAME_7, UNIQUE_NAME_8
    ]
    for template in fulltext_templates:
        if template in report:
            continue
        else:
            assert False, f'{template} not found.'

    re_templates = [UNIQUE_MOVE_TEMPLATE]
    for template in re_templates:
        if re.search(template, report):
            continue
        else:
            assert False, f'{template} not found.'
Exemple #2
0
def test_filedict_eq():
    fd1 = core.FilepathDict()
    core._scan_duplicates(SOURCE_1, fd1)
    fd2 = core.FilepathDict()
    core._scan_duplicates(SOURCE_1, fd2)
    assert fd1 == fd2
    fd3 = core.FilepathDict()
    core._scan_duplicates(SOURCE_2, fd3)
    assert fd1 != fd3

    n1 = fd1.duplicateslist_count()
    n2 = fd2.duplicateslist_count()
    n3 = fd3.duplicateslist_count()

    assert n1 == n2
    assert n1 == n3
Exemple #3
0
def test_print_duplicates(capfd):
    fd1 = core.FilepathDict()
    core._scan_duplicates(SOURCE_1, fd1)
    fd1.print_duplicates()
    out = [line for line in capfd.readouterr()[0].split('\n') if line.strip()]

    assert out[0] == SHOW_DUPLICATE_REPORT_FIRSTLINE
    assert out[1] == SHOW_DUPLICATE_REPORT_NAMELINE
    assert out[2] == SHOW_DUPLICATE_REPORT_ATTRLINE
    assert out[3].endswith(SHOW_DUPLICATE_REPORT_DUPNAME_2)
    assert out[4].endswith(SHOW_DUPLICATE_REPORT_DUPNAME_1)
    assert out[-1] == SHOW_DUPLICATE_REPORT_LASTLINE
Exemple #4
0
def test_print_uniques(capfd):
    fd1 = core.FilepathDict()
    core._scan_duplicates(SOURCE_1, fd1)
    fd1.print_uniques()
    out = [line for line in capfd.readouterr()[0].split('\n') if line.strip()]

    i = 0
    for s in out:
        if i in [3, 6, 9, 12, 15, 18, 21, 24]:
            assert s.endswith(SHOW_UNIQUE_REPORT[i])
        else:
            assert s == SHOW_UNIQUE_REPORT[i]
        i += 1
Exemple #5
0
def test_unique_enamerator():
    settings = core.Settings(False, True, os.path.abspath(RESULT_DIR),
                             [os.path.abspath(path) for path in [SOURCE_1]],
                             False, True)
    fd = core.FilepathDict()
    for el in settings.source:
        core._scan_duplicates(os.path.abspath(el), fd)

    report_buffer = io.StringIO()
    for sk in fd.keys():
        for unique in fd[sk].uniques():
            print(f'{unique}', file=report_buffer)
    report = report_buffer.getvalue()
    report_buffer.close()

    re_templates = [UNIQUE_ENUM_TEMPLATE]
    for template in re_templates:
        if re.search(template, report):
            continue
        else:
            assert False, f'{template} not found.'