def test_sync_to_device_unmatched(mtp, tmpdir, tmpfiles, tmpdir_device_remove, unmatched_action): """ :unmatched_action == SYNCHRONIZE Test if Sync.sync() really sync files from computer to device and sync back to computer file(s) that are only on the device. :unmatched_action == REMOVE Test if Sync.sync() really sync files from computer to device and remove files that are only on the device. """ tmpfiles_names = set([os.path.basename(tmpf) for tmpf in tmpfiles]) # # create parent directory and copy a new file to the device # destination directory; this copied file will be the unmatched file, i.e. # a file that is present only in the destination directory unmatched = 'test.test' dst_pth = os.path.join(mtp[1], DEVICE_DESTINATION_TEST_DIR) gvfs.mkdir(dst_pth) dst_file = os.path.join(dst_pth, unmatched) gvfs.cp(src=COMPUTER_SOURCE_FILE, dst=dst_file) sync = Sync(mtp, tmpdir, DEVICE_DESTINATION_TEST_DIR, unmatched=unmatched_action) # NOQA sync.set_source_abs() sync.set_destination_abs() sync.sync() # # exclude the unmatched file from synchronized files as it was already in # the destination directory synced_files = [syncf for syncf in os.listdir(sync.destination_abs) if syncf != unmatched] assert synced_files for synced_file in synced_files: synced_file = os.path.basename(synced_file) assert synced_file in tmpfiles_names # # test if unmatched_action works as expected if unmatched_action == SYNCHRONIZE: # unmatched file should be synchronized to the source directory assert unmatched in os.listdir(sync.source_abs) elif unmatched_action == REMOVE: # unmatched file should be removed from the destination directory assert unmatched not in os.listdir(sync.destination_abs)
def test_sync_to_computer(mtp, tmpdir, tmpfiles, tmpdir_device_remove): """ Test if Sync.sync() really sync files from device to computer """ tmpfiles_names = set([os.path.basename(tmpf) for tmpf in tmpfiles]) # # first move tmpfiles to the device device_source = os.path.join(mtp[1], DEVICE_DESTINATION_TEST_DIR) if not os.path.exists(device_source): gvfs.mkdir(device_source) for tmpfile in tmpfiles: gvfs.mv(tmpfile, os.path.join(mtp[1], device_source)) moved_files = os.listdir(device_source) assert moved_files for moved_file in moved_files: moved_file = os.path.basename(moved_file) assert moved_file in tmpfiles_names # # then sync them back to computer sync = Sync(mtp, device_source, tmpdir) sync.set_source_abs() sync.set_destination_abs() sync.sync() synced_files = os.listdir(sync.destination_abs) assert synced_files for synced_file in synced_files: synced_file = os.path.basename(synced_file) assert synced_file in tmpfiles_names
def test_mkdir(self): path = "/dst/path" mkdir(path) self.mock_run_bash_cmd.assert_called_with(["gvfs-mkdir", "-p", path])