From 2beb85415732cc9f8c7c600aeec743970fb924ee Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 25 Apr 2016 21:48:51 +0200 Subject: [PATCH] Factor out duplicate UID strategies --- tests/__init__.py | 8 ++++++++ tests/cli/test_repair.py | 8 ++------ tests/test_sync.py | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 489096d..fe6d412 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -74,3 +74,11 @@ printable_characters_strategy = st.text( 'Cc', 'Cs' )) ) + +uid_strategy = st.text( + st.characters(blacklist_categories=( + 'Zs', 'Zl', 'Zp', + 'Cc', 'Cs' + )), + min_size=1 +).filter(lambda x: x.strip() == x) diff --git a/tests/cli/test_repair.py b/tests/cli/test_repair.py index 715049a..ddd740e 100644 --- a/tests/cli/test_repair.py +++ b/tests/cli/test_repair.py @@ -3,18 +3,14 @@ from textwrap import dedent from hypothesis import given, settings -import hypothesis.strategies as st + +from tests import uid_strategy from vdirsyncer.repair import repair_storage from vdirsyncer.storage.memory import MemoryStorage from vdirsyncer.utils import href_safe from vdirsyncer.utils.vobject import Item -uid_strategy = st.text(st.characters(blacklist_categories=( - 'Zs', 'Zl', 'Zp', - 'Cc', 'Cs' -))) - @given(uid=uid_strategy) @settings(perform_health_check=False) # Using the random module for UIDs diff --git a/tests/test_sync.py b/tests/test_sync.py index e7fa128..f2e82f9 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -14,7 +14,7 @@ from vdirsyncer.storage.memory import MemoryStorage from vdirsyncer.sync import BothReadOnly, IdentConflict, StorageEmpty, \ SyncConflict, sync -from . import assert_item_equals, blow_up +from . import assert_item_equals, blow_up, uid_strategy def empty_storage(x): @@ -409,7 +409,7 @@ class SyncMachine(RuleBasedStateMachine): return {} @rule(target=Storage, storage=Storage, - uid=st.text(min_size=1), + uid=uid_strategy, etag=st.text()) def upload(self, storage, uid, etag): item = Item(u'UID:{}'.format(uid))