A [`unittest.TestCase`][] subclass with helpers for testing Markdown output. Define `default_kwargs` as a `dict` of keywords to pass to Markdown for each test. The defaults can be overridden on individual tests. The `assertMarkdownRenders` method accepts the source text, the expec
| 37 | |
| 38 | |
| 39 | class TestCase(unittest.TestCase): |
| 40 | """ |
| 41 | A [`unittest.TestCase`][] subclass with helpers for testing Markdown output. |
| 42 | |
| 43 | Define `default_kwargs` as a `dict` of keywords to pass to Markdown for each |
| 44 | test. The defaults can be overridden on individual tests. |
| 45 | |
| 46 | The `assertMarkdownRenders` method accepts the source text, the expected |
| 47 | output, and any keywords to pass to Markdown. The `default_kwargs` are used |
| 48 | except where overridden by `kwargs`. The output and expected output are passed |
| 49 | to `TestCase.assertMultiLineEqual`. An `AssertionError` is raised with a diff |
| 50 | if the actual output does not equal the expected output. |
| 51 | |
| 52 | The `dedent` method is available to dedent triple-quoted strings if |
| 53 | necessary. |
| 54 | |
| 55 | In all other respects, behaves as `unittest.TestCase`. |
| 56 | """ |
| 57 | |
| 58 | default_kwargs: dict[str, Any] = {} |
| 59 | """ Default options to pass to Markdown for each test. """ |
| 60 | |
| 61 | def assertMarkdownRenders(self, source, expected, expected_attrs=None, **kwargs): |
| 62 | """ |
| 63 | Test that source Markdown text renders to expected output with given keywords. |
| 64 | |
| 65 | `expected_attrs` accepts a `dict`. Each key should be the name of an attribute |
| 66 | on the `Markdown` instance and the value should be the expected value after |
| 67 | the source text is parsed by Markdown. After the expected output is tested, |
| 68 | the expected value for each attribute is compared against the actual |
| 69 | attribute of the `Markdown` instance using `TestCase.assertEqual`. |
| 70 | """ |
| 71 | |
| 72 | expected_attrs = expected_attrs or {} |
| 73 | kws = self.default_kwargs.copy() |
| 74 | kws.update(kwargs) |
| 75 | md = Markdown(**kws) |
| 76 | output = md.convert(source) |
| 77 | self.assertMultiLineEqual(output, expected) |
| 78 | for key, value in expected_attrs.items(): |
| 79 | self.assertEqual(getattr(md, key), value) |
| 80 | |
| 81 | def dedent(self, text): |
| 82 | """ |
| 83 | Dedent text. |
| 84 | """ |
| 85 | |
| 86 | # TODO: If/when actual output ends with a newline, then use: |
| 87 | # return textwrap.dedent(text.strip('/n')) |
| 88 | return textwrap.dedent(text).strip() |
| 89 | |
| 90 | |
| 91 | class recursionlimit: |
nothing calls this directly
no outgoing calls
no test coverage detected