[Checkins] SVN: zope.contenttype/trunk/ - Added some tests for better coverage.

Stephen Richter cvs-admin at zope.org
Mon Feb 11 19:20:58 UTC 2013


Log message for revision 129298:
  - Added some tests for better coverage.
  - Added `tox.ini` and manifest.
  - Added support for Python 3.3 and PyPy 1.9.
  
  

Changed:
  _U  zope.contenttype/trunk/
  U   zope.contenttype/trunk/CHANGES.txt
  A   zope.contenttype/trunk/MANIFEST.in
  U   zope.contenttype/trunk/setup.py
  U   zope.contenttype/trunk/src/zope/contenttype/__init__.py
  U   zope.contenttype/trunk/src/zope/contenttype/parse.py
  U   zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py
  A   zope.contenttype/trunk/tox.ini

-=-

Property changes on: zope.contenttype/trunk
___________________________________________________________________
Modified: svn:ignore
   - bin
build
dist
lib
setup.cfg
develop-eggs
eggs
parts
.installed.cfg

   + .coverage
.tox
.installed.cfg
bin
build
dist
lib
setup.cfg
develop-eggs
eggs
parts
*.xml


Modified: zope.contenttype/trunk/CHANGES.txt
===================================================================
--- zope.contenttype/trunk/CHANGES.txt	2013-02-11 18:45:01 UTC (rev 129297)
+++ zope.contenttype/trunk/CHANGES.txt	2013-02-11 19:20:58 UTC (rev 129298)
@@ -4,6 +4,12 @@
 4.0.0 (unreleased)
 ------------------
 
+- Added some tests for better coverage.
+
+- Added `tox.ini` and manifest.
+
+- Added support for Python 3.3 and PyPy 1.9.
+
 - Dropped support for Python 2.4 and 2.5.
 
 3.5.5 (2011-07-27)

Added: zope.contenttype/trunk/MANIFEST.in
===================================================================
--- zope.contenttype/trunk/MANIFEST.in	                        (rev 0)
+++ zope.contenttype/trunk/MANIFEST.in	2013-02-11 19:20:58 UTC (rev 129298)
@@ -0,0 +1,9 @@
+include *.rst
+include *.txt
+include tox.ini
+include bootstrap.py
+include buildout.cfg
+
+recursive-include src *
+
+global-exclude *.pyc

Modified: zope.contenttype/trunk/setup.py
===================================================================
--- zope.contenttype/trunk/setup.py	2013-02-11 18:45:01 UTC (rev 129297)
+++ zope.contenttype/trunk/setup.py	2013-02-11 19:20:58 UTC (rev 129298)
@@ -50,6 +50,10 @@
         'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: Implementation :: CPython',
+        'Programming Language :: Python :: Implementation :: PyPy',
         'Operating System :: OS Independent',
         'Topic :: Internet :: WWW/HTTP',
         'Topic :: Software Development',

Modified: zope.contenttype/trunk/src/zope/contenttype/__init__.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/__init__.py	2013-02-11 18:45:01 UTC (rev 129297)
+++ zope.contenttype/trunk/src/zope/contenttype/__init__.py	2013-02-11 19:20:58 UTC (rev 129298)
@@ -16,10 +16,9 @@
 import os.path
 import mimetypes
 
-
 find_binary = re.compile('[\0-\7]').search
 
-  
+
 def text_type(s):
     """Given an unnamed piece of text, try to guess its content type.
 
@@ -42,13 +41,13 @@
             return 'text/xml'
 
     # we also recognize small snippets of HTML - the closing tag might be
-    # anywhere, even at the end of 
+    # anywhere, even at the end of
     if '</' in s:
         return 'text/html'
 
     return 'text/plain'
- 
 
+
 def guess_content_type(name='', body='', default=None):
     """Given a named piece of content, try to guess its content type.
 
@@ -105,7 +104,15 @@
 here = os.path.dirname(os.path.abspath(__file__))
 add_files([os.path.join(here, "mime.types")])
 
-if __name__ == '__main__':
+# Python 2/3 compatibility for testing.
+def _print(s):
+    print(s)
+
+def main():
     items = mimetypes.types_map.items()
-    items.sort()
-    for item in items: print "%s:\t%s" % item
+    items = sorted(items)
+    for item in items:
+        _print("%s:\t%s" % item)
+
+if __name__ == '__main__': #pragma: nocover
+    main()

Modified: zope.contenttype/trunk/src/zope/contenttype/parse.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/parse.py	2013-02-11 18:45:01 UTC (rev 129297)
+++ zope.contenttype/trunk/src/zope/contenttype/parse.py	2013-02-11 19:20:58 UTC (rev 129298)
@@ -112,7 +112,8 @@
     return string
 
 
-def join((major, minor, params)):
+def join(spec):
+    (major, minor, params) = spec
     pstr = ""
     try:
         params.items
@@ -121,7 +122,7 @@
     else:
         params = params.items()
         # ensure a predictable order:
-        params.sort()
+        params = sorted(params)
     for name, value in params:
         pstr += ";%s=%s" % (name, _escape(value))
     return "%s/%s%s" % (major, minor, pstr)

Modified: zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py	2013-02-11 18:45:01 UTC (rev 129297)
+++ zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py	2013-02-11 19:20:58 UTC (rev 129298)
@@ -37,6 +37,26 @@
         here = os.path.dirname(os.path.abspath(__file__))
         return os.path.join(here, name)
 
+    def test_main(self):
+        import zope.contenttype
+        _print = zope.contenttype._print
+        zope.contenttype._print = lambda s: None
+        zope.contenttype.main()
+        zope.contenttype._print = _print
+
+    def test_guess_content_type(self):
+        from zope.contenttype import add_files
+        from zope.contenttype import guess_content_type
+        filename = self._getFilename('mime.types-1')
+        add_files([filename])
+        ctype, encoding = guess_content_type(body='text file')
+        self.assertEqual(ctype, "text/plain")
+        ctype, encoding = guess_content_type(body='\001binary')
+        self.assertEqual(ctype, "application/octet-stream")
+        ctype, encoding = guess_content_type()
+        self.assertEqual(ctype, "text/x-unknown-content-type")
+
+
     def test_add_one_file(self):
         from zope.contenttype import add_files
         from zope.contenttype import guess_content_type

Added: zope.contenttype/trunk/tox.ini
===================================================================
--- zope.contenttype/trunk/tox.ini	                        (rev 0)
+++ zope.contenttype/trunk/tox.ini	2013-02-11 19:20:58 UTC (rev 129298)
@@ -0,0 +1,24 @@
+[tox]
+envlist =
+    py26,py27,py33,pypy
+
+[testenv]
+commands =
+    python setup.py test -q
+# without explicit deps, setup.py test will download a bunch of eggs into $PWD
+deps =
+
+[testenv:coverage]
+basepython =
+    python2.7
+commands =
+#   The installed version messes up nose's test discovery / coverage reporting
+#   So, we uninstall that from the environment, and then install the editable
+#   version, before running nosetests.
+    pip uninstall -y zope.contenttype
+    pip install -e .
+    nosetests --with-xunit --with-xcoverage
+deps =
+    nose
+    coverage
+    nosexcover



More information about the checkins mailing list