Skip to content

Commit e9e16e0

Browse files
committed
Fixed tests
1 parent 2573eb2 commit e9e16e0

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

mergin/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ def apply_pull_changes(self, changes, temp_dir):
457457
# We just apply the diff between our copy and server to both the local copy and its basefile
458458
try:
459459
server_diff = self.fpath(f'{path}-server_diff', temp_dir) # diff between server file and local basefile
460+
# TODO: it could happen that basefile does not exist.
461+
# It was either never created (e.g. when pushing without geodiff)
462+
# or it was deleted by mistake(?) by the user. We should detect that
463+
# when starting pull and download it as well
460464
self.geodiff.create_changeset(basefile, src, server_diff)
461465
self.geodiff.apply_changeset(dest, server_diff)
462466
self.geodiff.apply_changeset(basefile, server_diff)
@@ -1019,6 +1023,11 @@ def pull_project(self, directory, parallel=True):
10191023
if local_version == server_info["version"]:
10201024
return # Project is up to date
10211025

1026+
# we either download a versioned file using diffs (strongly preferred),
1027+
# but if we don't have history with diffs (e.g. uploaded without diffs)
1028+
# then we just download the whole file
1029+
_pulling_file_with_diffs = lambda f: 'diffs' in f and len(f['diffs']) != 0
1030+
10221031
temp_dir = mp.fpath_meta(f'fetch_{local_version}-{server_info["version"]}')
10231032
os.makedirs(temp_dir, exist_ok=True)
10241033
pull_changes = mp.get_pull_changes(server_info["files"])
@@ -1028,7 +1037,7 @@ def pull_project(self, directory, parallel=True):
10281037
fetch_files.append(f)
10291038
# extend fetch files download list with various version of diff files (if needed)
10301039
for f in pull_changes["updated"]:
1031-
if 'diffs' in f:
1040+
if _pulling_file_with_diffs(f):
10321041
for diff in f['diffs']:
10331042
diff_file = copy.deepcopy(f)
10341043
for k, v in f['history'].items():
@@ -1047,7 +1056,7 @@ def pull_project(self, directory, parallel=True):
10471056
with concurrent.futures.ThreadPoolExecutor() as executor:
10481057
futures_map = {}
10491058
for file in fetch_files:
1050-
diff_only = 'diffs' in file
1059+
diff_only = _pulling_file_with_diffs(f)
10511060
future = executor.submit(self._download_file, project_path, file, temp_dir, parallel, diff_only)
10521061
futures_map[future] = file
10531062

@@ -1060,13 +1069,13 @@ def pull_project(self, directory, parallel=True):
10601069
else:
10611070
for file in fetch_files:
10621071
# TODO check it does not fail, do some retry on ClientError
1063-
diff_only = 'diffs' in file
1072+
diff_only = _pulling_file_with_diffs(f)
10641073
self._download_file(project_path, file, temp_dir, parallel, diff_only)
10651074

10661075
# make sure we can update geodiff reference files (aka. basefiles) with diffs or
10671076
# download their full versions so we have them up-to-date for applying changes
10681077
for file in pull_changes['updated']:
1069-
if 'diffs' not in file:
1078+
if not _pulling_file_with_diffs(f):
10701079
continue
10711080
file['version'] = server_info['version']
10721081
basefile = mp.fpath_meta(file['path'])

mergin/test/test_client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,17 @@ def test_ignore_files(mc):
209209

210210
# (diffs size limit, push geodiff enabled, pull geodiff enabled)
211211
diff_test_scenarios = [
212-
(1024, True, True),
213-
(1024*1024, True, True),
214-
(1024, True, False),
215-
(1024, False, True),
216-
(1024, False, False),
212+
(True, True),
213+
(True, False),
214+
(False, True),
215+
(False, False),
217216
]
218217

219218

220-
@pytest.mark.parametrize("diffs_limit, push_geodiff_enabled, pull_geodiff_enabled", diff_test_scenarios)
221-
def test_sync_diff(mc, diffs_limit, push_geodiff_enabled, pull_geodiff_enabled):
219+
@pytest.mark.parametrize("push_geodiff_enabled, pull_geodiff_enabled", diff_test_scenarios)
220+
def test_sync_diff(mc, push_geodiff_enabled, pull_geodiff_enabled):
222221

223-
test_project = f'test_sync_diff_{diffs_limit}_{int(push_geodiff_enabled)}_{int(pull_geodiff_enabled)}'
222+
test_project = f'test_sync_diff_push{int(push_geodiff_enabled)}_pull{int(pull_geodiff_enabled)}'
224223
project = API_USER + '/' + test_project
225224
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir for updates
226225
project_dir_2 = os.path.join(TMP_DIR, test_project + '_2') # concurrent project dir with no changes
@@ -277,7 +276,6 @@ def test_sync_diff(mc, diffs_limit, push_geodiff_enabled, pull_geodiff_enabled):
277276
assert not os.path.exists(mp.fpath_meta('renamed.gpkg'))
278277

279278
# pull project in different directory
280-
os.environ['DIFFS_LIMIT_SIZE'] = str(diffs_limit)
281279
toggle_geodiff(pull_geodiff_enabled)
282280
mp2 = MerginProject(project_dir_2)
283281
mc.pull_project(project_dir_2)

0 commit comments

Comments
 (0)