Skip to content

Commit 065c997

Browse files
authored
Mermaid www test. (#88)
1 parent 39787d1 commit 065c997

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎.github/workflows/py3.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
env:
4949
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
5050
run: |
51-
pytest --cov=markdown_pdf --cov-report xml --cov-report term:skip-covered --durations=5 tests
51+
pytest -m "not external" --cov=markdown_pdf --cov-report xml --cov-report term:skip-covered --durations=5 tests
5252
if [ "$CODACY_PROJECT_TOKEN" != "" ]; then
5353
python-codacy-coverage -r coverage.xml
5454
fi
@@ -84,4 +84,4 @@ jobs:
8484
8585
- name: pytest
8686
run: |
87-
pytest --cov=markdown_pdf --cov-report xml --cov-report term:skip-covered --durations=5 tests
87+
pytest -m "not external" --cov=markdown_pdf --cov-report xml --cov-report term:skip-covered --durations=5 tests

‎makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pep257:
3636
$(PYTHON) -m pydocstyle $(SOURCE)
3737

3838
tests: flake8 pep257 lint
39-
$(PYTEST) --durations=5 $(TESTS)
39+
$(PYTEST) -m "not external" --durations=5 $(TESTS)
4040
$(COVERAGE) html --skip-covered
4141

4242
example:

‎pyproject.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ filterwarnings = [
5454
'ignore:builtin type SwigPyObject has no __module__ attribute:DeprecationWarning',
5555
'ignore:builtin type SwigPyPacked has no __module__ attribute:DeprecationWarning',
5656
]
57+
markers = [
58+
'external: marks a test as uses external resources'
59+
]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Mermaid plugin tests.
2+
3+
make test T=test_plugins/test_mermaid.py
4+
"""
5+
import base64
6+
import requests
7+
import pytest
8+
9+
from . import TestPlugin
10+
11+
MERMAID_CODE = """
12+
stateDiagram-v2
13+
[*] --> Still
14+
Still --> [*]
15+
16+
Still --> Moving
17+
Moving --> Still
18+
Moving --> Crash
19+
Crash --> [*]
20+
"""
21+
22+
23+
class TesMermaid(TestPlugin):
24+
"""Mermaid content."""
25+
26+
@pytest.mark.external
27+
def test_www(self):
28+
"""Make image for mermaid content."""
29+
# https://github.com/ouhammmourachid/mermaid-py
30+
response = requests.get(
31+
"https://mermaid.ink/img/{}".format(
32+
# Use URL-safe base64 encoding (replaces + with -, / with _)
33+
base64.urlsafe_b64encode(MERMAID_CODE.encode("utf-8")).decode("ascii"),
34+
),
35+
params={"format": "png"},
36+
timeout=5
37+
)
38+
assert len(response.content) > 0
39+
with open(self.build("test_mermaid.png"), "wb") as out:
40+
out.write(response.content)

‎tests/test/test_plugins/test_plantuml.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
class TesPlantuml(TestPlugin):
1818
"""Plantuml content."""
1919

20-
def _test_www(self):
20+
@pytest.mark.external
21+
def test_www(self):
2122
"""Make image for plantuml content."""
2223
server = PlantUML(url='http://www.plantuml.com/plantuml/img/')
2324
image = server.processes(UML_CODE)

0 commit comments

Comments
 (0)