Skip to content

Commit a358d69

Browse files
committed
improving test coverage
1 parent 53e6688 commit a358d69

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

open_fortran_parser/ofc_wrapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def execute_compiler(
2323
"""Run Open Fortran Compiler with given parameters."""
2424
assert isinstance(input_path, pathlib.Path), type(input_path)
2525
assert output_path is None or isinstance(output_path, pathlib.Path), type(output_path)
26-
assert isinstance(indent, int), type(indent)
27-
assert indent >= 0, indent
26+
assert indent is None or isinstance(indent, int), type(indent)
27+
assert indent is None or indent > 0, indent
2828
assert form is None or isinstance(form, CodeForm), type(form)
2929

3030
if ofc_config['path'] is not None:
@@ -53,8 +53,8 @@ def transpile(
5353
raise_on_error: bool = False) -> str:
5454
"""Parse given (possibly non-standard) Fortran code and return standard-compliant code."""
5555
assert isinstance(input_path, pathlib.Path), type(input_path)
56-
assert isinstance(indent, int), type(indent)
57-
assert indent >= 0, indent
56+
assert indent is None or isinstance(indent, int), type(indent)
57+
assert indent is None or indent > 0, indent
5858
assert form is None or isinstance(form, CodeForm), type(form)
5959

6060
process = execute_compiler(input_path, None, indent, form)

test/test_dependencies.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ def test_deps_script(self):
1818
@unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test')
1919
def test_deps(self):
2020
from open_fortran_parser.dependencies import DEV_DEPENDENCIES, ensure_dependencies
21-
for silent in (False, True):
22-
with tempfile.TemporaryDirectory() as temp_dir:
23-
ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=silent)
24-
self.assertGreater(len(os.listdir(temp_dir)), 0)
25-
26-
return
21+
with tempfile.TemporaryDirectory() as temp_dir:
22+
ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=False)
23+
self.assertGreater(len(os.listdir(temp_dir)), 0)
24+
with tempfile.TemporaryDirectory() as temp_dir:
25+
os.rmdir(temp_dir)
26+
ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=True)
27+
self.assertGreater(len(os.listdir(temp_dir)), 0)

test/test_ofc.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
import logging
44
import pathlib
55
import platform
6+
import tempfile
67
import 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

1515
INPUT_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

2120
class 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)

test/test_script.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Tests(unittest.TestCase):
2020

2121
maxDiff = None
2222

23+
def test_run_not_main(self):
24+
run_module('open_fortran_parser', 'some', 'bad', 'args', run_name='not_main')
25+
2326
def test_help(self):
2427
sio = io.StringIO()
2528
with contextlib.redirect_stderr(sio):

0 commit comments

Comments
 (0)