Skip to content

Commit d9219a6

Browse files
committed
Add test for config file search when stdin
1 parent 8881172 commit d9219a6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

fprettify/tests/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,43 @@ def check_output_file(fname, str_exp):
376376
else:
377377
self.removeTmpDir()
378378

379+
def test_config_stdin(self):
380+
outstring = []
381+
instring = "CALL alien_invasion( x)"
382+
outstring_with_config = "call alien_invasion(x)"
383+
self.createTmpDir()
384+
385+
alien_file = joinpath(TEMP_DIR, "alien_invasion.f90")
386+
config_file = joinpath(os.getcwd(), ".fprettify.rc")
387+
conf_string = "case=[1,1,1,2]\nexclude=[excluded*]"
388+
389+
if os.path.exists(config_file):
390+
raise FileException(
391+
"remove file %s" % conf_file_cwd) # pragma: no cover
392+
393+
def create_file(fname, string):
394+
with io.open(fname, 'w', encoding='utf-8') as infile:
395+
infile.write(string)
396+
397+
try:
398+
create_file(alien_file, instring)
399+
create_file(config_file, conf_string)
400+
401+
# testing stdin --> stdout, with configuration file read from CWD
402+
p1 = subprocess.Popen(RUNSCRIPT,
403+
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
404+
outstr = p1.communicate(instring.encode('UTF-8'))[0].decode('UTF-8')
405+
self.assertEqual(outstring_with_config, outstr.strip())
406+
407+
except: # pragma: no cover
408+
self.removeTmpDir()
409+
if os.path.isfile(config_file):
410+
os.remove(config_file)
411+
raise
412+
else:
413+
self.removeTmpDir()
414+
os.remove(config_file)
415+
379416
def test_config_file(self):
380417
"""simple test for configuration file reading"""
381418

0 commit comments

Comments
 (0)