From efb90f8a49e7099ff2631c61eb505971acb51d76 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 23 Feb 2015 16:44:20 -0500 Subject: Require 100% coverage. --- src/zope/contenttype/__init__.py | 2 +- src/zope/contenttype/parse.py | 7 +------ src/zope/contenttype/tests/test_parse.py | 9 +++++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/zope/contenttype/__init__.py b/src/zope/contenttype/__init__.py index cededc4..0724a56 100644 --- a/src/zope/contenttype/__init__.py +++ b/src/zope/contenttype/__init__.py @@ -105,7 +105,7 @@ here = os.path.dirname(os.path.abspath(__file__)) add_files([os.path.join(here, "mime.types")]) # Python 2/3 compatibility for testing. -def _print(s): +def _print(s): # pragma: NO COVER print(s) def main(): diff --git a/src/zope/contenttype/parse.py b/src/zope/contenttype/parse.py index 5978da3..27fde81 100644 --- a/src/zope/contenttype/parse.py +++ b/src/zope/contenttype/parse.py @@ -86,12 +86,7 @@ def _parse_params(string): return result -def _quoted_string_match(string): - # This support RFC 822 quoted-string values. - global _quoted_string_match - _quoted_string_match = re.compile( - '"(?:\\\\.|[^"\n\r\\\\])*"', re.DOTALL).match - return _quoted_string_match(string) +_quoted_string_match = re.compile('"(?:\\\\.|[^"\n\r\\\\])*"', re.DOTALL).match def _check_token(string): if _token_match(string) is None: diff --git a/src/zope/contenttype/tests/test_parse.py b/src/zope/contenttype/tests/test_parse.py index dd2fffd..04490af 100644 --- a/src/zope/contenttype/tests/test_parse.py +++ b/src/zope/contenttype/tests/test_parse.py @@ -31,6 +31,9 @@ class ParseOrderedTestCase(unittest.TestCase): def oneParam(self, name, value): return [(name, value)] + def test_invalid_type(self): + self.assertRaises(ValueError, self._callFUT, 'no-slash-here') + def test_without_params(self): self.assertEqual(self._callFUT("text/plain"), ("text", "plain", self.empty_params)) @@ -41,6 +44,12 @@ class ParseOrderedTestCase(unittest.TestCase): self.assertEqual(self._callFUT("text / vnd.wap.wml"), ("text", "vnd.wap.wml", self.empty_params)) + def test_invalid_params(self): + self.assertRaises(ValueError, + self._callFUT, 'text/plain; foo="abc') + self.assertRaises(ValueError, + self._callFUT, 'text/plain; foo="abc" bar') + def test_with_empty_params(self): self.assertEqual(self._callFUT("text/plain ; "), ("text", "plain", self.empty_params)) -- cgit v1.2.1