Skip to content

Commit 55d9e5a

Browse files
committed
Fix test test_mergin_project
1 parent ae3e55c commit 55d9e5a

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

mergin/test/test_mergin_project.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import pytest
66
from mergin.merginproject import MerginProject
77
from mergin.common import DeltaChangeType, PullActionType, ClientError
8-
from mergin.models import ProjectDeltaItem, ProjectDeltaItemDiff, ProjectDeltaItemDiff, PullAction
8+
from mergin.models import ProjectDeltaItem, ProjectDeltaItemDiff
9+
from mergin.client_pull import PullAction
910
from mergin.utils import edit_conflict_file_name
1011

1112
TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_data")
@@ -171,40 +172,47 @@ def test_get_pull_delta():
171172
assert len(diff_item.diffs) == 2
172173

173174

174-
def test_get_local_delta_mocked():
175+
def test_get_local_delta():
175176
"""Test get_local_delta with mocked compare_file_sets."""
176177
with tempfile.TemporaryDirectory() as tmp_dir:
177178
test_project = "delta_test_project"
178179
project_dir = os.path.join(tmp_dir, test_project)
179180
os.makedirs(project_dir, exist_ok=True)
180-
shutil.copyfile(os.path.join(TEST_DATA_DIR, "inseAted_1_A.gpkg"), os.path.join(project_dir, "base.
181+
shutil.copyfile(os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"), os.path.join(project_dir, "base.gpkg"))
181182
mp = MerginProject(project_dir)
182-
shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, ".mergin", "base.gpkg"))gp )
183+
shutil.copyfile(os.path.join(TEST_DATA_DIR, "base.gpkg"), os.path.join(project_dir, ".mergin", "base.gpkg"))
184+
185+
# Mock compare_file_sets return value
186+
mock_changes = {
187+
"added": [{"path": "new.txt", "size": 10, "checksum": "c1"}],
188+
"removed": [{"path": "deleted.txt", "size": 20, "checksum": "c2"}],
189+
"updated": [
190+
{"path": "updated.txt", "size": 30, "checksum": "c3"},
191+
{"path": "base.gpkg", "size": 40, "checksum": "c4"},
192+
],
193+
}
194+
mp.compare_file_sets = lambda local, server: mock_changes
183195

184-
# Mock compare_file_sets return ue
185-
mock_chang "added": [{"path": "new.txt", "size": 10, "checksum": " "removed": [{"path": "deleted.txt", "size": 20, "checksum": " "updat {"path": "updated.txt", "size": 30, "checksum": {"path": "base.gpkg", "size": 40, "checksum": ], }
186-
mp.compare_file_sets = lambda local, server: mock_c
187196
# Mock files() to return origin info for version lookup
188197
mp.files = lambda: []
189198

190-
mp.inspect_files = lambda: [] # Dummy returnf
191-
w
199+
mp.inspect_files = lambda: [] # Dummy return
192200

193-
delta_items = mp.get_local_delta(projec r)
194-
assert len(delta_items) 4
201+
delta_items = mp.get_local_delta(project_dir)
202+
assert len(delta_items) == 4
195203

196-
# Verify ms
197-
create_item = next(i for i in delta_items if i.path == "new ")
198-
assert create_item.change == DeltaChangeType.C E
204+
# Verify items
205+
create_item = next(i for i in delta_items if i.path == "new.txt")
206+
assert create_item.change == DeltaChangeType.CREATE
199207

200-
delete_item = next(i for i in delta_items if i.path == "deleted ")
201-
assert delete_item.change == DeltaChangeType.D E
208+
delete_item = next(i for i in delta_items if i.path == "deleted.txt")
209+
assert delete_item.change == DeltaChangeType.DELETE
202210

203-
update_item = next(i for i in delta_items if i.path == "updated ")
204-
assert update_item.change == DeltaChangeType.U E
211+
update_item = next(i for i in delta_items if i.path == "updated.txt")
212+
assert update_item.change == DeltaChangeType.UPDATE
205213

206-
update_diff_item = next(i for i in delta_items if i.path == "base. ")
207-
assert update_diff_item.change == DeltaChangeType.UPDA
214+
update_diff_item = next(i for i in delta_items if i.path == "base.gpkg")
215+
assert update_diff_item.change == DeltaChangeType.UPDATE_DIFF
208216

209217

210218
def test_apply_pull_actions_apply_diff():
@@ -445,4 +453,3 @@ def username(self):
445453
assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-server.diff"))
446454
assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-base.diff"))
447455
assert mp.geodiff.has_changes(os.path.join(tmp_dir, "live-conflict.diff"))
448-
E_DIFF

0 commit comments

Comments
 (0)