summaryrefslogtreecommitdiff
path: root/mimeparse.py
diff options
context:
space:
mode:
authorAde Oshineye <adewale@gmail.com>2010-02-15 05:09:27 -0800
committerDavid Tsai <dbtsai@dbtsai.com>2012-08-22 14:34:38 -0700
commitbb1cbb2aa586d3ac74a21148a03c207d18a64262 (patch)
treedc46b79817e5e9a494ab580cb6a9afc95810c62f /mimeparse.py
parent032c52c6172856af88bbd5b7c59b3c1fb744421e (diff)
downloadpython-mimeparse-bb1cbb2aa586d3ac74a21148a03c207d18a64262.tar.gz
Removed the tests in mimeparse.py since we now have the language independent tests.
Diffstat (limited to 'mimeparse.py')
-rw-r--r--mimeparse.py58
1 files changed, 0 insertions, 58 deletions
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()