Skip to content

Commit

Permalink
feat: Pre-implement to render psuedxml from STDIN by module execute
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Feb 18, 2024
1 parent 1881ea5 commit 8e75e0d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
source .venv/bin/activate
pytest
pytest functests
build:
runs-on: ubuntu-latest
steps:
Expand Down
25 changes: 25 additions & 0 deletions functests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Test cases for CLI testing."""
import subprocess


def test_with_npm():
"""CLI I/O test with ``npm`` role."""
source = ":npm:`react`"
expected = (
"\n".join(
[
'<document source="<stdin>">',
" <paragraph>",
' <reference refuri="https://www.npmjs.com/package/react">',
" react",
]
)
+ "\n"
)
proc = subprocess.run(
["python", "-m", "rst_multi_refs"],
input=source.encode(),
stdout=subprocess.PIPE,
)
assert proc.returncode == 0
assert proc.stdout == expected.encode()
36 changes: 36 additions & 0 deletions src/rst_multi_refs/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""CLI entrypoint for simple testing by users.
.. note:: Current implementatoin is stub to pass functests.
"""
from typing import List, Optional

from docutils import nodes
from docutils.core import publish_cmdline
from docutils.parsers.rst import roles
from docutils.parsers.rst.states import Inliner


def npm_reference_role(
role: str,
rawtext: str,
text: str,
lineno: int,
inliner: Inliner,
options: Optional[dict] = None,
content: Optional[List[str]] = None,
):
"""Parse ``npm`` role."""
options = roles.normalized_role_options(options)
messages = []
url = f"https://www.npmjs.com/package/{text}"
return [nodes.reference(rawtext, text, refuri=url, **options)], messages


def configure():
"""Set up using roles."""
roles.register_canonical_role("npm", npm_reference_role)
pass


configure()
publish_cmdline()

0 comments on commit 8e75e0d

Please sign in to comment.