@@ -107,20 +107,29 @@ def test_filename_with_url_delimiters(self):
107
107
eq (self .db .guess_type (r" \"\`;b&b&c |.tar.gz" ), gzip_expected )
108
108
109
109
def test_guess_all_types (self ):
110
- eq = self .assertEqual
111
- unless = self .assertTrue
112
110
# First try strict. Use a set here for testing the results because if
113
111
# test_urllib2 is run before test_mimetypes, global state is modified
114
112
# such that the 'all' set will have more items in it.
115
- all = set (self .db .guess_all_extensions ('text/plain' , strict = True ))
116
- unless (all >= set (['.bat' , '.c' , '.h' , '.ksh' , '.pl' , '.txt' ]))
113
+ all = self .db .guess_all_extensions ('text/plain' , strict = True )
114
+ self .assertTrue (set (all ) >= {'.bat' , '.c' , '.h' , '.ksh' , '.pl' , '.txt' })
115
+ self .assertEqual (len (set (all )), len (all )) # no duplicates
117
116
# And now non-strict
118
117
all = self .db .guess_all_extensions ('image/jpg' , strict = False )
119
- all .sort ()
120
- eq (all , ['.jpg' ])
118
+ self .assertEqual (all , ['.jpg' ])
121
119
# And now for no hits
122
120
all = self .db .guess_all_extensions ('image/jpg' , strict = True )
123
- eq (all , [])
121
+ self .assertEqual (all , [])
122
+ # And now for type existing in both strict and non-strict mappings.
123
+ self .db .add_type ('test-type' , '.strict-ext' )
124
+ self .db .add_type ('test-type' , '.non-strict-ext' , strict = False )
125
+ all = self .db .guess_all_extensions ('test-type' , strict = False )
126
+ self .assertEqual (all , ['.strict-ext' , '.non-strict-ext' ])
127
+ all = self .db .guess_all_extensions ('test-type' )
128
+ self .assertEqual (all , ['.strict-ext' ])
129
+ # Test that changing the result list does not affect the global state
130
+ all .append ('.no-such-ext' )
131
+ all = self .db .guess_all_extensions ('test-type' )
132
+ self .assertNotIn ('.no-such-ext' , all )
124
133
125
134
def test_encoding (self ):
126
135
getpreferredencoding = locale .getpreferredencoding
0 commit comments