Skip to content

Commit 65df920

Browse files
committed
Fix tests on Python 3.10
1 parent 2f4c93a commit 65df920

File tree

6 files changed

+668
-672
lines changed

6 files changed

+668
-672
lines changed

domdf_python_tools/testing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"not_pypy",
6363
"only_pypy",
6464
"pytest_report_header",
65+
"PEP_563",
6566
]
6667

6768
MarkDecorator.__module__ = "_pytest.mark"
@@ -379,3 +380,11 @@ def pytest_report_header(config, startdir):
379380
"""
380381

381382
return f"Test session started at {datetime.datetime.now():%H:%M:%S}"
383+
384+
385+
PEP_563: bool = (sys.version_info[:2] >= (3, 10))
386+
"""
387+
:py:obj:`True` if the current Python version implements :pep:`563` -- Postponed Evaluation of Annotations
388+
389+
.. versionadded:: 1.4.2
390+
"""

domdf_python_tools/utils.py

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
8787

8888
# 3rd party
89-
import consolekit.utils
9089
import deprecation # type: ignore
9190
from packaging import version
9291

@@ -605,11 +604,73 @@ def check_dependencies(dependencies: Iterable[str], prt: bool = True) -> List[st
605604
return missing_modules
606605

607606

608-
coloured_diff = deprecated(
609-
deprecated_in="1.4.0",
610-
removed_in="2.0.0",
611-
current_version=__version__,
612-
details="Import from :mod:`consolekit.utils` (v0.3.0 or later) instead.",
613-
)(
614-
consolekit.utils.coloured_diff
615-
)
607+
def coloured_diff(
608+
*args,
609+
**kwargs,
610+
) -> str:
611+
r"""
612+
Compare two sequences of lines; generate the delta as a unified diff.
613+
614+
Unified diffs are a compact way of showing line changes and a few
615+
lines of context. The number of context lines is set by ``n`` which
616+
defaults to three.
617+
618+
By default, the diff control lines (those with ``---``, ``+++``, or ``@@``)
619+
are created with a trailing newline. This is helpful so that inputs
620+
created from ``file.readlines()`` result in diffs that are suitable for
621+
``file.writelines()`` since both the inputs and outputs have trailing
622+
newlines.
623+
624+
For inputs that do not have trailing newlines, set the lineterm
625+
argument to ``''`` so that the output will be uniformly newline free.
626+
627+
The unidiff format normally has a header for filenames and modification
628+
times. Any or all of these may be specified using strings for
629+
``fromfile``, ``tofile``, ``fromfiledate``, and ``tofiledate``.
630+
The modification times are normally expressed in the ISO 8601 format.
631+
632+
**Example:**
633+
634+
>>> for line in coloured_diff('one two three four'.split(),
635+
... 'zero one tree four'.split(), 'Original', 'Current',
636+
... '2005-01-26 23:30:50', '2010-04-02 10:20:52',
637+
... lineterm=''):
638+
... print(line) # doctest: +NORMALIZE_WHITESPACE
639+
--- Original 2005-01-26 23:30:50
640+
+++ Current 2010-04-02 10:20:52
641+
@@ -1,4 +1,4 @@
642+
+zero
643+
one
644+
-two
645+
-three
646+
+tree
647+
four
648+
649+
:param a:
650+
:param b:
651+
:param fromfile:
652+
:param tofile:
653+
:param fromfiledate:
654+
:param tofiledate:
655+
:param n:
656+
:param lineterm:
657+
:param removed_colour: The :class:`~consolekit.terminal_colours.Colour` to use for lines that were removed.
658+
:param added_colour: The :class:`~consolekit.terminal_colours.Colour` to use for lines that were added.
659+
660+
.. versionadded:: 0.3.0
661+
662+
.. deprecated:: 1.4.0
663+
664+
Will be removed in versiion 2.0.0. Import from :mod:`consolekit.utils` (v0.3.0 or later) instead.
665+
"""
666+
667+
# 3rd party
668+
import consolekit.utils
669+
670+
warnings.warn(
671+
"domdf_python_tools.utils.coloured_diff is deprecated since v1.4.0 and will be removed in v2.0.0. "
672+
"Import from consolekit.utils (v0.3.0 or later) instead.",
673+
DeprecationWarning,
674+
)
675+
676+
return consolekit.utils.coloured_diff(*args, **kwargs)

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ coverage>=5.1
22
coverage-pyver-pragma>=0.0.6
33
faker>=4.1.2
44
iniconfig!=1.1.0,>=1.0.1
5-
pandas>=1.0.0; implementation_name == "cpython" and python_version < "3.9"
5+
pandas>=1.0.0; implementation_name == "cpython" and python_version < "3.10"
66
pytest>=6.0.0
77
pytest-cov>=2.8.1
88
pytest-randomly>=3.3.1

tests/seq_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import pytest
1919

2020
# this package
21+
from domdf_python_tools.iterative import Len
2122
from domdf_python_tools.testing import not_pypy
22-
from domdf_python_tools.utils import Len
2323

2424

2525
class _ALWAYS_EQ:

tests/test_doctools.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
operator_docstrings,
2525
prettify_docstrings
2626
)
27-
from domdf_python_tools.testing import max_version
27+
from domdf_python_tools.testing import PEP_563, max_version
2828

2929
# TODO: test sphinxification of docstrings
3030

@@ -221,7 +221,16 @@ def test_decorators():
221221
# Functions
222222
assert undocumented_function.__doc__ == documented_function.__doc__
223223
assert undocumented_function.__name__ == "undocumented_function"
224-
assert undocumented_function.__annotations__ == {'a': float, 'b': float, 'c': float, 'd': int, "return": float}
224+
225+
if PEP_563:
226+
assert undocumented_function.__annotations__ == {
227+
'a': "float", 'b': "float", 'c': "float", 'd': "int", "return": "float"
228+
}
229+
else:
230+
assert undocumented_function.__annotations__ == {
231+
'a': float, 'b': float, 'c': float, 'd': int, "return": float
232+
}
233+
225234
assert partially_documented_function.__doc__.startswith(
226235
"This function works like ``documented_function`` except it returns the result telepathically.",
227236
)

0 commit comments

Comments
 (0)