-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code for rendering markdown files from tutorials to PlumedToHTML
- Loading branch information
Gareth Aneurin Tribello
committed
Oct 10, 2024
1 parent
7419546
commit 074cc82
Showing
5 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .PlumedToHTML import test_plumed, test_and_get_html, get_html, get_html_header, compare_to_reference, get_mermaid | ||
from .PlumedToHTML import test_plumed, test_and_get_html, get_html, get_html_header, compare_to_reference, get_mermaid, processMarkdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from unittest import TestCase | ||
|
||
import os | ||
import json | ||
import PlumedToHTML | ||
from bs4 import BeautifulSoup | ||
|
||
class TestPlumedToHTML(TestCase): | ||
def testBasicOutput(self) : | ||
# Open the json file and read it in | ||
f = open("tdata/tests.json") | ||
tests = json.load(f) | ||
f.close() | ||
|
||
# Now run over all the inputs in the json | ||
n=1 | ||
for item in tests["regtests"] : | ||
with self.subTest(item=item): | ||
print("INPUT", item["index"], item["input"] ) | ||
if "__FILL__" in item["input"] : continue | ||
with open("testmarkdown" + str(n) +".md", "w") as of : | ||
of.write("# TEST MARKDOWN \n\n") | ||
of.write("Some text before \n") | ||
of.write("```plumed`\n") | ||
of.write( item["input"] + "\n") | ||
of.write("```\n") | ||
of.write("Some text after \n") | ||
actions = set() | ||
PlumedToHTML.processMarkdown( "testmarkdown" + str(n) +".md", ("plumed",), ("master",), actions ) | ||
self.assertTrue( actions==set(item["actions"]) ) | ||
with open("testmarkdown" + str(n) +".md", "r") as f : inp = f.read() | ||
out, inhtml = "", False | ||
for line in inp.splitlines() : | ||
if inhtml and "{% endraw %}" in line : inhtml = False | ||
elif inhtml : out += line + "\n" | ||
elif "{% raw %}" in line : inhtml = True | ||
self.assertTrue( PlumedToHTML.compare_to_reference( out, item ) ) | ||
soup = BeautifulSoup( out, "html.parser" ) | ||
# Check the badges | ||
out_badges = soup.find_all("img") | ||
self.assertTrue( len(out_badges)==len(item["badges"]) ) | ||
for i in range(len(out_badges)) : | ||
if item["badges"][i]=="pass" : self.assertTrue( out_badges[i].attrs["src"].find("passing")>0 ) | ||
elif item["badges"][i]=="fail" : self.assertTrue( out_badges[i].attrs["src"].find("failed")>0 ) | ||
elif item["badges"][i]=="load" : self.assertTrue( out_badges[i].attrs["src"].find("with-LOAD")>0 ) | ||
elif item["badges"][i]=="incomplete" : self.assertTrue( out_badges[i].attrs["src"].find("incomplete")>0 ) | ||
n=n+1 | ||
|
||
with open("testmarkdown" + str(n) +".md", "w") as of : | ||
of.write("# TEST MARKDOWN \n\n") | ||
of.write("Some text before \n") | ||
of.write("```plumed`\n") | ||
of.write("#SOLUTIONFILE=tdata/solution.dat\n") | ||
of.write("d: DISTANCE __FILL__=1,2\n") | ||
of.write("```\n") | ||
of.write("Some text after \n") | ||
actions = set() | ||
PlumedToHTML.processMarkdown( "testmarkdown" + str(n) +".md", ("plumed",), ("master",), actions ) | ||
self.assertTrue( actions==set(["DISTANCE"]) ) | ||
|
||
|
||
def testHeader(self) : | ||
headerfilename = os.path.join(os.path.dirname(__file__),"../assets/header.html") | ||
hfile = open( headerfilename ) | ||
codes = hfile.read() | ||
hfile.close() | ||
self.assertTrue( codes==PlumedToHTML.get_html_header() ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
setuptools.setup( | ||
name='PlumedToHTML', | ||
version='0.75', | ||
version='0.76', | ||
author="Gareth Tribello", | ||
author_email="[email protected]", | ||
description="A package for creating pretified HTML for PLUMED files", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d: DISTANCE ATOMS=1,2 |