@@ -295,6 +295,79 @@ def test_io(self):
295295 else :
296296 os .remove (alien_file )
297297
298+
299+ def test_config_file (self ):
300+ """simple test for configuration file reading"""
301+
302+ outstring = []
303+ instring = "CALL alien_invasion( x)"
304+ outstring_with_config = "call alien_invasion(x)"
305+ outstring_without_config = "CALL alien_invasion(x)"
306+
307+ dirname = 'test_tmp/'
308+
309+ if os .path .lexists (dirname ):
310+ raise AlienInvasion (
311+ "remove directory test_tmp" ) # pragma: no cover
312+
313+ os .mkdir (dirname )
314+ alien_file = os .path .join (dirname , "alien_invasion.f90" )
315+ excluded_file = os .path .join (dirname , "excluded.f90" )
316+ config_file = os .path .join (dirname , ".fprettify.rc" )
317+ configuration = "case=[1,1,1,2]\n exclude=[excluded.f90]"
318+
319+ try :
320+ with io .open (alien_file , 'w' , encoding = 'utf-8' ) as infile :
321+ infile .write (instring )
322+
323+ with io .open (excluded_file , 'w' , encoding = 'utf-8' ) as infile :
324+ infile .write (instring )
325+
326+ with io .open (config_file , 'w' , encoding = 'utf-8' ) as infile :
327+ infile .write (configuration )
328+
329+ # testing stdin --> stdout
330+ # In this case, the config file will not be read,
331+ # because it is not located in CWD.
332+ p1 = subprocess .Popen (RUNSCRIPT ,
333+ stdout = subprocess .PIPE , stdin = subprocess .PIPE )
334+ outstr = p1 .communicate (instring .encode ('UTF-8' ))[0 ].decode ('UTF-8' )
335+ self .assertEqual (outstring_without_config , outstr .strip ())
336+
337+ # testing file --> stdout
338+ p1 = subprocess .Popen ([RUNSCRIPT , alien_file , '--stdout' ],
339+ stdout = subprocess .PIPE )
340+ outstr = p1 .communicate (instring .encode ('UTF-8' )[0 ])[0 ].decode ('UTF-8' )
341+ self .assertEqual (outstring_with_config , outstr .strip ())
342+
343+ # testing recursive mode
344+ p1 = subprocess .Popen ([RUNSCRIPT , '--recursive' , dirname ],
345+ stdout = subprocess .PIPE )
346+ p1 .wait ()
347+
348+ with io .open (alien_file , 'r' , encoding = 'utf-8' ) as infile :
349+ self .assertEqual (outstring_with_config , infile .read ().strip ())
350+
351+ # Excluded file should not be touched at all.
352+ with io .open (excluded_file , 'r' , encoding = 'utf-8' ) as infile :
353+ self .assertEqual (instring , infile .read ().strip ())
354+
355+ except : # pragma: no cover
356+ if os .path .isfile (alien_file ):
357+ os .remove (alien_file )
358+ if os .path .isfile (excluded_file ):
359+ os .remove (excluded_file )
360+ if os .path .isfile (config_file ):
361+ os .remove (config_file )
362+ if os .path .isdir (dirname ):
363+ os .rmdir (dirname )
364+ raise
365+ else :
366+ os .remove (alien_file )
367+ os .remove (excluded_file )
368+ os .remove (config_file )
369+ os .rmdir (dirname )
370+
298371 def test_multi_alias (self ):
299372 """test for issue #11 (multiple alias and alignment)"""
300373 instring = "use A,only:B=>C,&\n D=>E"
0 commit comments