File: test_public_api.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 (49 lines) | stat: -rw-r--r-- 2,209 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
# This file is part of python-markups test suite
# License: 3-clause BSD, see LICENSE file
# Copyright: (C) Dmitry Shachnev, 2012-2022

import importlib
import unittest

import markups
from markups.common import get_pygments_stylesheet


class APITest(unittest.TestCase):
    def test_api(self) -> None:
        all_markups = markups.get_all_markups()
        self.assertIn(markups.MarkdownMarkup, all_markups)
        self.assertIn(markups.ReStructuredTextMarkup, all_markups)
        self.assertIn(markups.AsciiDocMarkup, all_markups)
        markup_class = markups.find_markup_class_by_name("restructuredtext")
        self.assertEqual(markups.ReStructuredTextMarkup, markup_class)
        markup_class = markups.get_markup_for_file_name("myfile.mkd", return_class=True)
        self.assertEqual(markups.MarkdownMarkup, markup_class)
        markup_class = markups.get_markup_for_file_name(
            "myfile.adoc",
            return_class=True,
        )
        self.assertEqual(markups.AsciiDocMarkup, markup_class)

    @unittest.skipUnless(markups.MarkdownMarkup.available(), "Markdown not available")
    def test_api_instance(self) -> None:
        markup = markups.get_markup_for_file_name("myfile.mkd")
        self.assertIsInstance(markup, markups.MarkdownMarkup)

    @unittest.skipUnless(markups.MarkdownMarkup.available(), "Markdown not available")
    def test_available_markups(self) -> None:
        available_markups = markups.get_available_markups()
        self.assertIn(markups.MarkdownMarkup, available_markups)

    def test_get_pygments_stylesheet(self) -> None:
        try:
            importlib.import_module("pygments.formatters")
        except ImportError:
            raise unittest.SkipTest("Pygments not available")
        stylesheet = get_pygments_stylesheet(".selector")
        stylesheet = stylesheet.replace("#0000FF", "#00F")
        self.assertIn(".selector .nf { color: #00F", stylesheet)
        stylesheet = get_pygments_stylesheet(".selector", style="colorful")
        stylesheet = stylesheet.replace("#0066BB", "#06B")
        self.assertIn(".selector .nf { color: #06B", stylesheet)
        self.assertFalse(get_pygments_stylesheet(".selector", style=""))