I didn't like the other figure + figcaption parsers, they either assumed a lot about usage (e.g. images only), or they were inline parsers that either wrapped the figure in a paragraph tag (which is incorrect syntax) or did span trickery (annoying) so, this handles images and maybe other things, and does things properly with figures as their own blocks. incomplete but it works with my images, and should allow for looping (for multi-line content) in the future?
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""Test graphviz functionality."""
|
|
import os
|
|
|
|
from incorporealcms import create_app
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def app_with_pydot():
|
|
"""Create the test app, including the pydot extension."""
|
|
return create_app(instance_path=os.path.join(HERE, 'instance'),
|
|
test_config={'MARKDOWN_EXTENSIONS': ['incorporealcms.mdx.pydot']})
|
|
|
|
|
|
def test_functional_initialization():
|
|
"""Test initialization with the graphviz config."""
|
|
app = app_with_pydot()
|
|
assert app is not None
|
|
|
|
|
|
def test_graphviz_is_rendered():
|
|
"""Initialize the app with the graphviz extension and ensure it does something."""
|
|
app = app_with_pydot()
|
|
client = app.test_client()
|
|
|
|
response = client.get('/test-graphviz')
|
|
assert response.status_code == 200
|
|
assert b'~~~pydot' not in response.data
|
|
assert b'data:image/png;base64' in response.data
|
|
|
|
|
|
def test_invalid_graphviz_is_not_rendered():
|
|
"""Check that invalid graphviz doesn't blow things up."""
|
|
app = app_with_pydot()
|
|
client = app.test_client()
|
|
|
|
response = client.get('/test-invalid-graphviz')
|
|
assert response.status_code == 500
|
|
assert b'INTERNAL SERVER ERROR' in response.data
|
|
|
|
|
|
def test_figures_are_rendered(client):
|
|
"""Test that a page with my figure syntax renders as expected."""
|
|
response = client.get('/figures')
|
|
assert response.status_code == 200
|
|
assert (b'<figure class="right"><img alt="fancy captioned logo" src="bss-square-no-bg.png" />'
|
|
b'<figcaption>this is my cool logo!</figcaption></figure>') in response.data
|
|
assert (b'<figure><img alt="vanilla captioned logo" src="bss-square-no-bg.png" />'
|
|
b'<figcaption>this is my cool logo without an attr!</figcaption>\n</figure>') in response.data
|
|
assert (b'<figure class="left"><img alt="fancy logo" src="bss-square-no-bg.png" />'
|
|
b'<span></span></figure>') in response.data
|
|
assert b'<figure><img alt="just a logo" src="bss-square-no-bg.png" /></figure>' in response.data
|