Add doctest support

This commit is contained in:
Andras Schmelczer 2022-07-04 14:22:00 +02:00
parent 411af60e57
commit 134fc780d4
5 changed files with 10 additions and 20 deletions

View file

@ -27,14 +27,15 @@ jobs:
- name: Install dependencies
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 .
- name: Check code and formatting
run: scripts/check-python.sh .
- 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
if: always()

4
.vscode/tasks.json vendored
View file

@ -20,9 +20,9 @@
{
"label": "Test",
"type": "shell",
"command": "source .env/bin/activate && python3 -m pytest .",
"command": "source .env/bin/activate && python3 -m pytest . --doctest-modules",
"windows": {
"command": ".env\\bin\\activate.bat; python3 -m pytest ."
"command": ".env\\bin\\activate.bat; python3 -m pytest . --doctest-modules"
},
"group": "test",
"presentation": {

View file

@ -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
directly::
>>> from pylatexenc.latexencode import unicode_to_latex
>>> print(unicode_to_latex('À votre santé'))
\`A votre sant\'e
>>> 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
:py:meth:`~UnicodeToLatexEncoder.unicode_to_latex()` as many times as necessary::
>>> from pylatexenc.latexencode import UnicodeToLatexEncoder
>>> u = UnicodeToLatexEncoder(unknown_char_policy='replace')
>>> print(u.unicode_to_latex('À votre santé'))
\`A votre sant\'e
>>> 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
>>> 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 ?}
Example using custom conversion rules::
>>> from pylatexenc.latexencode import UnicodeToLatexEncoder, \
... UnicodeToLatexConversionRule, RULE_REGEX
>>> import re
>>> u = UnicodeToLatexEncoder(
... conversion_rules=[
... UnicodeToLatexConversionRule(rule_type=RULE_REGEX, rule=[

View file

@ -34,7 +34,6 @@ database searches of LaTeX content.)
Simple example usage::
>>> from pylatexenc.latexwalker import LatexWalker, LatexEnvironmentNode
>>> w = LatexWalker(r"""
... \textbf{Hi there!} Here is \emph{a list}:
... \begin{enumerate}[label=(i)]
@ -45,12 +44,9 @@ Simple example usage::
... """)
>>> (nodelist, pos, len_) = w.get_latex_nodes(pos=0)
>>> nodelist[0]
LatexCharsNode(pos=0, len=1, chars='\n')
LatexCharsNode(parsing_state=..., pos=0, len=1, chars='\n')
>>> nodelist[1]
LatexMacroNode(pos=1, len=18, macroname='textbf',
nodeargd=ParsedMacroArgs(argnlist=[LatexGroupNode(pos=8, len=11,
nodelist=[LatexCharsNode(pos=9, len=9, chars='Hi there!')],
delimiters=('{', '}'))], argspec='{'), macro_post_space='')
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='')
>>> nodelist[5].isNodeType(LatexEnvironmentNode)
True
>>> nodelist[5].environmentname
@ -58,8 +54,7 @@ Simple example usage::
>>> nodelist[5].nodeargd.argspec
'['
>>> nodelist[5].nodeargd.argnlist
[LatexGroupNode(pos=60, len=11, nodelist=[LatexCharsNode(pos=61, len=9,
chars='label=(i)')], delimiters=('[', ']'))]
[LatexGroupNode(parsing_state=..., pos=60, len=11, nodelist=[LatexCharsNode(parsing_state=..., pos=61, len=9, chars='label=(i)')], delimiters=('[', ']'))]
>>> nodelist[7].latex_verbatim()
'$x$'

View file

@ -14,7 +14,7 @@ def unique(
>>> unique([{'a': 1, 'b': 2}, {'a': 1, 'b': 3}], key=lambda v: v['a'])
[{'a': 1, 'b': 2}]
>>> 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 = {}