mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
parent
b3e389cb59
commit
e457586b29
2 changed files with 30 additions and 3 deletions
23
tests/unit/cli/test_config.py
Normal file
23
tests/unit/cli/test_config.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue