33import logging
44import pathlib
55import platform
6+ import tempfile
67import unittest
78
8- # CodeForm,
9- from open_fortran_parser .ofc_wrapper import execute_compiler , transpile
9+ from open_fortran_parser .ofc_wrapper import CodeForm , execute_compiler , transpile
1010
1111_LOG = logging .getLogger (__name__ )
1212
1313_HERE = pathlib .Path (__file__ ).resolve ().parent
1414
1515INPUT_PATHS = [_HERE .joinpath ('examples' , _ ) for _ in ['empty.f' ]]
16- OUTPUT_PATHS = [None ] # [pathlib.Path('/tmp/out.f'), None]
17- INDENTS = (4 ,) # (0, 4, 8)
18- FORMS = (None ,) # (CodeForm.Fixed, CodeForm.Free, None)
16+ INDENTS = (None , 2 , 4 , 8 )
17+ FORMS = (None , CodeForm .Fixed , CodeForm .Free )
1918
2019
2120class Tests (unittest .TestCase ):
@@ -25,20 +24,23 @@ class Tests(unittest.TestCase):
2524 @unittest .skipIf (platform .system () == 'Windows' , 'OFC not available on Windows' )
2625 def test_execute_compiler (self ):
2726 for input_path in INPUT_PATHS :
28- for output_path in OUTPUT_PATHS :
29- for indent in INDENTS :
30- for form in FORMS :
27+ for indent in INDENTS :
28+ for form in FORMS :
29+ output_file = tempfile .NamedTemporaryFile (delete = False )
30+ output_file_path = pathlib .Path (output_file .name )
31+ for output_path in (None , output_file_path ):
3132 with self .subTest (input_path = input_path , output_path = output_path ,
3233 indent = indent , form = form ):
33- execute_compiler (input_path , output_path , indent , form )
34+ result = execute_compiler (input_path , output_path , indent , form )
35+ self .assertEqual (result .returncode , 0 , msg = result )
3436
3537 @unittest .skipIf (platform .system () == 'Windows' , 'OFC not available on Windows' )
3638 def test_transpile (self ):
3739 for input_path in INPUT_PATHS :
3840 for indent in INDENTS :
3941 for form in FORMS :
4042 with self .subTest (input_path = input_path , indent = indent , form = form ):
41- code = transpile (input_path , indent , form )
43+ code = transpile (input_path , indent , form , raise_on_error = True )
4244 self .assertIsNotNone (code )
4345 self .assertIsInstance (code , str )
4446 self .assertGreater (len (code ), 0 )
0 commit comments