Пример #1
0
def test_type_changes_difficult(sync):

    file_events = [
        # convert to FileDeleted -> DirCreated
        FileModifiedEvent(ipath(1)),
        FileDeletedEvent(ipath(1)),
        FileCreatedEvent(ipath(1)),
        FileDeletedEvent(ipath(1)),
        DirCreatedEvent(ipath(1)),
        # convert to FileDeleted(path1) -> DirCreated(path2)
        FileModifiedEvent(ipath(2)),
        FileDeletedEvent(ipath(2)),
        FileCreatedEvent(ipath(2)),
        FileDeletedEvent(ipath(2)),
        DirCreatedEvent(ipath(2)),
        DirMovedEvent(ipath(2), ipath(3)),
    ]

    res = [
        FileDeletedEvent(ipath(1)),
        DirCreatedEvent(ipath(1)),
        FileDeletedEvent(ipath(2)),
        DirCreatedEvent(ipath(3)),
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #2
0
def test_move_events(sync):

    file_events = [
        # created + moved -> created
        FileCreatedEvent(ipath(1)),
        FileMovedEvent(ipath(1), ipath(2)),
        # moved + deleted -> deleted
        FileMovedEvent(ipath(1), ipath(4)),
        FileDeletedEvent(ipath(4)),
        # moved + moved back -> modified
        FileMovedEvent(ipath(5), ipath(6)),
        FileMovedEvent(ipath(6), ipath(5)),
        # moved + moved -> deleted + created
        # (this is currently not handled as a single moved)
        FileMovedEvent(ipath(7), ipath(8)),
        FileMovedEvent(ipath(8), ipath(9)),
    ]

    res = [
        # created + moved -> created
        FileCreatedEvent(ipath(2)),
        # moved + deleted -> deleted
        FileDeletedEvent(ipath(1)),
        # moved + moved back -> modified
        FileModifiedEvent(ipath(5)),
        # moved + moved -> deleted + created
        # (this is currently not handled as a single moved)
        FileDeletedEvent(ipath(7)),
        FileCreatedEvent(ipath(9)),
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #3
0
def test_gedit_save(sync):

    file_events = [
        FileCreatedEvent(".gedit-save-UR4EC0"),  # save new version to tmp file
        FileModifiedEvent(".gedit-save-UR4EC0"),  # modify tmp file
        FileMovedEvent(ipath(1),
                       ipath(1) + "~"),  # move old version to backup
        FileMovedEvent(".gedit-save-UR4EC0",
                       ipath(1)),  # replace old version with tmp
    ]

    res = [
        FileModifiedEvent(ipath(1)),  # modified file
        FileCreatedEvent(ipath(1) + "~"),  # backup
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #4
0
def test_single_file_events(sync):

    # only a single event for every path -> no consolidation

    file_events = [
        FileModifiedEvent(ipath(1)),
        FileCreatedEvent(ipath(2)),
        FileDeletedEvent(ipath(3)),
        FileMovedEvent(ipath(4), ipath(5)),
    ]

    res = [
        FileModifiedEvent(ipath(1)),
        FileCreatedEvent(ipath(2)),
        FileDeletedEvent(ipath(3)),
        FileMovedEvent(ipath(4), ipath(5)),
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #5
0
def test_single_path_cases(sync):

    file_events = [
        # created + deleted -> None
        FileCreatedEvent(ipath(1)),
        FileDeletedEvent(ipath(1)),
        # deleted + created -> modified
        FileDeletedEvent(ipath(2)),
        FileCreatedEvent(ipath(2)),
        # created + modified -> created
        FileCreatedEvent(ipath(3)),
        FileModifiedEvent(ipath(3)),
    ]

    res = [
        # created + deleted -> None
        # deleted + created -> modified
        FileModifiedEvent(ipath(2)),
        # created + modified -> created
        FileCreatedEvent(ipath(3)),
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #6
0
def test_macos_safe_save(sync):

    file_events = [
        FileMovedEvent(ipath(1),
                       ipath(1) + ".sb-b78ef837-dLht38"),  # move to backup
        FileCreatedEvent(ipath(1)),  # create new version
        FileDeletedEvent(ipath(1) + ".sb-b78ef837-dLht38"),  # delete backup
    ]

    res = [
        FileModifiedEvent(ipath(1)),  # modified file
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Пример #7
0

# Simple cases
file_events_test0 = [
    # created + deleted -> None
    FileCreatedEvent(path(1)),
    FileDeletedEvent(path(1)),
    # deleted + created -> modified
    FileDeletedEvent(path(2)),
    FileCreatedEvent(path(2)),
]

res0 = [
    # created + deleted -> None
    # deleted + created -> modified
    FileModifiedEvent(path(2))
]

# Single file events, keep as is
file_events_test1 = [
    FileModifiedEvent(path(1)),
    FileCreatedEvent(path(2)),
    FileDeletedEvent(path(3)),
    FileMovedEvent(path(4), path(5)),
]

res1 = [
    FileModifiedEvent(path(1)),
    FileCreatedEvent(path(2)),
    FileDeletedEvent(path(3)),
    FileMovedEvent(path(4), path(5)),