Kaydet (Commit) ceca5d29 authored tarafından Barry Warsaw's avatar Barry Warsaw

test_guess_all_types(): Use a more robust test for checking that

guess_all_extensions() returns (at least) what we expect.  As Jeff
Epler suggests in

http://mail.python.org/pipermail/python-dev/2003-September/038264.html

We use a set to test the results.  This fixes the test when
test_urllib2 is run before test_mimetypes.
üst 49ba4c39
import mimetypes import mimetypes
import StringIO import StringIO
import unittest import unittest
from sets import Set
from test import test_support from test import test_support
...@@ -46,10 +47,12 @@ class MimeTypesTestCase(unittest.TestCase): ...@@ -46,10 +47,12 @@ class MimeTypesTestCase(unittest.TestCase):
def test_guess_all_types(self): def test_guess_all_types(self):
eq = self.assertEqual eq = self.assertEqual
# First try strict unless = self.failUnless
all = self.db.guess_all_extensions('text/plain', strict=True) # First try strict. Use a set here for testing the results because if
all.sort() # test_urllib2 is run before test_mimetypes, global state is modified
eq(all, ['.bat', '.c', '.h', '.ksh', '.pl', '.txt']) # such that the 'all' set will have more items in it.
all = Set(self.db.guess_all_extensions('text/plain', strict=True))
unless(all >= Set(['.bat', '.c', '.h', '.ksh', '.pl', '.txt']))
# And now non-strict # And now non-strict
all = self.db.guess_all_extensions('image/jpg', strict=False) all = self.db.guess_all_extensions('image/jpg', strict=False)
all.sort() all.sort()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment