Skip to content

Commit 1576631

Browse files
committed
polishing test suites
1 parent e1d7aa7 commit 1576631

File tree

5 files changed

+60
-26
lines changed

5 files changed

+60
-26
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
python-version: ${{ matrix.python }}
103103

104104
- name: Install dependencies
105-
run: pip install -r requirements.txt coveralls
105+
run: pip install -r requirements.txt coveralls GitPython
106106

107107
- name: Install project
108108
run: pip install .

fortran_tests/externalTestCode.config

Lines changed: 0 additions & 16 deletions
This file was deleted.

fortran_tests/testsuites.config

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[DEFAULT]
2+
suite: builtin
3+
options:
4+
5+
[UnitTests]
6+
obtain: shutil.copytree('../../examples/in', 'examples', dirs_exist_ok=True)
7+
path: examples
8+
suite: builtin
9+
10+
[RosettaCodeData]
11+
obtain: repo = git.Repo.clone_from("https://github.com/acmeism/RosettaCodeData.git", "RosettaCodeData", no_checkout=True); repo.git.checkout("29a5eea")
12+
path: RosettaCodeData
13+
suite: regular
14+
15+
[wannier90]
16+
obtain: git.Repo.clone_from("https://github.com/wannier-developers/wannier90", "wannier90", branch="v3.1.0")
17+
path: wannier90/src
18+
options: --indent 2
19+
suite: regular
20+
21+
[cp2k]
22+
obtain: git.Repo.clone_from("https://github.com/cp2k/cp2k.git", "cp2k", branch="v2024.1")
23+
path: cp2k/src
24+
options: --whitespace 2 --indent 3 --case 2 2 2 2
25+
suite: cron
26+
27+
[flap]
28+
obtain: git.Repo.clone_from("https://github.com/szaghi/FLAP", "FLAP", branch="v1.2.5")
29+
path: FLAP
30+
suite: regular

fprettify/tests/fortrantests.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,23 @@
3434

3535
fprettify.set_fprettify_logger(logging.ERROR)
3636

37-
def generate_suite(suitename):
37+
def generate_suite(suite=None, name=None):
38+
import git
3839
config = configparser.ConfigParser()
39-
config.read(joinpath(TEST_MAIN_DIR, 'externalTestCode.config'))
40+
config.read(joinpath(TEST_MAIN_DIR, 'testsuites.config'))
41+
42+
if suite is None and name is None:
43+
return None
4044

4145
for key in config.sections():
4246
code = config[key]
43-
if code['suite'] == suitename:
47+
if code['suite'] == suite or key == name:
4448
orig = os.getcwd()
4549
try:
4650
os.chdir(TEST_EXT_DIR)
4751

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

5661
def addtestcode(code_path, options):
62+
print(f"creating test cases from {code_path} ...")
5763
# dynamically create test cases from fortran files in test directory
5864
for dirpath, _, filenames in os.walk(joinpath(TEST_EXT_DIR, code_path)):
5965
for example in [f for f in filenames if any(f.endswith(_) for _ in fprettify.FORTRAN_EXTENSIONS)]:

run_tests.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,31 @@
3333
description='Run tests', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
3434
parser.add_argument("-r", "--reset", action='store_true', default=False,
3535
help="Reset test results to new results of failed tests")
36-
parser.add_argument("-s", "--suite", type=str, default="unittests", help="select suite.")
36+
parser.add_argument("-n", "--name", type=str, help="select tests by name (sections in testsuites.config).")
37+
38+
suite_default = ["unittests", "builtin"]
39+
parser.add_argument("-s", "--suite", type=str, default=suite_default, help="select suite.", choices=["unittests", "builtin", "regular", "cron", "custom"], action='append')
3740

3841
args = parser.parse_args()
3942

40-
if args.suite == "unittests":
41-
suite = unittest.TestLoader().loadTestsFromTestCase(FprettifyUnitTestCase)
43+
# remove defaults if user has specified anything
44+
if args.suite[:2] == suite_default and len(args.suite) > 2:
45+
args.suite = args.suite[2:]
46+
47+
if args.name:
48+
testCase = generate_suite(name=args.name)
4249
else:
43-
testCase = generate_suite(args.suite)
44-
suite = unittest.TestLoader().loadTestsFromTestCase(testCase)
50+
test_suite = unittest.TestSuite()
51+
for suite in args.suite:
52+
if suite == "unittests":
53+
test_loaded = unittest.TestLoader().loadTestsFromTestCase(FprettifyUnitTestCase)
54+
test_suite.addTest(test_loaded)
55+
else:
56+
testCase = generate_suite(suite=suite)
57+
test_loaded = unittest.TestLoader().loadTestsFromTestCase(testCase)
58+
test_suite.addTest(test_loaded)
4559

46-
unittest.TextTestRunner(verbosity=2).run(suite)
60+
unittest.TextTestRunner(verbosity=2).run(test_suite)
4761

4862
if args.reset and os.path.isfile(FAILED_FILE):
4963
sep_str = ' : '

0 commit comments

Comments
 (0)