From e457586b2965ab93f46a89aae52d4cd4ce132c68 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 26 Feb 2017 23:21:22 +0100 Subject: [PATCH] Fix bug in custom conflict_resolution Fix #563 --- tests/unit/cli/test_config.py | 23 +++++++++++++++++++++++ vdirsyncer/cli/config.py | 10 +++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/unit/cli/test_config.py diff --git a/tests/unit/cli/test_config.py b/tests/unit/cli/test_config.py new file mode 100644 index 0000000..53e46ca --- /dev/null +++ b/tests/unit/cli/test_config.py @@ -0,0 +1,23 @@ +import os + +from vdirsyncer.cli.config import _resolve_conflict_via_command +from vdirsyncer.utils.vobject import Item + +def test_conflict_resolution_command(): + def check_call(command): + command, a_tmp, b_tmp = command + assert command == os.path.expanduser('~/command') + with open(a_tmp) as f: + assert f.read() == a.raw + with open(b_tmp) as f: + assert f.read() == b.raw + + with open(b_tmp, 'w') as f: + f.write(a.raw) + + a = Item('UID:AAAAAAA') + b = Item('UID:BBBBBBB') + assert _resolve_conflict_via_command( + a, b, ['~/command'], 'a', 'b', + _check_call=check_call + ).raw == a.raw diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index 72f9443..b5ba920 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -306,10 +306,13 @@ class CollectionConfig(object): load_config = Config.from_filename_or_environment -def _resolve_conflict_via_command(a, b, command, a_name, b_name): +def _resolve_conflict_via_command(a, b, command, a_name, b_name, + _check_call=None): import tempfile import shutil - import subprocess + + if _check_call is None: + from subprocess import check_call as _check_call from ..utils.vobject import Item @@ -323,7 +326,8 @@ def _resolve_conflict_via_command(a, b, command, a_name, b_name): with open(b_tmp, 'w') as f: f.write(b.raw) - subprocess.check_call(command + [a_tmp, b_tmp]) + command[0] = expand_path(command[0]) + _check_call(command + [a_tmp, b_tmp]) with open(a_tmp) as f: new_a = f.read()