Debian Codegraph @

test/test_parsers/test_rst/test_directives/test__init__.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 # $Id: test__init__.py 9277 2022-11-26 23:15:13Z milde $
3 # Author: Günter Milde <[email protected]>,
4 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
5 #
6 # Copying and distribution of this file, with or without modification,
7 # are permitted in any medium without royalty provided the copyright
8 # notice and this notice are preserved.
9 # This file is offered as-is, without any warranty.
10 #
11 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
12 """
13 Test module for `docutils.parsers.rst.directives`.
14 """
15
16 from pathlib import Path
17 import sys
18 import unittest
19
20 if __name__ == '__main__':
21 # prepend the "docutils root" to the Python library path
22 # so we import the local `docutils` package.
23 sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
24
25 import docutils
26 import docutils.parsers.null
27 from docutils.parsers.rst import directives
28
29
30 class DirectiveOptionConversionTestCase(unittest.TestCase):
31
32 def test_flag(self):
33 # Raise error when there is an argument:
34 self.assertEqual(None, directives.flag(''))
35 self.assertRaises(ValueError, directives.flag, 'alles')
36
37 def test_unchanged_required(self):
38 # Raise error when there is no argument:
39 self.assertRaises(ValueError, directives.unchanged_required, None)
40 self.assertEqual(3, directives.unchanged_required(3))
41
42 def test_unchanged(self):
43 self.assertEqual('', directives.unchanged(''))
44 self.assertTrue('something' == directives.unchanged('something'))
45 self.assertEqual(3, directives.unchanged(3))
46 self.assertEqual([3], directives.unchanged([3]))
47
48 # TODO: 13 more directive option conversion functions.
49
50 def test_parser_name(self):
51 self.assertEqual(directives.parser_name(None), None)
52 self.assertEqual(directives.parser_name('null'),
53 docutils.parsers.null.Parser)
54 self.assertEqual(directives.parser_name('rst'),
55 docutils.parsers.rst.Parser)
56 self.assertRaises(ValueError, directives.parser_name, 'fantasy')
57
58
59 if __name__ == '__main__':
60 unittest.main()