Skip to content

Commit

Permalink
100% coverage for contentinfo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 30, 2018
1 parent 8e2adc3 commit 2d47d22
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,8 @@
- Fix an AttributeError accessing the ``preferredCharset`` of an
``ICodecTerm`` when no ``ICodecPreferredCharset`` was registered.

- Reach and automatically require 100% test coverage.

2.3.1 (2018-01-09)
==================

Expand Down
55 changes: 55 additions & 0 deletions src/zope/mimetype/tests/test_contentinfo.py
@@ -0,0 +1,55 @@
##############################################################################
#
# Copyright (c) 2005 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# -*- coding: utf-8 -*-
"""
Tests for contentinfo.py
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest

from zope import interface
from zope.testing import cleanup

from zope.mimetype.contentinfo import ContentInfo


class TestContentinfo(cleanup.CleanUp,
unittest.TestCase):
# py2 bwc
assertRaisesRegex = getattr(unittest.TestCase,
'assertRaisesRegex',
unittest.TestCase.assertRaisesRegexp)

def test_codec_cant_decode_all(self):
from zope.mimetype.interfaces import IContentTypeAware

@interface.implementer(IContentTypeAware)
class Content(object):
mimeType = 'text/plain'
parameters = ()


class Codec(object):
def decode(self, s):
return '', 0

info = ContentInfo(Content())
# ContentInfo caches the codec, take advantage of that.
info._codec = Codec()

with self.assertRaisesRegex(ValueError, "not completely consumed"):
info.decode('foo')
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -20,7 +20,7 @@ basepython =
python2.7
commands =
coverage run -m zope.testrunner --test-path=src []
coverage report --fail-under=94
coverage report --fail-under=100
deps =
{[testenv]deps}
coverage
Expand Down

0 comments on commit 2d47d22

Please sign in to comment.