Skip to content

Commit cd167fb

Browse files
committed
housekeeping
1 parent 2135eb8 commit cd167fb

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

open_fortran_parser/ofc_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CodeForm(enum.IntEnum):
2020
def execute_compiler(
2121
input_path: pathlib.Path, output_path: t.Optional[pathlib.Path],
2222
indent: int = 4, form: t.Optional[CodeForm] = None) -> subprocess.CompletedProcess:
23+
"""Run Open Fortran Compiler with given parameters."""
2324
assert isinstance(input_path, pathlib.Path), type(input_path)
2425
assert output_path is None or isinstance(output_path, pathlib.Path), type(output_path)
2526
assert isinstance(indent, int), type(indent)

test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Tests for open_fortran_parser package."""
12

23
import pathlib
34

test/test_apps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_miranda_io(self):
3737

3838
def test_flash(self):
3939
flash_relative_repo_path = pathlib.Path('..', 'flash-subset')
40-
flash_src_dir = _HERE.parent.joinpath(flash_relative_repo_path, 'FLASH4.4', 'source').resolve()
40+
flash_src_dir = _HERE.parent.joinpath(flash_relative_repo_path,
41+
'FLASH4.4', 'source').resolve()
4142
if not flash_src_dir.is_dir():
4243
self.skipTest('FLASH directory not found')
4344
tested_flash_kernel_paths = [

test/test_compatibility.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def all_fortran_paths(root_path: pathlib.Path):
2222
if not root_path.exists():
2323
return []
2424
all_input_paths = []
25-
for extension in itertools.chain(*[(_, _.upper()) for _ in ('.f', '.f90', '.f03', '.f08', '.h')]):
25+
for extension in itertools.chain(
26+
*[(_, _.upper()) for _ in ('.f', '.f90', '.f03', '.f08', '.h')]):
2627
input_paths = root_path.glob(
2728
f'**/*{extension}')
2829
for input_path in input_paths:
@@ -41,6 +42,7 @@ class Tests(unittest.TestCase):
4142
maxDiff = None
4243

4344
def check_cases(self, input_paths, relative=True):
45+
"""Try to parse all given files, fail on first failure."""
4446
for input_path in input_paths:
4547
if relative:
4648
input_path = _OFP_TESTS_DIR.joinpath(input_path).resolve()
@@ -65,6 +67,7 @@ def check_cases_and_report(
6567
success_reports_path: pathlib.Path, input_paths_root: pathlib.Path,
6668
input_paths: t.Sequence[pathlib.Path], minimum_passed_cases: int = None,
6769
fall_back_to_ofc: bool = False):
70+
"""Try to parse all given files, fail if there are not enough successes."""
6871
all_count = len(input_paths)
6972
if minimum_passed_cases is None:
7073
minimum_passed_cases = all_count
@@ -250,7 +253,7 @@ def test_ofp_do(self):
250253
'rule-tests/R843.f03']]
251254
self.check_cases(input_paths)
252255

253-
def test_ofp_do_concurrent_and_forall(self):
256+
def test_ofp_do_concurr_and_forall(self):
254257
input_paths = [pathlib.Path(_) for _ in [
255258
'annex_c/c_4_5.f03',
256259
'annex_c/c_4_6.f03',

test/test_ofc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import platform
66
import unittest
77

8-
from open_fortran_parser.ofc_wrapper import CodeForm, execute_compiler, transpile
8+
# CodeForm,
9+
from open_fortran_parser.ofc_wrapper import execute_compiler, transpile
910

1011
_LOG = logging.getLogger(__name__)
1112

test/test_script.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import io
55
import os
66
import pathlib
7-
import runpy
8-
import sys
97
import tempfile
108
import unittest
119

10+
from .test_setup import run_module
11+
1212
INPUT_PATH = pathlib.Path('test', 'examples', 'empty.f')
1313

1414

@@ -20,15 +20,11 @@ class Tests(unittest.TestCase):
2020

2121
maxDiff = None
2222

23-
def run_script(self, *args):
24-
sys.argv = ['open_fortran_parser'] + list(args)
25-
runpy.run_module('open_fortran_parser', run_name='__main__')
26-
2723
def test_help(self):
2824
f = io.StringIO()
2925
with contextlib.redirect_stderr(f):
3026
with self.assertRaises(SystemExit):
31-
self.run_script()
27+
run_module('open_fortran_parser')
3228
text = f.getvalue()
3329
self.assertIn('usage', text)
3430
self.assertIn('open_fortran_parser', text)
@@ -38,16 +34,16 @@ def test_verbosity_flag(self):
3834
for verbosity in verbosities:
3935
f = io.StringIO()
4036
with contextlib.redirect_stdout(f):
41-
self.run_script('-v', str(verbosity), str(INPUT_PATH))
37+
run_module('open_fortran_parser', '-v', str(verbosity), str(INPUT_PATH))
4238
self.assertGreater(len(f.getvalue()), 0)
4339

4440
def test_output_flag(self):
4541
output_file = tempfile.NamedTemporaryFile(delete=False)
4642
output_file.close()
4743
f = io.StringIO()
4844
with contextlib.redirect_stdout(f):
49-
self.run_script(str(INPUT_PATH))
50-
self.run_script(str(INPUT_PATH), output_file.name)
45+
run_module('open_fortran_parser', str(INPUT_PATH))
46+
run_module('open_fortran_parser', str(INPUT_PATH), output_file.name)
5147
with open(output_file.name) as output_file:
5248
self.assertEqual(normalize_newlines(f.getvalue()),
5349
normalize_newlines(output_file.read()))

0 commit comments

Comments
 (0)