1010 from collections import OrderedDict
1111from nose .tools import raises
1212
13-
14- OUTPUT = "response_test .xls"
13+ FILE_NAME = "response_test"
14+ OUTPUT = "%s .xls" % FILE_NAME
1515
1616
1717class TestInput (webio .ExcelInput ):
@@ -31,11 +31,10 @@ def get_file_tuple(self, field_name):
3131 return field_name
3232
3333
34- def dumpy_response (content , content_type = None , status = 200 ):
34+ def dumpy_response (content , content_type = None , status = 200 , file_name = None ):
3535 """A dummy response"""
36- f = open (OUTPUT , 'wb' )
37- f .write (content )
38- f .close ()
36+ with open (file_name , 'wb' ) as f :
37+ f .write (content )
3938
4039
4140webio .ExcelResponse = dumpy_response
@@ -236,19 +235,19 @@ def setUp(self):
236235
237236 def test_make_response_from_sheet (self ):
238237 sheet = pe .Sheet (self .data )
239- webio .make_response (sheet , "xls" )
238+ webio .make_response (sheet , "xls" , file_name = FILE_NAME )
240239 self .verify ()
241240
242241 def test_make_response_from_array (self ):
243- webio .make_response_from_array (self .data , "xls" )
242+ webio .make_response_from_array (self .data , "xls" , file_name = FILE_NAME )
244243 self .verify ()
245244
246245 def test_make_response_from_records (self ):
247246 records = [
248247 {"X" : 1 , "Y" : 2 , "Z" : 3 },
249248 {"X" : 4 , "Y" : 5 , "Z" : 6 }
250249 ]
251- webio .make_response_from_records (records , "xls" )
250+ webio .make_response_from_records (records , "xls" , file_name = FILE_NAME )
252251 self .verify ()
253252
254253 def test_make_response_from_dict (self ):
@@ -257,7 +256,7 @@ def test_make_response_from_dict(self):
257256 "Y" : [2 , 5 ],
258257 "Z" : [3 , 6 ]
259258 }
260- webio .make_response_from_dict (adict , "xls" )
259+ webio .make_response_from_dict (adict , "xls" , file_name = FILE_NAME )
261260 self .verify ()
262261
263262 def test_make_response_from_table (self ):
@@ -269,7 +268,7 @@ def test_make_response_from_table(self):
269268 session .add (row1 )
270269 session .add (row2 )
271270 session .commit ()
272- webio .make_response_from_a_table (session , Signature , "xls" )
271+ webio .make_response_from_a_table (session , Signature , "xls" , file_name = FILE_NAME )
273272 self .verify ()
274273 session .close ()
275274
@@ -284,7 +283,7 @@ def test_make_response_from_query_sets(self):
284283 session .commit ()
285284 query_sets = session .query (Signature ).filter_by (X = 1 ).all ()
286285 column_names = ["X" , "Y" , "Z" ]
287- webio .make_response_from_query_sets (query_sets , column_names , "xls" )
286+ webio .make_response_from_query_sets (query_sets , column_names , "xls" , file_name = FILE_NAME )
288287 sheet2 = pe .get_sheet (file_name = OUTPUT )
289288 assert sheet2 .to_array () == [
290289 ["X" , "Y" , "Z" ],
@@ -310,11 +309,11 @@ def setUp(self):
310309
311310 def test_make_response_from_book (self ):
312311 book = pe .get_book (bookdict = self .content )
313- webio .make_response (book , "xls" )
312+ webio .make_response (book , "xls" , file_name = FILE_NAME )
314313 self .verify ()
315314
316315 def test_make_response_from_book_dict (self ):
317- webio .make_response_from_book_dict (self .content , "xls" )
316+ webio .make_response_from_book_dict (self .content , "xls" , file_name = FILE_NAME )
318317 self .verify ()
319318
320319 def verify (self ):
@@ -340,7 +339,7 @@ def test_make_response_from_tables(self):
340339 session .add (row3 )
341340 session .add (row4 )
342341 session .commit ()
343- webio .make_response_from_tables (session , [Signature , Signature2 ], "xls" )
342+ webio .make_response_from_tables (session , [Signature , Signature2 ], "xls" , file_name = FILE_NAME )
344343 book = pe .get_book (file_name = OUTPUT )
345344 expected = OrderedDict ()
346345 expected .update ({'signature' : [['X' , 'Y' , 'Z' ], [1 , 2 , 3 ], [4 , 5 , 6 ]]})
0 commit comments