@@ -355,7 +355,7 @@ def tearDown(self):
355355 """Clean up temporary directory after tests are over."""
356356 shutil .rmtree (self .tmpdir )
357357
358- def _check_logfile (self , exists = True ):
358+ def _check_logfile (self , exists = True , logfile = None ):
359359 """Check for logfiles existence and contents.
360360
361361 exists=True:
@@ -364,12 +364,14 @@ def _check_logfile(self, exists=True):
364364 Optionally check that the logfiles contents is equal to this value.
365365
366366 """
367+ if not logfile :
368+ logfile = self .logfile
367369 if not exists :
368- self .assertFalse (os .path .exists (self . logfile ))
370+ self .assertFalse (os .path .exists (logfile ))
369371 return
370372
371- self .assertTrue (os .path .exists (self . logfile ))
372- with open (self . logfile ) as f :
373+ self .assertTrue (os .path .exists (logfile ))
374+ with open (logfile ) as f :
373375 logfile_contents = f .read ()
374376 self .assertIn (self .characteristic_output_string , logfile_contents )
375377
@@ -416,6 +418,15 @@ def test_logfile(self):
416418 self ._check_stdout (output .getvalue (), exists = False )
417419 self ._check_logfile (exists = True )
418420
421+ def test_logfile_with_spaces (self ):
422+ # In response to Issue 3579
423+ logfile_with_spaces = os .path .join (self .tmpdir , "My File.log" )
424+ with SolverFactory ("gams" , solver_io = "gms" ) as opt :
425+ with capture_output () as output :
426+ opt .solve (self .m , logfile = logfile_with_spaces )
427+ self ._check_stdout (output .getvalue (), exists = False )
428+ self ._check_logfile (exists = True , logfile = logfile_with_spaces )
429+
419430 def test_logfile_relative (self ):
420431 cwd = os .getcwd ()
421432 with TempfileManager :
@@ -470,6 +481,15 @@ def test_logfile(self):
470481 self ._check_stdout (output .getvalue (), exists = False )
471482 self ._check_logfile (exists = True )
472483
484+ def test_logfile_with_spaces (self ):
485+ # In response to Issue 3579
486+ logfile_with_spaces = os .path .join (self .tmpdir , "My File.log" )
487+ with SolverFactory ("gams" , solver_io = "gms" ) as opt :
488+ with capture_output () as output :
489+ opt .solve (self .m , logfile = logfile_with_spaces )
490+ self ._check_stdout (output .getvalue (), exists = False )
491+ self ._check_logfile (exists = True , logfile = logfile_with_spaces )
492+
473493 def test_logfile_relative (self ):
474494 cwd = os .getcwd ()
475495 with TempfileManager :
0 commit comments