Пример #1
0
def test_dedup():
    db = mongomock.MongoClient().image_database.images
    duplicate_finder.add(['tests'], db)
    assert db.count() == 4

    dups = duplicate_finder.find(db, match_time=False)
    assert len(dups) == 1
    dup = dups[0]

    for item in dup['items'][1:]:
        # It is still in its original place
        assert os.path.exists(item['file_name'])

    dups = duplicate_finder.find(db)
    duplicate_finder.delete_duplicates(dups, db)

    for item in dup['items'][1:]:
        # The files have been moved
        assert not os.path.exists(item['file_name'])
        assert os.path.exists(
            os.path.join('Trash', os.path.basename(item['file_name'])))

    assert db.count() == 2

    # Move files back
    shutil.move('Trash/sideways.jpg', 'tests/images/deeply/nested/image')
    shutil.move('Trash/smaller.jpg', 'tests/images/deeply/nested/image')
    os.rmdir('Trash')
Пример #2
0
def test_find():
    db = mongomock.MongoClient().image_database.images
    duplicate_finder.add(['tests/images/deeply/nested'], db)

    dups = duplicate_finder.find(db, match_time=False)
    assert len(dups) == 1

    dup = dups[0]
    assert dup['total'] == 2

    time_dups = duplicate_finder.find(db, match_time=True)
    assert dups == time_dups
Пример #3
0
def test_dedup():
    db = mongomock.MongoClient().image_database.images
    duplicate_finder.add(['tests'], db)
    assert db.count() == 8

    dups = duplicate_finder.find(db, match_time=False)
    assert len(dups) == 2

    duplicate_finder.delete_duplicates(dups, db)

    dup = dups[0]

    # The first item should still be in its original place
    assert os.path.exists(dup['items'][0]['file_name'])

    # The rest of the files should be moved to the trash
    for item in dup['items'][1:]:
        assert not os.path.exists(item['file_name'])
        assert os.path.exists(
            os.path.join('Trash', os.path.basename(item['file_name'])))

    assert db.count() == 4

    # Move files back
    for dup in dups:
        for item in dup['items'][1:]:
            shutil.move(
                os.path.join('Trash', os.path.basename(item['file_name'])),
                item['file_name'])
    os.rmdir('Trash')