File: test_asciidoc.py

package info (click to toggle)
pymarkups 4.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: python: 1,156; sh: 7; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# This file is part of python-markups test suite
# License: 3-clause BSD, see LICENSE file
# Copyright: (C) Dave Kuhlman, 2022

import unittest

from markups.asciidoc import AsciiDocMarkup


@unittest.skipUnless(
    AsciiDocMarkup.available(),
    "asciidoc.py and/or lxml not available",
)
class AsciiDocTextTest(unittest.TestCase):
    def test_basic(self) -> None:
        self.maxDiff = None
        markup = AsciiDocMarkup()
        converted = markup.convert(BASIC_TEXT)
        body = converted.get_document_body()
        title = converted.get_document_title()
        stylesheet = converted.get_stylesheet()
        title_expected = "Hello, world!"
        self.assertIn(CONTENT_PART_EXPECTED, body)
        self.assertEqual(title_expected, title)
        self.assertGreater(len(stylesheet), 100)

    def test_error_handling(self) -> None:
        markup = AsciiDocMarkup()
        with self.assertWarnsRegex(
            SyntaxWarning,
            "section title not allowed in list item",
        ):
            converted = markup.convert(INVALID_SYNTAX)
        self.assertIn("Foo", converted.get_document_body())

    def test_unicode(self) -> None:
        markup = AsciiDocMarkup()
        converted = markup.convert("Тест")
        body = converted.get_document_body()
        self.assertIn("Тест", body)


#
# =================================================================
#
# Data to be used for comparison of correct results.
#

BASIC_TEXT = """\
= Hello, world!
:toc:

== Some subtitle

This is an example *asciidoc* document.
"""

CONTENT_PART_EXPECTED = """\
<div id="content">
<div class="sect1">
<h2 id="_some_subtitle">Some subtitle</h2>
<div class="sectionbody">
<div class="paragraph"><p>This is an example <strong>asciidoc</strong> document.</p></div>
</div>
</div>
</div>
"""  # noqa: E501

INVALID_SYNTAX = """\
- Foo
+
= Bar
"""