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