-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure testing and directive block parsing (#59)
In this PR I have: 1. Restructured the test folder and added an `AstRenderer` and lower level tests for the source text to Markdown (mistletoe) AST. 2. Added `docs/develop/test_infrastructure.md` to explain the testing inrastructure. 3. Restructured the directive block parsing, to make it more modular/understandable and improved error checking and reporting. fixes #54, fixes #55, fixes #51
- Loading branch information
1 parent
ccf6a56
commit 1a1cd05
Showing
58 changed files
with
1,333 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Testing Infrastructure | ||
|
||
Where possible, additions to the code should be carried out in a | ||
[test-driven development](https://en.wikipedia.org/wiki/Test-driven_development) | ||
manner: | ||
|
||
> **Write failing tests that the code should pass, then write code to pass the tests**. | ||
The tests are run using [pytest](https://docs.pytest.org)/[TravisCI](https://travis-ci.org) for unit tests, and [sphinx-build](https://www.sphinx-doc.org/en/master/man/sphinx-build.html)/[CircleCI](https://circleci.com) for documentation build tests. | ||
|
||
The tests are ordered in a hierarchical fashion: | ||
|
||
1. In `tests/test_syntax` are tests that check that the source text is being correctly converted to the Markdown ([mistletoe](https://github.com/miyuchina/mistletoe)) AST. | ||
2. In `tests/test_commonmark` the [CommonMark](https://github.com/commonmark/CommonMark.git) test set is run; to check that the parser is complying with the CommonMark specification. | ||
3. In `tests/test_renderers` are tests that check that the Markdown AST is being correctly converted to the docutils/sphinx AST. This includes testing that roles and directives are correctly parsed and run. | ||
4. In `tests/test_sphinx` are tests that check that minimal sphinx project builds are running correctly, to convert myst markdown files to HTML. | ||
5. In `.circleci` the package documentation (written in myst format) is built and tested for build errors/warnings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Abstract syntax tree renderer for myst.""" | ||
from itertools import chain | ||
import json | ||
|
||
from mistletoe import block_token, span_token | ||
from mistletoe import ast_renderer | ||
|
||
from myst_parser import span_tokens as myst_span_tokens | ||
from myst_parser import block_tokens as myst_block_tokens | ||
|
||
|
||
class AstRenderer(ast_renderer.ASTRenderer): | ||
def __init__(self): | ||
"""This AST render uses the same block/span tokens as the docutils renderer.""" | ||
|
||
_span_tokens = self._tokens_from_module(myst_span_tokens) | ||
_block_tokens = self._tokens_from_module(myst_block_tokens) | ||
|
||
super(ast_renderer.ASTRenderer, self).__init__( | ||
*chain(_block_tokens, _span_tokens) | ||
) | ||
|
||
span_token._token_types.value = _span_tokens | ||
block_token._token_types.value = _block_tokens | ||
|
||
def render(self, token, to_json=False): | ||
""" | ||
Returns the string representation of the AST. | ||
Overrides super().render. Delegates the logic to get_ast. | ||
""" | ||
ast = ast_renderer.get_ast(token) | ||
if to_json: | ||
return json.dumps(ast, indent=2) + "\n" | ||
return ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.