| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
"""test `docutils.parsers.get_parser_class()`""" |
| 9 |
|
| 10 |
from pathlib import Path |
| 11 |
import sys |
| 12 |
import unittest |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
DOCUTILS_ROOT = Path(__file__).resolve().parents[2] |
| 19 |
if str(DOCUTILS_ROOT) not in sys.path: |
| 20 |
sys.path.insert(0, str(DOCUTILS_ROOT)) |
| 21 |
|
| 22 |
from docutils.core import publish_string |
| 23 |
from docutils.parsers import get_parser_class |
| 24 |
try: |
| 25 |
md_parser_class = get_parser_class('recommonmark') |
| 26 |
except ImportError: |
| 27 |
md_parser_class = None |
| 28 |
|
| 29 |
|
| 30 |
class GetParserClassTestCase(unittest.TestCase): |
| 31 |
|
| 32 |
def test_registered_parsers(self): |
| 33 |
get_parser_class('null') |
| 34 |
get_parser_class('rst') |
| 35 |
get_parser_class('docutils_xml') |
| 36 |
|
| 37 |
|
| 38 |
def test_registered_parsers_case_folding(self): |
| 39 |
get_parser_class('reStructuredText') |
| 40 |
get_parser_class('XML') |
| 41 |
|
| 42 |
|
| 43 |
def test_bogus_parser(self): |
| 44 |
with self.assertRaises(ImportError): |
| 45 |
get_parser_class('nope') |
| 46 |
|
| 47 |
def test_local_parser(self): |
| 48 |
|
| 49 |
get_parser_class('test.local-parser') |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@unittest.skipUnless(md_parser_class is None, '"recommonmark" module found.') |
| 54 |
class RecommonmarkMissingTests(unittest.TestCase): |
| 55 |
|
| 56 |
def test_missing_parser_message(self): |
| 57 |
|
| 58 |
with self.assertRaisesRegex( |
| 59 |
ImportError, '(?s)requires the.*package .*recommonmark'): |
| 60 |
publish_string('test data', parser='recommonmark') |
| 61 |
|
| 62 |
|
| 63 |
if __name__ == '__main__': |
| 64 |
unittest.main() |