diff options
| author | Jason Madden <jamadden@gmail.com> | 2017-07-10 07:37:16 -0500 |
|---|---|---|
| committer | Jason Madden <jamadden@gmail.com> | 2017-07-10 07:37:16 -0500 |
| commit | fa586c64b77b7afab17104b60f5a955cc94a5542 (patch) | |
| tree | 5c9afec5c6b349ed4a1700425ccc97d318f6d55b | |
| parent | d38c34dc90998e102e6a8569b3c67ecfdcdb7db7 (diff) | |
| download | zope-schema-py36.tar.gz | |
100% coverage.py36
| -rw-r--r-- | .coveragerc | 1 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/zope/schema/_bootstrapinterfaces.py | 2 | ||||
| -rw-r--r-- | src/zope/schema/tests/states.py | 11 | ||||
| -rw-r--r-- | src/zope/schema/tests/test__bootstrapfields.py | 37 | ||||
| -rw-r--r-- | src/zope/schema/tests/test__bootstrapinterfaces.py | 10 | ||||
| -rw-r--r-- | src/zope/schema/tests/test__field.py | 49 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_accessors.py | 12 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_equality.py | 6 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_fieldproperty.py | 10 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_interfaces.py | 7 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_schema.py | 13 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_states.py | 6 | ||||
| -rw-r--r-- | src/zope/schema/tests/test_vocabulary.py | 25 |
14 files changed, 24 insertions, 166 deletions
diff --git a/.coveragerc b/.coveragerc index e57a659..953ece6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,3 +6,4 @@ exclude_lines = pragma: no cover if __name__ == '__main__': raise NotImplementedError + raise AssertionError @@ -10,6 +10,7 @@ parts *.egg-info .tox .coverage +htmlcov/ nosetests.xml coverage.xml devel diff --git a/src/zope/schema/_bootstrapinterfaces.py b/src/zope/schema/_bootstrapinterfaces.py index da423fb..9bc761b 100644 --- a/src/zope/schema/_bootstrapinterfaces.py +++ b/src/zope/schema/_bootstrapinterfaces.py @@ -114,7 +114,7 @@ class IContextAwareDefaultFactory(zope.interface.Interface): class NO_VALUE(object): - def __repr__(self): + def __repr__(self): # pragma: no cover return '<NO_VALUE>' NO_VALUE = NO_VALUE() diff --git a/src/zope/schema/tests/states.py b/src/zope/schema/tests/states.py index e3a6e8a..3507fb2 100644 --- a/src/zope/schema/tests/states.py +++ b/src/zope/schema/tests/states.py @@ -117,14 +117,3 @@ class StateVocabulary(object): def getTerm(self, value): return _states[value] - - -class StateSelectionField(Choice): - - vocabulary = StateVocabulary() - - def __init__(self, **kw): - super(StateSelectionField, self).__init__( - vocabulary=StateSelectionField.vocabulary, - **kw) - self.vocabularyName = "states" diff --git a/src/zope/schema/tests/test__bootstrapfields.py b/src/zope/schema/tests/test__bootstrapfields.py index 42addbe..b709ee2 100644 --- a/src/zope/schema/tests/test__bootstrapfields.py +++ b/src/zope/schema/tests/test__bootstrapfields.py @@ -267,10 +267,8 @@ class FieldTests(unittest.TestCase): def test_validate_missing_not_required(self): missing = object() - def _fail(value): - return False field = self._makeOne( - required=False, missing_value=missing, constraint=_fail, + required=False, missing_value=missing, constraint=lambda x: False, ) self.assertEqual(field.validate(missing), None) # doesn't raise @@ -278,28 +276,22 @@ class FieldTests(unittest.TestCase): from zope.schema._bootstrapinterfaces import RequiredMissing missing = object() - def _fail(value): - return False field = self._makeOne( - required=True, missing_value=missing, constraint=_fail, + required=True, missing_value=missing, constraint=lambda x: False, ) self.assertRaises(RequiredMissing, field.validate, missing) def test_validate_wrong_type(self): from zope.schema._bootstrapinterfaces import WrongType - def _fail(value): - return False - field = self._makeOne(required=True, constraint=_fail) + field = self._makeOne(required=True, constraint=lambda x: False) field._type = str self.assertRaises(WrongType, field.validate, 1) def test_validate_constraint_fails(self): from zope.schema._bootstrapinterfaces import ConstraintNotSatisfied - def _fail(value): - return False - field = self._makeOne(required=True, constraint=_fail) + field = self._makeOne(required=True, constraint=lambda x: False) field._type = int self.assertRaises(ConstraintNotSatisfied, field.validate, 1) @@ -401,7 +393,7 @@ class ContainerTests(unittest.TestCase): class Dummy(object): def __contains__(self, item): - return False + raise AssertionError("Not called") cont._validate(Dummy()) # doesn't raise def test__validate_not_collection_but_iterable(self): @@ -432,7 +424,7 @@ class IterableTests(ContainerTests): class Dummy(object): def __contains__(self, item): - return False + raise AssertionError("Not called") self.assertRaises(NotAnIterator, itr._validate, Dummy()) @@ -803,20 +795,3 @@ class DummyInst(object): def validate(self, value): if self._exc is not None: raise self._exc() - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(ValidatedPropertyTests), - unittest.makeSuite(DefaultPropertyTests), - unittest.makeSuite(FieldTests), - unittest.makeSuite(ContainerTests), - unittest.makeSuite(IterableTests), - unittest.makeSuite(OrderableTests), - unittest.makeSuite(MinMaxLenTests), - unittest.makeSuite(TextTests), - unittest.makeSuite(TextLineTests), - unittest.makeSuite(PasswordTests), - unittest.makeSuite(BoolTests), - unittest.makeSuite(IntTests), - )) diff --git a/src/zope/schema/tests/test__bootstrapinterfaces.py b/src/zope/schema/tests/test__bootstrapinterfaces.py index 7df3c4f..6d11334 100644 --- a/src/zope/schema/tests/test__bootstrapinterfaces.py +++ b/src/zope/schema/tests/test__bootstrapinterfaces.py @@ -16,9 +16,7 @@ import unittest def _skip_under_py3(testcase): from zope.schema._compat import PY3 - if not PY3: - return testcase - + return unittest.skipIf(PY3, "Not under Python 3")(testcase) class ValidationErrorTests(unittest.TestCase): @@ -60,9 +58,3 @@ class ValidationErrorTests(unittest.TestCase): self.assertEqual(left == right, False) self.assertEqual(left == left, True) self.assertEqual(right == right, True) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(ValidationErrorTests), - )) diff --git a/src/zope/schema/tests/test__field.py b/src/zope/schema/tests/test__field.py index 211f7da..6b8384e 100644 --- a/src/zope/schema/tests/test__field.py +++ b/src/zope/schema/tests/test__field.py @@ -933,7 +933,7 @@ class ChoiceTests(unittest.TestCase): @implementer(IContextSourceBinder) class SampleContextSourceBinder(object): def __call__(self, context): - pass + raise AssertionError("This is not called") choice = self._makeOne(source=SampleContextSourceBinder()) self.assertRaises(TypeError, choice.validate, 1) @@ -1675,14 +1675,9 @@ class ObjectTests(unittest.TestCase): def _getErrors(self, f, *args, **kw): from zope.schema.interfaces import WrongContainedType - try: + with self.assertRaises(WrongContainedType) as e: f(*args, **kw) - except WrongContainedType as e: - try: - return e.args[0] - except: - return [] - self.fail('Expected WrongContainedType Error') + return e.exception.args[0] def _makeCycles(self): from zope.interface import Interface @@ -2063,21 +2058,16 @@ def _makeSampleVocabulary(): class SampleVocabulary(object): def __iter__(self): - return iter([self.getTerm(x) for x in range(0, 10)]) + raise AssertionError("Not implemented") def __contains__(self, value): return 0 <= value < 10 - def __len__(self): + def __len__(self): # pragma: no cover return 10 def getTerm(self, value): - if value in self: - t = SampleTerm() - t.value = value - t.double = 2 * value - return t - raise LookupError("no such value: %r" % value) + raise AssertionError("Not implemented") return SampleVocabulary() @@ -2092,30 +2082,3 @@ def _makeDummyRegistry(v): def get(self, object, name): return self._vocabulary return DummyRegistry(v) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(BytesTests), - unittest.makeSuite(ASCIITests), - unittest.makeSuite(BytesLineTests), - unittest.makeSuite(ASCIILineTests), - unittest.makeSuite(FloatTests), - unittest.makeSuite(DecimalTests), - unittest.makeSuite(DatetimeTests), - unittest.makeSuite(DateTests), - unittest.makeSuite(TimedeltaTests), - unittest.makeSuite(TimeTests), - unittest.makeSuite(ChoiceTests), - unittest.makeSuite(InterfaceFieldTests), - unittest.makeSuite(AbstractCollectionTests), - unittest.makeSuite(TupleTests), - unittest.makeSuite(ListTests), - unittest.makeSuite(SetTests), - unittest.makeSuite(FrozenSetTests), - unittest.makeSuite(ObjectTests), - unittest.makeSuite(DictTests), - unittest.makeSuite(URITests), - unittest.makeSuite(IdTests), - unittest.makeSuite(DottedNameTests), - )) diff --git a/src/zope/schema/tests/test_accessors.py b/src/zope/schema/tests/test_accessors.py index baac70a..1512766 100644 --- a/src/zope/schema/tests/test_accessors.py +++ b/src/zope/schema/tests/test_accessors.py @@ -151,7 +151,7 @@ class FieldReadAccessorTests(unittest.TestCase): class Foo(object): def getter(self): - return '123' + raise AssertionError("Not called") self.assertRaises(TypeError, getter.set, Foo(), '456') def test_set_no_writer(self): @@ -163,7 +163,7 @@ class FieldReadAccessorTests(unittest.TestCase): class Foo(object): def getter(self): - return '123' + raise AssertionError("Not called") self.assertRaises(AttributeError, getter.set, Foo(), '456') @@ -305,11 +305,3 @@ class Test_accessors(unittest.TestCase): self.assertEqual(info['optional'], ()) self.assertEqual(info['varargs'], None) self.assertEqual(info['kwargs'], None) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(FieldReadAccessorTests), - unittest.makeSuite(FieldWriteAccessorTests), - unittest.makeSuite(Test_accessors), - )) diff --git a/src/zope/schema/tests/test_equality.py b/src/zope/schema/tests/test_equality.py index 422d9d8..f8f0dd5 100644 --- a/src/zope/schema/tests/test_equality.py +++ b/src/zope/schema/tests/test_equality.py @@ -28,9 +28,3 @@ class FieldEqualityTests(unittest.TestCase): for cls in (Int, Text): self.assertEqual(_makeOne(cls), _makeOne(cls)) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(FieldEqualityTests), - )) diff --git a/src/zope/schema/tests/test_fieldproperty.py b/src/zope/schema/tests/test_fieldproperty.py index 513d3f3..f319f55 100644 --- a/src/zope/schema/tests/test_fieldproperty.py +++ b/src/zope/schema/tests/test_fieldproperty.py @@ -517,7 +517,7 @@ class FieldPropertyStoredThroughFieldTests(_Base, _Integration): return default def set(self, inst, value): - if self.readonly: + if self.readonly: # pragma: no cover raise ValueError setattr(inst, 'faux', value) @@ -658,11 +658,3 @@ class CreateFieldPropertiesTests(unittest.TestCase): self.assertFalse(hasattr(Dummy, 'date')) self.assertFalse(hasattr(Dummy, 'code')) self.assertTrue(hasattr(Dummy, 'title')) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(FieldPropertyTests), - unittest.makeSuite(FieldPropertyStoredThroughFieldTests), - unittest.makeSuite(CreateFieldPropertiesTests), - )) diff --git a/src/zope/schema/tests/test_interfaces.py b/src/zope/schema/tests/test_interfaces.py index 3111fb4..4025324 100644 --- a/src/zope/schema/tests/test_interfaces.py +++ b/src/zope/schema/tests/test_interfaces.py @@ -88,10 +88,3 @@ class Test__fields(unittest.TestCase): self._callFUT([Text(), Bytes(), Int(), Float(), Decimal(), 0]), False ) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(Test__is_field), - unittest.makeSuite(Test__fields), - )) diff --git a/src/zope/schema/tests/test_schema.py b/src/zope/schema/tests/test_schema.py index 3a54e11..6262125 100644 --- a/src/zope/schema/tests/test_schema.py +++ b/src/zope/schema/tests/test_schema.py @@ -212,7 +212,7 @@ class Test_getSchemaValidationErrors(unittest.TestCase): class INoFields(Interface): def method(): - pass + "A method." attr = Attribute('ignoreme') errors = self._callFUT(INoFields, object()) @@ -262,14 +262,3 @@ class Test_getSchemaValidationErrors(unittest.TestCase): self.assertEqual(len(errors), 1) self.assertEqual(errors[0][0], 'value') self.assertEqual(errors[0][1].__class__, TooSmall) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(Test_getFields), - unittest.makeSuite(Test_getFieldsInOrder), - unittest.makeSuite(Test_getFieldNames), - unittest.makeSuite(Test_getFieldNamesInOrder), - unittest.makeSuite(Test_getValidationErrors), - unittest.makeSuite(Test_getSchemaValidationErrors), - )) diff --git a/src/zope/schema/tests/test_states.py b/src/zope/schema/tests/test_states.py index 2bfd3d0..7b81cc1 100644 --- a/src/zope/schema/tests/test_states.py +++ b/src/zope/schema/tests/test_states.py @@ -98,9 +98,3 @@ class StateSelectionTest(unittest.TestCase): self.assertTrue(bound.vocabularyName is None) self.assertTrue(verifyObject(IVocabulary, bound.vocabulary)) self.assertTrue("AL" in bound.vocabulary) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(StateSelectionTest), - )) diff --git a/src/zope/schema/tests/test_vocabulary.py b/src/zope/schema/tests/test_vocabulary.py index ede5c08..5bcc6a6 100644 --- a/src/zope/schema/tests/test_vocabulary.py +++ b/src/zope/schema/tests/test_vocabulary.py @@ -602,21 +602,16 @@ def _makeSampleVocabulary(): class SampleVocabulary(object): def __iter__(self): - return iter([self.getTerm(x) for x in range(0, 10)]) + raise AssertionError("Not called") def __contains__(self, value): return 0 <= value < 10 - def __len__(self): + def __len__(self): # pragma: no cover return 10 def getTerm(self, value): - if value in self: - t = SampleTerm() - t.value = value - t.double = 2 * value - return t - raise LookupError("no such value: %r" % value) + raise AssertionError("Not called.") return SampleVocabulary() @@ -626,17 +621,5 @@ def _makeDummyRegistry(): class DummyRegistry(VocabularyRegistry): def get(self, object, name): - v = _makeSampleVocabulary() - v.object = object - v.name = name - return v + raise AssertionError("Not called") return DummyRegistry() - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(SimpleTermTests), - unittest.makeSuite(SimpleVocabularyTests), - unittest.makeSuite(TreeVocabularyTests), - unittest.makeSuite(RegistryTests), - )) |
