Skip to content

Commit f8da620

Browse files
authored
Merge pull request #3341 from boegel/fix_avail_easyconfig_constants
fix crash in --avail-easyconfig-constants when using --output-format=rst + ensure sorted output
2 parents 40101f1 + af18600 commit f8da620

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

easybuild/tools/docs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def avail_easyconfig_constants(output_format=FORMAT_TXT):
143143
def avail_easyconfig_constants_txt():
144144
"""Generate easyconfig constant documentation in txt format"""
145145
doc = ["Constants that can be used in easyconfigs"]
146-
for cst, (val, descr) in EASYCONFIG_CONSTANTS.items():
146+
for cst, (val, descr) in sorted(EASYCONFIG_CONSTANTS.items()):
147147
doc.append('%s%s: %s (%s)' % (INDENT_4SPACES, cst, val, descr))
148148

149149
return '\n'.join(doc)
@@ -159,10 +159,12 @@ def avail_easyconfig_constants_rst():
159159
"Description",
160160
]
161161

162+
sorted_keys = sorted(EASYCONFIG_CONSTANTS)
163+
162164
table_values = [
163-
["``%s``" % cst for cst in EASYCONFIG_CONSTANTS.keys()],
164-
["``%s``" % cst[0] for cst in EASYCONFIG_CONSTANTS.values()],
165-
[cst[1] for cst in EASYCONFIG_CONSTANTS.values()],
165+
["``%s``" % key for key in sorted_keys],
166+
["``%s``" % str(EASYCONFIG_CONSTANTS[key][0]) for key in sorted_keys],
167+
[EASYCONFIG_CONSTANTS[key][1] for key in sorted_keys],
166168
]
167169

168170
doc = rst_title_and_table(title, table_titles, table_values)

test/framework/options.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,44 @@ def test_zzz_logtostdout(self):
412412
if os.path.exists(dummylogfn):
413413
os.remove(dummylogfn)
414414

415+
def test_avail_easyconfig_constants(self):
416+
"""Test listing available easyconfig file constants."""
417+
418+
def run_test(fmt=None):
419+
"""Helper function to test --avail-easyconfig-constants."""
420+
421+
args = ['--avail-easyconfig-constants']
422+
if fmt is not None:
423+
args.append('--output-format=%s' % fmt)
424+
425+
self.mock_stderr(True)
426+
self.mock_stdout(True)
427+
self.eb_main(args, verbose=True, raise_error=True)
428+
stderr, stdout = self.get_stderr(), self.get_stdout()
429+
self.mock_stderr(False)
430+
self.mock_stdout(False)
431+
432+
self.assertFalse(stderr)
433+
434+
if fmt == 'rst':
435+
pattern_lines = [
436+
r'^``HOME``.*',
437+
r'``OS_NAME``.*',
438+
r'``OS_PKG_IBVERBS_DEV``.*',
439+
]
440+
else:
441+
pattern_lines = [
442+
r'^\s*HOME:.*',
443+
r'\s*OS_NAME: .*',
444+
r'\s*OS_PKG_IBVERBS_DEV: .*',
445+
]
446+
447+
regex = re.compile('\n'.join(pattern_lines), re.M)
448+
self.assertTrue(regex.search(stdout), "Pattern '%s' should match in: %s" % (regex.pattern, stdout))
449+
450+
for fmt in [None, 'txt', 'rst']:
451+
run_test(fmt=fmt)
452+
415453
def test_avail_easyconfig_params(self):
416454
"""Test listing available easyconfig parameters."""
417455

0 commit comments

Comments
 (0)