From 134fc780d459937bce0f1d6a8e173ca998938286 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 4 Jul 2022 14:22:00 +0200 Subject: [PATCH] Add doctest support --- .github/workflows/test.yml | 5 +++-- .vscode/tasks.json | 4 ++-- .../external/pylatexenc/latexencode/__init__.py | 8 +------- .../external/pylatexenc/latexwalker/__init__.py | 11 +++-------- src/utilities/unique.py | 2 +- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c283e94..f572f6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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() diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3ad7159..9abc7ab 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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": { diff --git a/src/utilities/external/pylatexenc/latexencode/__init__.py b/src/utilities/external/pylatexenc/latexencode/__init__.py index 06f4a61..ce77cd7 100644 --- a/src/utilities/external/pylatexenc/latexencode/__init__.py +++ b/src/utilities/external/pylatexenc/latexencode/__init__.py @@ -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=[ diff --git a/src/utilities/external/pylatexenc/latexwalker/__init__.py b/src/utilities/external/pylatexenc/latexwalker/__init__.py index 4b12068..b60bd69 100644 --- a/src/utilities/external/pylatexenc/latexwalker/__init__.py +++ b/src/utilities/external/pylatexenc/latexwalker/__init__.py @@ -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$' diff --git a/src/utilities/unique.py b/src/utilities/unique.py index 58b852c..ac8a088 100644 --- a/src/utilities/unique.py +++ b/src/utilities/unique.py @@ -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 = {}