Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
    def test_msoffice_created(self):

        file_events = [
            FileCreatedEvent(ipath(1)),
            FileDeletedEvent(ipath(1)),
            FileCreatedEvent(ipath(1)),
            FileCreatedEvent("~$" + ipath(1)),
        ]

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

        cleaned_events = self.sync._clean_local_events(file_events)
        self.assertEqual(set(cleaned_events), set(res))
Esempio n. 4
0
def test_msoffice_created(sync):

    file_events = [
        FileCreatedEvent(ipath(1)),
        FileDeletedEvent(ipath(1)),
        FileCreatedEvent(ipath(1)),
        FileCreatedEvent("~$" + ipath(1)),
    ]

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

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
def test_type_changes(sync):

    file_events = [
        # keep as is
        FileDeletedEvent(ipath(1)),
        DirCreatedEvent(ipath(1)),
        # keep as is
        DirDeletedEvent(ipath(2)),
        FileCreatedEvent(ipath(2)),
    ]

    res = [
        # keep as is
        FileDeletedEvent(ipath(1)),
        DirCreatedEvent(ipath(1)),
        # keep as is
        DirDeletedEvent(ipath(2)),
        FileCreatedEvent(ipath(2)),
    ]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)
Esempio n. 8
0
    def test_type_changes(self):

        file_events = [
            # keep as is
            FileDeletedEvent(ipath(1)),
            DirCreatedEvent(ipath(1)),
            # keep as is
            DirDeletedEvent(ipath(2)),
            FileCreatedEvent(ipath(2)),
        ]

        res = [
            # keep as is
            FileDeletedEvent(ipath(1)),
            DirCreatedEvent(ipath(1)),
            # keep as is
            DirDeletedEvent(ipath(2)),
            FileCreatedEvent(ipath(2)),
        ]

        cleaned_events = self.sync._clean_local_events(file_events)
        self.assertEqual(set(cleaned_events), set(res))
Esempio n. 9
0
    def test_local_deletion_during_upload(self):

        fake_created_event = FileCreatedEvent(self.test_folder_local +
                                              "/file.txt")
        self.m.monitor.fs_event_handler.local_file_event_queue.put(
            fake_created_event)

        self.wait_for_idle()

        self.assert_synced(self.test_folder_local, self.test_folder_dbx)
        self.assert_count(self.test_folder_dbx, 0)

        # check for fatal errors
        self.assertFalse(self.m.fatal_errors)
Esempio n. 10
0
def test_local_deletion_during_upload(m):
    """Tests the case where a local item is deleted during the upload."""

    # we mimic a deletion during upload by queueing a fake FileCreatedEvent
    fake_created_event = FileCreatedEvent(m.test_folder_local + "/file.txt")
    m.monitor.fs_event_handler.local_file_event_queue.put(fake_created_event)

    wait_for_idle(m)

    assert_synced(m)
    assert_child_count(m, "/sync_tests", 0)

    # check for fatal errors
    assert not m.fatal_errors
Esempio n. 11
0
def test_performance(sync):

    # 10,000 nested deleted events (5,000 folders, 5,000 files)
    file_events = [DirDeletedEvent(n * ipath(1)) for n in range(1, 5001)]
    file_events += [
        FileDeletedEvent(n * ipath(1) + ".txt") for n in range(1, 5001)
    ]

    # 10,000 nested moved events (5,000 folders, 5,000 files)
    file_events += [
        DirMovedEvent(n * ipath(2), n * ipath(3)) for n in range(1, 5001)
    ]
    file_events += [
        FileMovedEvent(n * ipath(2) + ".txt",
                       n * ipath(3) + ".txt") for n in range(1, 5001)
    ]

    # 4,995 unrelated created events
    file_events += [FileCreatedEvent(ipath(n)) for n in range(5, 5001)]

    res = [
        DirDeletedEvent(ipath(1)),
        DirMovedEvent(ipath(2), ipath(3)),
        FileDeletedEvent(ipath(1) + ".txt"),
        FileMovedEvent(ipath(2) + ".txt",
                       ipath(3) + ".txt"),
    ]
    res += [FileCreatedEvent(ipath(n)) for n in range(5, 5001)]

    cleaned_events = sync._clean_local_events(file_events)
    assert set(cleaned_events) == set(res)

    n_loops = 4
    duration = timeit.timeit(lambda: sync._clean_local_events(file_events),
                             number=n_loops)

    assert duration < 10 * n_loops
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
0
(c) Sam Schott; This work is licensed under a Creative Commons
Attribution-NonCommercial-NoDerivs 2.0 UK: England & Wales License.

"""
from maestral.sync import (FileCreatedEvent, FileDeletedEvent,
                           FileModifiedEvent, FileMovedEvent, UpDownSync)


def path(i):
    return f'test_{i}.txt'


# 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)),