From bb1cbb2aa586d3ac74a21148a03c207d18a64262 Mon Sep 17 00:00:00 2001 From: Ade Oshineye Date: Mon, 15 Feb 2010 05:09:27 -0800 Subject: Removed the tests in mimeparse.py since we now have the language independent tests. --- mimeparse.py | 58 ---------------------------------------------------------- 1 file changed, 58 deletions(-) (limited to 'mimeparse.py') diff --git a/mimeparse.py b/mimeparse.py index f9b6bb4..0fd91e7 100644 --- a/mimeparse.py +++ b/mimeparse.py @@ -121,61 +121,3 @@ def best_match(supported, header): for mime_type in supported] weighted_matches.sort() return weighted_matches[-1][0][1] and weighted_matches[-1][1] or '' - -if __name__ == "__main__": - import unittest - - class TestMimeParsing(unittest.TestCase): - - def test_parse_media_range(self): - self.assert_(('application', 'xml', {'q': '1'}) == parse_media_range('application/xml;q=1')) - self.assertEqual(('application', 'xml', {'q': '1'}), parse_media_range('application/xml')) - self.assertEqual(('application', 'xml', {'q': '1'}), parse_media_range('application/xml;q=')) - self.assertEqual(('application', 'xml', {'q': '1'}), parse_media_range('application/xml ; q=')) - self.assertEqual(('application', 'xml', {'q': '1', 'b': 'other'}), parse_media_range('application/xml ; q=1;b=other')) - self.assertEqual(('application', 'xml', {'q': '1', 'b': 'other'}), parse_media_range('application/xml ; q=2;b=other')) - # Java URLConnection class sends an Accept header that includes a single * - self.assertEqual(('*', '*', {'q': '.2'}), parse_media_range(" *; q=.2")) - - def test_rfc_2616_example(self): - accept = "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" - self.assertEqual(1, quality("text/html;level=1", accept)) - self.assertEqual(0.7, quality("text/html", accept)) - self.assertEqual(0.3, quality("text/plain", accept)) - self.assertEqual(0.5, quality("image/jpeg", accept)) - self.assertEqual(0.4, quality("text/html;level=2", accept)) - self.assertEqual(0.7, quality("text/html;level=3", accept)) - - def test_best_match(self): - mime_types_supported = ['application/xbel+xml', 'application/xml'] - # direct match - self.assertEqual(best_match(mime_types_supported, 'application/xbel+xml'), 'application/xbel+xml') - # direct match with a q parameter - self.assertEqual(best_match(mime_types_supported, 'application/xbel+xml; q=1'), 'application/xbel+xml') - # direct match of our second choice with a q parameter - self.assertEqual(best_match(mime_types_supported, 'application/xml; q=1'), 'application/xml') - # match using a subtype wildcard - self.assertEqual(best_match(mime_types_supported, 'application/*; q=1'), 'application/xml') - # match using a type wildcard - self.assertEqual(best_match(mime_types_supported, '*/*'), 'application/xml') - - mime_types_supported = ['application/xbel+xml', 'text/xml'] - # match using a type versus a lower weighted subtype - self.assertEqual(best_match(mime_types_supported, 'text/*;q=0.5,*/*; q=0.1'), 'text/xml') - # fail to match anything - self.assertEqual(best_match(mime_types_supported, 'text/html,application/atom+xml; q=0.9'), '') - - # common AJAX scenario - mime_types_supported = ['application/json', 'text/html'] - self.assertEqual(best_match(mime_types_supported, 'application/json, text/javascript, */*'), 'application/json') - # verify fitness ordering - self.assertEqual(best_match(mime_types_supported, 'application/json, text/html;q=0.9'), 'application/json') - - def test_support_wildcards(self): - mime_types_supported = ['image/*', 'application/xml'] - # match using a type wildcard - self.assertEqual(best_match(mime_types_supported, 'image/png'), 'image/*') - # match using a wildcard for both requested and supported - self.assertEqual(best_match(mime_types_supported, 'image/*'), 'image/*') - - unittest.main() -- cgit v1.2.1