File tree Expand file tree Collapse file tree 3 files changed +24
-17
lines changed
Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 11"""Root class for testing plugins."""
2+ from plantuml import PlantUMLConnectionError
23from .. 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+
521class TestPlugin (TestBase ):
622 """Base class for tests plugins."""
Original file line number Diff line number Diff line change 22
33make test T=test_plugins/test_init.py
44"""
5- from . import TestPlugin
5+ from . import TestPlugin , MockPlantUML
66
77
88class 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
Original file line number Diff line number Diff line change 44"""
55import pytest
66from plantuml import PlantUML , PlantUMLConnectionError
7- from . import TestPlugin
7+ from . import TestPlugin , MockPlantUML
88
99UML_CODE = """
1010@startuml
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-
3217class TesPlantuml (TestPlugin ):
3318 """Plantuml content."""
3419
You can’t perform that action at this time.
0 commit comments