Skip to content

Commit

Permalink
polishing test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
pseewald committed May 4, 2024
1 parent e1d7aa7 commit 1576631
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: pip install -r requirements.txt coveralls
run: pip install -r requirements.txt coveralls GitPython

- name: Install project
run: pip install .
Expand Down
16 changes: 0 additions & 16 deletions fortran_tests/externalTestCode.config

This file was deleted.

30 changes: 30 additions & 0 deletions fortran_tests/testsuites.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[DEFAULT]
suite: builtin
options:

[UnitTests]
obtain: shutil.copytree('../../examples/in', 'examples', dirs_exist_ok=True)
path: examples
suite: builtin

[RosettaCodeData]
obtain: repo = git.Repo.clone_from("https://github.com/acmeism/RosettaCodeData.git", "RosettaCodeData", no_checkout=True); repo.git.checkout("29a5eea")
path: RosettaCodeData
suite: regular

[wannier90]
obtain: git.Repo.clone_from("https://github.com/wannier-developers/wannier90", "wannier90", branch="v3.1.0")
path: wannier90/src
options: --indent 2
suite: regular

[cp2k]
obtain: git.Repo.clone_from("https://github.com/cp2k/cp2k.git", "cp2k", branch="v2024.1")
path: cp2k/src
options: --whitespace 2 --indent 3 --case 2 2 2 2
suite: cron

[flap]
obtain: git.Repo.clone_from("https://github.com/szaghi/FLAP", "FLAP", branch="v1.2.5")
path: FLAP
suite: regular
12 changes: 9 additions & 3 deletions fprettify/tests/fortrantests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@

fprettify.set_fprettify_logger(logging.ERROR)

def generate_suite(suitename):
def generate_suite(suite=None, name=None):
import git
config = configparser.ConfigParser()
config.read(joinpath(TEST_MAIN_DIR, 'externalTestCode.config'))
config.read(joinpath(TEST_MAIN_DIR, 'testsuites.config'))

if suite is None and name is None:
return None

for key in config.sections():
code = config[key]
if code['suite'] == suitename:
if code['suite'] == suite or key == name:
orig = os.getcwd()
try:
os.chdir(TEST_EXT_DIR)

if not os.path.isdir(code['path']):
print(f"obtaining {key} ...")
exec(code['obtain'])
finally:
os.chdir(orig)
Expand All @@ -54,6 +59,7 @@ def generate_suite(suitename):
return FprettifyTestCase

def addtestcode(code_path, options):
print(f"creating test cases from {code_path} ...")
# dynamically create test cases from fortran files in test directory
for dirpath, _, filenames in os.walk(joinpath(TEST_EXT_DIR, code_path)):
for example in [f for f in filenames if any(f.endswith(_) for _ in fprettify.FORTRAN_EXTENSIONS)]:
Expand Down
26 changes: 20 additions & 6 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,31 @@
description='Run tests', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-r", "--reset", action='store_true', default=False,
help="Reset test results to new results of failed tests")
parser.add_argument("-s", "--suite", type=str, default="unittests", help="select suite.")
parser.add_argument("-n", "--name", type=str, help="select tests by name (sections in testsuites.config).")

suite_default = ["unittests", "builtin"]
parser.add_argument("-s", "--suite", type=str, default=suite_default, help="select suite.", choices=["unittests", "builtin", "regular", "cron", "custom"], action='append')

args = parser.parse_args()

if args.suite == "unittests":
suite = unittest.TestLoader().loadTestsFromTestCase(FprettifyUnitTestCase)
# remove defaults if user has specified anything
if args.suite[:2] == suite_default and len(args.suite) > 2:
args.suite = args.suite[2:]

if args.name:
testCase = generate_suite(name=args.name)
else:
testCase = generate_suite(args.suite)
suite = unittest.TestLoader().loadTestsFromTestCase(testCase)
test_suite = unittest.TestSuite()
for suite in args.suite:
if suite == "unittests":
test_loaded = unittest.TestLoader().loadTestsFromTestCase(FprettifyUnitTestCase)
test_suite.addTest(test_loaded)
else:
testCase = generate_suite(suite=suite)
test_loaded = unittest.TestLoader().loadTestsFromTestCase(testCase)
test_suite.addTest(test_loaded)

unittest.TextTestRunner(verbosity=2).run(suite)
unittest.TextTestRunner(verbosity=2).run(test_suite)

if args.reset and os.path.isfile(FAILED_FILE):
sep_str = ' : '
Expand Down

0 comments on commit 1576631

Please sign in to comment.