From 7bbc8b87da0a2708843f2510d20ace4c53e15c8f Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 6 Jul 2014 20:28:48 +0200 Subject: [PATCH] Some smaller changes to testsuite --- tests/storage/__init__.py | 55 ++++++++++++++++++-------------- tests/storage/test_memory.py | 13 ++------ tests/storage/test_singlefile.py | 10 ++---- vdirsyncer/utils/vobject.py | 1 - 4 files changed, 35 insertions(+), 44 deletions(-) diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index 55cda65..9c2df6a 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -17,7 +17,7 @@ from vdirsyncer.utils.compat import iteritems, text_type from .. import SIMPLE_TEMPLATE, assert_item_equals -class StorageTests(object): +class BaseStorageTests(object): item_template = SIMPLE_TEMPLATE def _create_bogus_item(self, item_template=None): @@ -111,6 +111,34 @@ class StorageTests(object): s.upload(self._create_bogus_item()) assert list(s.list()) + def test_has(self): + s = self._get_storage() + assert not s.has('asd') + href, etag = s.upload(self._create_bogus_item()) + assert s.has(href) + assert not s.has('asd') + + def test_update_others_stay_the_same(self): + s = self._get_storage() + info = dict([ + s.upload(self._create_bogus_item()), + s.upload(self._create_bogus_item()), + s.upload(self._create_bogus_item()), + s.upload(self._create_bogus_item()) + ]) + + assert dict( + (href, etag) for href, item, etag + in s.get_multi(href for href, etag in iteritems(info)) + ) == info + + def test_repr(self): + s = self._get_storage() + assert self.storage_class.__name__ in repr(s) + + +class SupportsCollections(object): + def test_discover(self): collections = set() @@ -159,27 +187,6 @@ class StorageTests(object): # fileextension to guess the collection type. assert 'test2' in s.collection - def test_has(self): - s = self._get_storage() - assert not s.has('asd') - href, etag = s.upload(self._create_bogus_item()) - assert s.has(href) - assert not s.has('asd') - def test_update_others_stay_the_same(self): - s = self._get_storage() - info = dict([ - s.upload(self._create_bogus_item()), - s.upload(self._create_bogus_item()), - s.upload(self._create_bogus_item()), - s.upload(self._create_bogus_item()) - ]) - - assert dict( - (href, etag) for href, item, etag - in s.get_multi(href for href, etag in iteritems(info)) - ) == info - - def test_repr(self): - s = self._get_storage() - assert self.storage_class.__name__ in repr(s) +class StorageTests(BaseStorageTests, SupportsCollections): + pass diff --git a/tests/storage/test_memory.py b/tests/storage/test_memory.py index 19cab24..d9d50e1 100644 --- a/tests/storage/test_memory.py +++ b/tests/storage/test_memory.py @@ -10,21 +10,12 @@ from vdirsyncer.storage.memory import MemoryStorage -from . import StorageTests +from . import BaseStorageTests -class TestMemoryStorage(StorageTests): +class TestMemoryStorage(BaseStorageTests): storage_class = MemoryStorage def get_storage_args(self, **kwargs): return kwargs - - def test_discover(self): - '''This test doesn't make any sense here.''' - - def test_discover_collection_arg(self): - '''This test doesn't make any sense here.''' - - def test_collection_arg(self): - '''This test doesn't make any sense here.''' diff --git a/tests/storage/test_singlefile.py b/tests/storage/test_singlefile.py index 47769f9..3a6d648 100644 --- a/tests/storage/test_singlefile.py +++ b/tests/storage/test_singlefile.py @@ -11,11 +11,11 @@ import pytest from vdirsyncer.storage.singlefile import SingleFileStorage -from . import StorageTests +from . import BaseStorageTests from .. import EVENT_TEMPLATE, assert_item_equals -class TestSingleFileStorage(StorageTests): +class TestSingleFileStorage(BaseStorageTests): storage_class = SingleFileStorage item_template = EVENT_TEMPLATE @@ -27,12 +27,6 @@ class TestSingleFileStorage(StorageTests): def get_storage_args(self, **kwargs): return dict(path=self._path) - def test_discover(self): - '''This test doesn't make any sense here.''' - - def test_discover_collection_arg(self): - '''This test doesn't make any sense here.''' - def test_collection_arg(self, tmpdir): with pytest.raises(ValueError): self.storage_class(str(tmpdir.join('foo.ics')), collection='ha') diff --git a/vdirsyncer/utils/vobject.py b/vdirsyncer/utils/vobject.py index 8b88077..fd63657 100644 --- a/vdirsyncer/utils/vobject.py +++ b/vdirsyncer/utils/vobject.py @@ -130,7 +130,6 @@ def split_collection(text, inline=(u'VTIMEZONE',), '''Emits items in the order they occur in the text.''' assert isinstance(text, text_type) collections = icalendar.cal.Component.from_ical(text, multiple=True) - assert collections collection_name = None for collection in collections: