mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
parent
325831049b
commit
e725df4747
2 changed files with 28 additions and 2 deletions
|
|
@ -1,5 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from hypothesis import given
|
||||
import hypothesis.strategies as st
|
||||
|
||||
import pytest
|
||||
|
||||
from vdirsyncer.metasync import MetaSyncConflict, metasync
|
||||
|
|
@ -82,3 +85,17 @@ def test_conflict_x_wins(wins):
|
|||
assert a.get_meta('foo') == b.get_meta('foo') == status['foo'] == (
|
||||
'bar' if wins == 'a' else 'baz'
|
||||
)
|
||||
|
||||
|
||||
@given(s=st.text().filter(lambda x: x.strip() == x), key=st.text())
|
||||
def test_trailing_newline(s, key):
|
||||
a = MemoryStorage()
|
||||
b = MemoryStorage()
|
||||
status = {}
|
||||
a.set_meta(key, s + u'\n')
|
||||
b.set_meta(key, s)
|
||||
a.set_meta = b.set_meta = blow_up
|
||||
|
||||
metasync(a, b, status, keys=[key])
|
||||
|
||||
assert status[key] == s
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from . import exceptions, log
|
||||
from .utils.compat import text_type
|
||||
|
||||
logger = log.get(__name__)
|
||||
|
||||
|
|
@ -33,8 +34,8 @@ def metasync(storage_a, storage_b, status, keys, conflict_resolution=None):
|
|||
_b_to_a()
|
||||
|
||||
for key in keys:
|
||||
a = storage_a.get_meta(key)
|
||||
b = storage_b.get_meta(key)
|
||||
a = _normalize_value(storage_a.get_meta(key))
|
||||
b = _normalize_value(storage_b.get_meta(key))
|
||||
s = status.get(key)
|
||||
logger.debug(u'Key: {}'.format(key))
|
||||
logger.debug(u'A: {}'.format(a))
|
||||
|
|
@ -52,3 +53,11 @@ def metasync(storage_a, storage_b, status, keys, conflict_resolution=None):
|
|||
|
||||
for key in set(status) - set(keys):
|
||||
del status[key]
|
||||
|
||||
|
||||
def _normalize_value(value):
|
||||
if value is None:
|
||||
return value
|
||||
else:
|
||||
assert isinstance(value, text_type)
|
||||
return value.strip()
|
||||
|
|
|
|||
Loading…
Reference in a new issue