diff options
Diffstat (limited to 'src/zope/schema/tests')
| -rw-r--r-- | src/zope/schema/tests/test__bootstrapfields.py | 23 | ||||
| -rw-r--r-- | src/zope/schema/tests/test__field.py | 21 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_accessors.py | 35 |
3 files changed, 71 insertions, 8 deletions
diff --git a/src/zope/schema/tests/test__bootstrapfields.py b/src/zope/schema/tests/test__bootstrapfields.py index 027944c..58e7e31 100644 --- a/src/zope/schema/tests/test__bootstrapfields.py +++ b/src/zope/schema/tests/test__bootstrapfields.py @@ -17,8 +17,9 @@ import unittest import unicodedata # pylint:disable=protected-access,inherit-non-class,blacklisted-name +# pylint:disable=attribute-defined-outside-init -class EqualityTestsMixin(object): +class InterfaceConformanceTestsMixin(object): def _getTargetClass(self): raise NotImplementedError @@ -54,6 +55,26 @@ class EqualityTestsMixin(object): verifyObject(iface, instance) return verifyObject + def test_iface_is_first_in_sro(self): + from zope.interface import implementedBy + implemented = implementedBy(self._getTargetClass()) + __traceback_info__ = implemented.__sro__ + self.assertIs(implemented, implemented.__sro__[0]) + self.assertIs(self._getTargetInterface(), implemented.__sro__[1]) + + def test_implements_consistent__sro__(self): + from zope.interface import ro + from zope.interface import implementedBy + __traceback_info__ = implementedBy(self._getTargetClass()).__sro__ + self.assertTrue(ro.is_consistent(implementedBy(self._getTargetClass()))) + + def test_iface_consistent_ro(self): + from zope.interface import ro + __traceback_info__ = self._getTargetInterface().__iro__ + self.assertTrue(ro.is_consistent(self._getTargetInterface())) + +class EqualityTestsMixin(InterfaceConformanceTestsMixin): + def test_is_hashable(self): field = self._makeOne() hash(field) # doesn't raise diff --git a/src/zope/schema/tests/test__field.py b/src/zope/schema/tests/test__field.py index 2e78b8e..13600d5 100644 --- a/src/zope/schema/tests/test__field.py +++ b/src/zope/schema/tests/test__field.py @@ -711,7 +711,7 @@ class ChoiceTests(EqualityTestsMixin, from zope.schema.vocabulary import setVocabularyRegistry class Reg(object): - def get(*args): + def get(self, *args): raise LookupError setVocabularyRegistry(Reg()) @@ -1369,7 +1369,7 @@ class SequenceTests(WrongTypeTestsMixin, from zope.schema._field import abc class MutableSequence(abc.MutableSequence): - def insert(self, item, ix): + def insert(self, index, value): raise AssertionError("not implemented") def __getitem__(self, name): raise AssertionError("not implemented") @@ -1754,6 +1754,21 @@ class NativeStringLineTests(EqualityTestsMixin, self.assertEqual(field.fromUnicode(u'DEADBEEF'), 'DEADBEEF') +class StrippedNativeStringLineTests(NativeStringLineTests): + + def _getTargetClass(self): + from zope.schema._field import _StrippedNativeStringLine + return _StrippedNativeStringLine + + def test_strips(self): + field = self._makeOne() + self.assertEqual(field.fromBytes(b' '), '') + self.assertEqual(field.fromUnicode(u' '), '') + + def test_iface_is_first_in_sro(self): + self.skipTest("Not applicable; we inherit implementation but have no interface") + + def _makeSampleVocabulary(): from zope.interface import implementer from zope.schema.interfaces import IVocabulary @@ -1784,7 +1799,7 @@ def _makeDummyRegistry(v): VocabularyRegistry.__init__(self) self._vocabulary = vocabulary - def get(self, object, name): + def get(self, context, name): return self._vocabulary return DummyRegistry(v) diff --git a/src/zope/schema/tests/test_accessors.py b/src/zope/schema/tests/test_accessors.py index 1512766..dbd3a48 100644 --- a/src/zope/schema/tests/test_accessors.py +++ b/src/zope/schema/tests/test_accessors.py @@ -15,6 +15,7 @@ """ import unittest +# pylint:disable=inherit-non-class class FieldReadAccessorTests(unittest.TestCase): @@ -59,15 +60,41 @@ class FieldReadAccessorTests(unittest.TestCase): def test___provides___w_field_w_provides(self): from zope.interface import implementedBy from zope.interface import providedBy + from zope.interface.interfaces import IAttribute + from zope.interface.interfaces import IMethod from zope.schema import Text + + # When wrapping a field that provides stuff, + # we provide the same stuff, with the addition of + # IMethod at the correct spot in the IRO (just before + # IAttribute). field = Text() field_provides = list(providedBy(field)) wrapped = self._makeOne(field) wrapped_provides = list(providedBy(wrapped)) - self.assertEqual(wrapped_provides[:len(field_provides)], - list(providedBy(field))) + + index_of_attribute = field_provides.index(IAttribute) + expected = list(field_provides) + expected.insert(index_of_attribute, IMethod) + self.assertEqual(expected, wrapped_provides) for iface in list(implementedBy(self._getTargetClass())): - self.assertTrue(iface in wrapped_provides) + self.assertIn(iface, wrapped_provides) + + def test___provides___w_field_w_provides_strict(self): + from zope.interface import ro + attr = 'STRICT_IRO' + try: + getattr(ro.C3, attr) + except AttributeError: + # https://github.com/zopefoundation/zope.interface/issues/194 + # zope.interface 5.0.0 used this incorrect spelling. + attr = 'STRICT_RO' + getattr(ro.C3, attr) + setattr(ro.C3, attr, True) + try: + self.test___provides___w_field_w_provides() + finally: + setattr(ro.C3, attr, getattr(ro.C3, 'ORIG_' + attr)) def test_getSignatureString(self): wrapped = self._makeOne() @@ -180,7 +207,7 @@ class FieldReadAccessorTests(unittest.TestCase): pass writer = Writer() - writer.__name__ = 'setMe' + writer.__name__ = 'setMe' # pylint:disable=attribute-defined-outside-init getter.writer = writer class Foo(object): |
