Skip to content

Commit

Permalink
100% coverage for zcml.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 26, 2018
1 parent 0169a7a commit fec8a2f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/zope/mimetype/codec.py
Expand Up @@ -21,8 +21,8 @@


@interface.implementer(ICodec)
class Codec:
class Codec(object):

def __init__(self, name, title):
self.name = name
self.title = title
Expand All @@ -39,7 +39,7 @@ def addCodec(name, title=None):


@interface.implementer(ICharset)
class Charset:
class Charset(object):

def __init__(self, name, encoding):
self.name = name
Expand Down
76 changes: 76 additions & 0 deletions src/zope/mimetype/tests/test_zcml.py
@@ -0,0 +1,76 @@
##############################################################################
#
# 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 zcml.py
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest

from zope import component
from zope.configuration import xmlconfig
from zope.testing import cleanup

class TestCodecDirective(cleanup.CleanUp,
unittest.TestCase):

def test_codec(self):
from zope.mimetype.interfaces import ICodec
from zope.mimetype.interfaces import ICharset

xmlconfig.string("""
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="zope.mimetype">
<include package="zope.mimetype" file="meta.zcml" />
<codec name="iso8859-1" title="Western (ISO-8859-1)">
<charset name="latin1" />
</codec>
</configure>
""")

codec = component.getUtility(ICodec, "iso8859-1")
self.assertEqual("Western (ISO-8859-1)", codec.title)

charset = component.getUtility(ICharset, "latin1")
self.assertIsNotNone(charset)


class TestMimeTypesDirective(cleanup.CleanUp,
unittest.TestCase):

def test_create_interfaces(self):
import os
import sys
import types

fake_module = types.ModuleType("zope_mime_testing")
sys.modules[fake_module.__name__] = fake_module
path = os.path.join(os.path.dirname(__file__), '..', 'types.csv')
try:
xmlconfig.string("""
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="zope.mimetype">
<include package="zope.mimetype" file="meta.zcml" />
<mimeTypes file='%s' module="zope_mime_testing" />
</configure>
""" % (path,))
finally:
del sys.modules[fake_module.__name__]

self.assertTrue(hasattr(fake_module, 'IContentTypeCSV'))
4 changes: 2 additions & 2 deletions src/zope/mimetype/zcml.py
Expand Up @@ -24,7 +24,7 @@

try:
from zope.browserresource.metaconfigure import icon
except ImportError:
except ImportError: # pragma: no cover (coverage runs with the extra installed)
def icon(*args):
import warnings
warnings.warn("No icon support: zope.browserresource is not installed")
Expand All @@ -38,7 +38,7 @@ class IMimeTypesDirective(interface.Interface):
Example:
<zope:mimeDefinitions file='types.csv'/>
<zope:mimeTypes file='types.csv' module="zope.mimetype.interfaces" />
"""

Expand Down

0 comments on commit fec8a2f

Please sign in to comment.