Skip to content

Commit 2fb07d0

Browse files
authored
Fix plugins tests. (#83)
1 parent eade29d commit 2fb07d0

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
"""Root class for testing plugins."""
2+
from plantuml import PlantUMLConnectionError
23
from .. import TestBase
34

45

6+
class MockPlantUML:
7+
"""Mocked PlantUML class."""
8+
9+
def __init__(self, url=''):
10+
"""Make new instance."""
11+
self.url = url
12+
13+
def processes(self, _text):
14+
"""Emulate call."""
15+
if not self.url.startswith('http://'):
16+
raise PlantUMLConnectionError("Only absolute URIs are allowed.")
17+
18+
return open("fixture/plantuml.png", "rb").read()
19+
20+
521
class TestPlugin(TestBase):
622
"""Base class for tests plugins."""

tests/test/test_plugins/test_init.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
make test T=test_plugins/test_init.py
44
"""
5-
from . import TestPlugin
5+
from . import TestPlugin, MockPlantUML
66

77

88
class TestInit(TestPlugin):
@@ -12,6 +12,7 @@ def test_md(self):
1212
"""Process md with plantuml content."""
1313
from markdown_pdf import Section, MarkdownPdf
1414
from markdown_pdf.pligins import Plugin
15+
from markdown_pdf.pligins import plantuml
1516

1617
pdf = MarkdownPdf()
1718
assert not pdf.plugins
@@ -20,6 +21,9 @@ def test_md(self):
2021
assert "@startuml" in html
2122
pdf.save(self.build("plantuml.pdf"))
2223

24+
saved = plantuml.PlantUML
25+
plantuml.PlantUML = MockPlantUML
26+
2327
plugins = {
2428
Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
2529
}
@@ -29,6 +33,8 @@ def test_md(self):
2933
html = pdf.add_section(Section(text))
3034
assert "@startuml" not in html
3135

36+
plantuml.PlantUML = saved
37+
3238
def test_get_plugin_chunks(self):
3339
"""Check get_plugin_chunks function."""
3440
from markdown_pdf.pligins import Plugin, get_plugin_chunks

tests/test/test_plugins/test_plantuml.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
import pytest
66
from plantuml import PlantUML, PlantUMLConnectionError
7-
from . import TestPlugin
7+
from . import TestPlugin, MockPlantUML
88

99
UML_CODE = """
1010
@startuml
@@ -14,21 +14,6 @@
1414
"""
1515

1616

17-
class MockPlantUML:
18-
"""Mocked PlantUML class."""
19-
20-
def __init__(self, url=''):
21-
"""Make new instance."""
22-
self.url = url
23-
24-
def processes(self, _text):
25-
"""Emulate call."""
26-
if not self.url.startswith('http://'):
27-
raise PlantUMLConnectionError("Only absolute URIs are allowed.")
28-
29-
return open("fixture/plantuml.png", "rb").read()
30-
31-
3217
class TesPlantuml(TestPlugin):
3318
"""Plantuml content."""
3419

0 commit comments

Comments
 (0)