Add doctest support
This commit is contained in:
parent
03d8faca1a
commit
9647e91efc
5 changed files with 10 additions and 20 deletions
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
|
|
@ -27,14 +27,15 @@ jobs:
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python3 -m pip install --upgrade pip setuptools pytest pytest-cov pytest-subtests pytest-asyncio
|
python3 -m pip install --upgrade pip
|
||||||
|
pip install --upgrade --requirement dev-requirements.txt
|
||||||
pip install --upgrade .
|
pip install --upgrade .
|
||||||
|
|
||||||
- name: Check code and formatting
|
- name: Check code and formatting
|
||||||
run: scripts/check-python.sh .
|
run: scripts/check-python.sh .
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: python3 -m pytest --cov=. --cov-report=xml --junit-xml pytest.xml --asyncio-mode=strict || true
|
run: python3 -m pytest --doctest-modules --cov=. --cov-report=xml --junit-xml pytest.xml --asyncio-mode=strict || true
|
||||||
|
|
||||||
- name: Upload results
|
- name: Upload results
|
||||||
if: always()
|
if: always()
|
||||||
|
|
|
||||||
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
|
|
@ -20,9 +20,9 @@
|
||||||
{
|
{
|
||||||
"label": "Test",
|
"label": "Test",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "source .env/bin/activate && python3 -m pytest .",
|
"command": "source .env/bin/activate && python3 -m pytest . --doctest-modules",
|
||||||
"windows": {
|
"windows": {
|
||||||
"command": ".env\\bin\\activate.bat; python3 -m pytest ."
|
"command": ".env\\bin\\activate.bat; python3 -m pytest . --doctest-modules"
|
||||||
},
|
},
|
||||||
"group": "test",
|
"group": "test",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ convert a unicode string to LaTeX escape sequences.
|
||||||
For basic usage you can use the :py:func:`unicode_to_latex()` function
|
For basic usage you can use the :py:func:`unicode_to_latex()` function
|
||||||
directly::
|
directly::
|
||||||
|
|
||||||
>>> from pylatexenc.latexencode import unicode_to_latex
|
|
||||||
>>> print(unicode_to_latex('À votre santé'))
|
>>> print(unicode_to_latex('À votre santé'))
|
||||||
\`A votre sant\'e
|
\`A votre sant\'e
|
||||||
>>> print(unicode_to_latex('The length of samples #3 & #4 is 3μm'))
|
>>> print(unicode_to_latex('The length of samples #3 & #4 is 3μm'))
|
||||||
|
|
@ -41,21 +40,16 @@ you are converting multiple strings, you may create an instance with the flags
|
||||||
you like and invoke its method
|
you like and invoke its method
|
||||||
:py:meth:`~UnicodeToLatexEncoder.unicode_to_latex()` as many times as necessary::
|
:py:meth:`~UnicodeToLatexEncoder.unicode_to_latex()` as many times as necessary::
|
||||||
|
|
||||||
>>> from pylatexenc.latexencode import UnicodeToLatexEncoder
|
|
||||||
>>> u = UnicodeToLatexEncoder(unknown_char_policy='replace')
|
>>> u = UnicodeToLatexEncoder(unknown_char_policy='replace')
|
||||||
>>> print(u.unicode_to_latex('À votre santé'))
|
>>> print(u.unicode_to_latex('À votre santé'))
|
||||||
\`A votre sant\'e
|
\`A votre sant\'e
|
||||||
>>> print(u.unicode_to_latex('The length of samples #3 & #4 is 3μm'))
|
>>> print(u.unicode_to_latex('The length of samples #3 & #4 is 3μm'))
|
||||||
The length of samples \#3 \& \#4 is 3\ensuremath{\mu}m
|
The length of samples \#3 \& \#4 is 3\ensuremath{\mu}m
|
||||||
>>> print(u.unicode_to_latex('À votre santé: 乾杯'))
|
>>> print(u.unicode_to_latex('À votre santé: 乾杯'))
|
||||||
No known latex representation for character: U+4E7E - ‘乾’
|
|
||||||
No known latex representation for character: U+676F - ‘杯’
|
|
||||||
\`A votre sant\'e: {\bfseries ?}{\bfseries ?}
|
\`A votre sant\'e: {\bfseries ?}{\bfseries ?}
|
||||||
|
|
||||||
Example using custom conversion rules::
|
Example using custom conversion rules::
|
||||||
|
>>> import re
|
||||||
>>> from pylatexenc.latexencode import UnicodeToLatexEncoder, \
|
|
||||||
... UnicodeToLatexConversionRule, RULE_REGEX
|
|
||||||
>>> u = UnicodeToLatexEncoder(
|
>>> u = UnicodeToLatexEncoder(
|
||||||
... conversion_rules=[
|
... conversion_rules=[
|
||||||
... UnicodeToLatexConversionRule(rule_type=RULE_REGEX, rule=[
|
... UnicodeToLatexConversionRule(rule_type=RULE_REGEX, rule=[
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ database searches of LaTeX content.)
|
||||||
|
|
||||||
Simple example usage::
|
Simple example usage::
|
||||||
|
|
||||||
>>> from pylatexenc.latexwalker import LatexWalker, LatexEnvironmentNode
|
|
||||||
>>> w = LatexWalker(r"""
|
>>> w = LatexWalker(r"""
|
||||||
... \textbf{Hi there!} Here is \emph{a list}:
|
... \textbf{Hi there!} Here is \emph{a list}:
|
||||||
... \begin{enumerate}[label=(i)]
|
... \begin{enumerate}[label=(i)]
|
||||||
|
|
@ -45,12 +44,9 @@ Simple example usage::
|
||||||
... """)
|
... """)
|
||||||
>>> (nodelist, pos, len_) = w.get_latex_nodes(pos=0)
|
>>> (nodelist, pos, len_) = w.get_latex_nodes(pos=0)
|
||||||
>>> nodelist[0]
|
>>> nodelist[0]
|
||||||
LatexCharsNode(pos=0, len=1, chars='\n')
|
LatexCharsNode(parsing_state=..., pos=0, len=1, chars='\n')
|
||||||
>>> nodelist[1]
|
>>> nodelist[1]
|
||||||
LatexMacroNode(pos=1, len=18, macroname='textbf',
|
LatexMacroNode(parsing_state=..., pos=1, len=18, macroname='textbf', nodeargd=ParsedMacroArgs(argspec='{', argnlist=[LatexGroupNode(parsing_state=..., pos=8, len=11, nodelist=[LatexCharsNode(parsing_state=..., pos=9, len=9, chars='Hi there!')], delimiters=('{', '}'))]), macro_post_space='')
|
||||||
nodeargd=ParsedMacroArgs(argnlist=[LatexGroupNode(pos=8, len=11,
|
|
||||||
nodelist=[LatexCharsNode(pos=9, len=9, chars='Hi there!')],
|
|
||||||
delimiters=('{', '}'))], argspec='{'), macro_post_space='')
|
|
||||||
>>> nodelist[5].isNodeType(LatexEnvironmentNode)
|
>>> nodelist[5].isNodeType(LatexEnvironmentNode)
|
||||||
True
|
True
|
||||||
>>> nodelist[5].environmentname
|
>>> nodelist[5].environmentname
|
||||||
|
|
@ -58,8 +54,7 @@ Simple example usage::
|
||||||
>>> nodelist[5].nodeargd.argspec
|
>>> nodelist[5].nodeargd.argspec
|
||||||
'['
|
'['
|
||||||
>>> nodelist[5].nodeargd.argnlist
|
>>> nodelist[5].nodeargd.argnlist
|
||||||
[LatexGroupNode(pos=60, len=11, nodelist=[LatexCharsNode(pos=61, len=9,
|
[LatexGroupNode(parsing_state=..., pos=60, len=11, nodelist=[LatexCharsNode(parsing_state=..., pos=61, len=9, chars='label=(i)')], delimiters=('[', ']'))]
|
||||||
chars='label=(i)')], delimiters=('[', ']'))]
|
|
||||||
>>> nodelist[7].latex_verbatim()
|
>>> nodelist[7].latex_verbatim()
|
||||||
'$x$'
|
'$x$'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ def unique(
|
||||||
>>> unique([{'a': 1, 'b': 2}, {'a': 1, 'b': 3}], key=lambda v: v['a'])
|
>>> unique([{'a': 1, 'b': 2}, {'a': 1, 'b': 3}], key=lambda v: v['a'])
|
||||||
[{'a': 1, 'b': 2}]
|
[{'a': 1, 'b': 2}]
|
||||||
>>> unique([{'a': 1, 'b': 2}, {'a': 1, 'b': 3}], key=lambda v: v['b'])
|
>>> unique([{'a': 1, 'b': 2}, {'a': 1, 'b': 3}], key=lambda v: v['b'])
|
||||||
[{'a': 1, 'b': 3}, {'a': 1, 'b': 3}]
|
[{'a': 1, 'b': 2}, {'a': 1, 'b': 3}]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key_values = {}
|
key_values = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue