Skip to content

Commit

Permalink
100% coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 10, 2017
1 parent d38c34d commit fa586c6
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 166 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ exclude_lines =
pragma: no cover
if __name__ == '__main__':
raise NotImplementedError
raise AssertionError
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parts
*.egg-info
.tox
.coverage
htmlcov/
nosetests.xml
coverage.xml
devel
Expand Down
2 changes: 1 addition & 1 deletion src/zope/schema/_bootstrapinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __call__(context):


class NO_VALUE(object):
def __repr__(self):
def __repr__(self): # pragma: no cover
return '<NO_VALUE>'

NO_VALUE = NO_VALUE()
11 changes: 0 additions & 11 deletions src/zope/schema/tests/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,3 @@ def __len__(self):

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"
37 changes: 6 additions & 31 deletions src/zope/schema/tests/test__bootstrapfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,39 +267,31 @@ def test_bind(self):
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

def test_validate_missing_and_required(self):
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)

Expand Down Expand Up @@ -401,7 +393,7 @@ def test__validate_collection_but_not_iterable(self):

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):
Expand Down Expand Up @@ -432,7 +424,7 @@ def test__validate_collection_but_not_iterable(self):

class Dummy(object):
def __contains__(self, item):
return False
raise AssertionError("Not called")
self.assertRaises(NotAnIterator, itr._validate, Dummy())


Expand Down Expand Up @@ -803,20 +795,3 @@ def __init__(self, exc=None):
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),
))
10 changes: 1 addition & 9 deletions src/zope/schema/tests/test__bootstrapinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

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):

Expand Down Expand Up @@ -60,9 +58,3 @@ def test___eq___w_args(self):
self.assertEqual(left == right, False)
self.assertEqual(left == left, True)
self.assertEqual(right == right, True)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ValidationErrorTests),
))
49 changes: 6 additions & 43 deletions src/zope/schema/tests/test__field.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def test__validate_source_is_ICSB_unbound(self):
@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)
Expand Down Expand Up @@ -1675,14 +1675,9 @@ def _makeSchema(self, **kw):

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
Expand Down Expand Up @@ -2063,21 +2058,16 @@ class SampleTerm(object):
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()

Expand All @@ -2092,30 +2082,3 @@ def __init__(self, vocabulary):
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),
))
12 changes: 2 additions & 10 deletions src/zope/schema/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class IFoo(Interface):

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):
Expand All @@ -163,7 +163,7 @@ class IFoo(Interface):

class Foo(object):
def getter(self):
return '123'
raise AssertionError("Not called")

self.assertRaises(AttributeError, getter.set, Foo(), '456')

Expand Down Expand Up @@ -305,11 +305,3 @@ class IFoo(Interface):
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),
))
6 changes: 0 additions & 6 deletions src/zope/schema/tests/test_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,3 @@ def _makeOne(cls):

for cls in (Int, Text):
self.assertEqual(_makeOne(cls), _makeOne(cls))


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FieldEqualityTests),
))
10 changes: 1 addition & 9 deletions src/zope/schema/tests/test_fieldproperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def query(self, inst, default):
return default

def set(self, inst, value):
if self.readonly:
if self.readonly: # pragma: no cover
raise ValueError
setattr(inst, 'faux', value)

Expand Down Expand Up @@ -658,11 +658,3 @@ class Dummy(object):
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),
))
7 changes: 0 additions & 7 deletions src/zope/schema/tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,3 @@ def test_w_mixed(self):
self._callFUT([Text(), Bytes(), Int(), Float(), Decimal(), 0]),
False
)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test__is_field),
unittest.makeSuite(Test__fields),
))
13 changes: 1 addition & 12 deletions src/zope/schema/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_schema_wo_fields(self):

class INoFields(Interface):
def method():
pass
"A method."
attr = Attribute('ignoreme')

errors = self._callFUT(INoFields, object())
Expand Down Expand Up @@ -262,14 +262,3 @@ class Obj(object):
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),
))
6 changes: 0 additions & 6 deletions src/zope/schema/tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,3 @@ def test_prebound_vocabulary(self):
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),
))
25 changes: 4 additions & 21 deletions src/zope/schema/tests/test_vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,21 +602,16 @@ class SampleTerm(object):
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()

Expand All @@ -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),
))

0 comments on commit fa586c6

Please sign in to comment.