Skip to content

Commit e80753f

Browse files
committed
the user have more control on the calls of test_plumed
1 parent c163ffa commit e80753f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/PlumedToHTML/PlumedToHTML.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def getPlumedSyntax( plumedexe ) :
5151
raise InvalidJSONError(ve)
5252
return keyword_dict
5353

54-
def test_and_get_html( inpt, name, actions=set({}) ) :
54+
def test_and_get_html( inpt, name, actions=set({}), test_plumed_kwargs={}) :
5555
"""
5656
Test if the plumed input is broken and generate the html syntax
5757
@@ -75,15 +75,15 @@ def test_and_get_html( inpt, name, actions=set({}) ) :
7575
iff.write(test_inpt + "\n")
7676
iff.close()
7777
# Now do the test
78-
broken = test_plumed( "plumed", filename, header="", printjson=True )
78+
broken = test_plumed( "plumed", filename, header="", printjson=True, **test_plumed_kwargs)
7979
# Retrieve the html that is output by plumed
8080
html = get_html( inpt, filename, filename, ("master",), (broken,), ("plumed",), actions=actions )
8181
# Remove the tempory files that we created
8282
if not keepfile : os.remove(filename)
8383

8484
return html
8585

86-
def test_plumed( executible, filename, header=[], printjson=False, jsondir="./", cmdTimeout:"None|float"=None, ghmarkdown=True ) :
86+
def test_plumed( executible, filename, header="", printjson=False, jsondir="./", cmdTimeout:"None|float"=None, ghmarkdown=True ) :
8787
"""
8888
Test if plumed can parse this input file
8989
@@ -136,7 +136,8 @@ def test_plumed( executible, filename, header=[], printjson=False, jsondir="./",
136136

137137
# write header and preamble to errfile
138138
with open(errfile,"w") as stderr:
139-
if len(header)>0 : print(header,file=stderr)
139+
if len(header)>0 :
140+
print(header,file=stderr)
140141
print("Stderr for source: ",re.sub("^data/","",filename)," ",file=stderr)
141142
print("Download: [zipped raw stdout](" + plumed_file + "." + executible + ".stdout.txt.zip) - [zipped raw stderr](" + plumed_file + "." + executible + ".stderr.txt.zip) ",file=stderr)
142143
if ghmarkdown : print("{% raw %}\n<pre style=\"overflow:scroll;\">",file=stderr)
@@ -449,7 +450,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
449450
else : raise Exception("Could not find toggler command for " + val)
450451
return html
451452

452-
def get_mermaid( executible, inpt, force ) :
453+
def get_mermaid( executible, inpt, force, test_plumed_kwargs={} ) :
453454
"""
454455
Generate the mermaid graph showing how data passes through PLUMED input file
455456
@@ -462,7 +463,7 @@ def get_mermaid( executible, inpt, force ) :
462463
iff.write(inpt+ "\n")
463464
iff.close()
464465
# Now check the input is OK
465-
broken = test_plumed( executible, "mermaid_plumed.dat", header="" )
466+
broken = test_plumed( executible, "mermaid_plumed.dat",**test_plumed_kwargs)
466467
if broken!=0 : raise Exception("invalid plumed input file -- cannot create mermaid graph")
467468
# Run mermaid
468469
cmd = [executible, 'show_graph', '--plumed', 'mermaid_plumed.dat', '--out', 'mermaid.md']
@@ -657,7 +658,8 @@ def compare_to_reference( output, reference ) :
657658

658659
return True
659660

660-
def processMarkdown( filename, plumedexe, plumed_names, actions, jsondir="./", ghmarkdown=True ) :
661+
def processMarkdown( filename, plumedexe, plumed_names, actions, jsondir="./", ghmarkdown=True,
662+
*,test_plumed_kwargs={} ) :
661663
"""
662664
Process a markdown file that contains PLUMED input files using PlumedtoHTML
663665
@@ -667,6 +669,7 @@ def processMarkdown( filename, plumedexe, plumed_names, actions, jsondir="./", g
667669
plumed_names -- the names of the plumed executibles to use in the badges
668670
actions -- names of actions used in the plumed inputs in this markdown file
669671
jsondir -- The directory in which to output the files containing the expansions of the shortcuts and the value dictionaries
672+
test_plumed_kwargs -- a dictionary of extra keywords to pass to the test_plumed utility, only "header" and "cmdTimeout" works
670673
"""
671674
if not os.path.exists(filename) :
672675
raise RuntimeError("Found no file called " + filename + " in lesson")
@@ -675,10 +678,13 @@ def processMarkdown( filename, plumedexe, plumed_names, actions, jsondir="./", g
675678
inp = f.read()
676679

677680
with open( filename, "w+" ) as ofile:
678-
ninputs, nfail = processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile, jsondir, ghmarkdown )
681+
ninputs, nfail = processMarkdownString( inp, filename, plumedexe, plumed_names,
682+
actions, ofile, jsondir, ghmarkdown, test_plumed_kwargs=test_plumed_kwargs )
679683
return ninputs, nfail
680684

681-
def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile, jsondir="./", ghmarkdown=True, checkaction="ignore", checkactionkeywords=set({}) ) :
685+
def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile,
686+
jsondir="./", ghmarkdown=True, checkaction="ignore", checkactionkeywords=set({}),
687+
*,test_plumed_kwargs={}) :
682688
"""
683689
Process a string of markdown that contains LUMED input files using PlumedtoHTML
684690
@@ -691,6 +697,7 @@ def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofil
691697
dirname -- the directory in which to find solution files
692698
ofile -- the file on which to output the processed markdown
693699
jsondir -- The directory in which to output the files containing the expansions of the shortcuts and the value dictionaries
700+
test_plumed_kwargs -- a dictionary of extra keywords to pass to the test_plumed utility, only "header" and "cmdTimeout" works
694701
"""
695702
dirname = os.path.dirname(filename)
696703
if dirname=="" : dirname = "."
@@ -782,12 +789,17 @@ def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofil
782789
# PlumedToHTML finds them when we do get_html (i.e. these will be in
783790
# the data directory where the calculation is run)
784791
if incomplete :
785-
success[i]=test_plumed(plumedexe[i], solutionfile, ghmarkdown=ghmarkdown )
792+
success[i]=test_plumed(plumedexe[i], solutionfile, ghmarkdown=ghmarkdown,
793+
**test_plumed_kwargs)
786794
else :
787795
success[i]=test_plumed(plumedexe[i], solutionfile,
788-
printjson=True, jsondir=jsondir, ghmarkdown=ghmarkdown )
796+
printjson=True, jsondir=jsondir, ghmarkdown=ghmarkdown,
797+
**test_plumed_kwargs)
789798
else :
790-
success[i]=test_plumed( plumedexe[i], solutionfile, ghmarkdown=ghmarkdown )
799+
success[i]=test_plumed( plumedexe[i],
800+
solutionfile,
801+
ghmarkdown=ghmarkdown,
802+
**test_plumed_kwargs,)
791803
if(success[i]!=0 and success[i]!="custom") : nfail[i] = nfail[i] + 1
792804
# Use PlumedToHTML to create the input with all the bells and whistles
793805
html = get_html(plumed_inp,

0 commit comments

Comments
 (0)