1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
# pylint: skip-file
# type: ignore
#
# tests.test_syntax_functions.py is part of the docformatter project
#
# Copyright (C) 2012-2023 Steven Myint
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module for testing functions that deal with syntax.
This module contains tests for syntax functions. Syntax functions are
those:
do_clean_link()
do_find_directives()
do_find_links()
do_skip_link()
"""
# Third Party Imports
import pytest
# docformatter Package Imports
import docformatter
class TestURLHandlers:
"""Class for testing the URL handling functions.
Includes tests for:
- do_clean_link()
- do_find_links()
- do_skip_link()
"""
@pytest.mark.unit
def test_find_in_line_link(self):
"""Should find link pattern in a text block."""
assert [(53, 162)] == docformatter.do_find_links(
"The text file can be retrieved via the Chrome plugin `Get \
Cookies.txt <https://chrome.google.com/webstore/detail/get-\
cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid>` while browsing."
)
assert [(95, 106), (110, 123)] == docformatter.do_find_links(
"``pattern`` is considered as an URL only if it is parseable as such\
and starts with ``http://`` or ``https://``."
)
@pytest.mark.unit
def test_skip_link_with_manual_wrap(self):
"""Should skip a link that has been manually wrapped by the user."""
assert docformatter.do_skip_link(
"``pattern`` is considered as an URL only if it is parseable as such\
and starts with ``http://`` or ``https://``.",
(95, 106),
)
assert docformatter.do_skip_link(
"``pattern`` is considered as an URL only if it is parseable as such\
and starts with ``http://`` or ``https://``.",
(110, 123),
)
@pytest.mark.unit
def test_do_clean_link(self):
"""Should remove line breaks from links."""
assert (
" `Get Cookies.txt <https://chrome.google.com/webstore/detail/get-cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid>`"
) == docformatter.do_clean_url(
"`Get \
Cookies.txt <https://chrome.google.com/webstore/detail/get-\
cookiestxt/bgaddhkoddajcdgocldbbfleckgcbcid>`",
" ",
)
assert (
" `custom types provided by Click <https://click.palletsprojects.com/en/8.1.x/api/?highlight=intrange#types>`_."
) == docformatter.do_clean_url(
"`custom types provided by Click\
<https://click.palletsprojects.com/en/8.1.x/api/?highlight=intrange#types>`_.",
" ",
)
class TestreSTHandlers:
"""Class for testing the reST directive handling functions.
Includes tests for:
- do_find_directives()
"""
@pytest.mark.unit
def test_find_in_line_directives(self):
"""Should find reST directieves in a text block."""
assert docformatter.do_find_directives(
"These are some reST directives that need to be retained even if it means not wrapping the line they are found on.\
Constructs and returns a :class:`QuadraticCurveTo <QuadraticCurveTo>`.\
Register ``..click:example::`` and ``.. click:run::`` directives, augmented with ANSI coloring."
)
@pytest.mark.unit
def test_find_double_dot_directives(self):
"""Should find reST directives preceeded by .."""
assert docformatter.do_find_directives(
".. _linspace API: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html\
.. _arange API: https://numpy.org/doc/stable/reference/generated/numpy.arange.html\
.. _logspace API: https://numpy.org/doc/stable/reference/generated/numpy.logspace.html"
)
assert docformatter.do_find_directives(
"``pattern`` is considered as an URL only if it is parseable as such"
"and starts with ``http://`` or ``https://``."
""
".. important::"
""
"This is a straight `copy of the functools.cache implementation"
"<https://github.com/python/cpython/blob/55a26de6ba938962dc23f2495723cf0f4f3ab7c6/Lib/functools.py#L647-L653>`_,"
"hich is only `available in the standard library starting with Python v3.9"
"<https://docs.python.org/3/library/functools.html?highlight=caching#functools.cache>`."
)
@pytest.mark.unit
def test_find_double_backtick_directives(self):
"""Should find reST directives preceeded by ``."""
assert docformatter.do_find_directives(
"By default we choose to exclude:"
""
"``Cc``"
" Since ``mailman`` apparently `sometimes trims list members"
" <https://mail.python.org/pipermail/mailman-developers/2002-September/013233.html>`_"
" from the ``Cc`` header to avoid sending duplicates. Which means that copies of mail"
" reflected back from the list server will have a different ``Cc`` to the copy saved by"
" the MUA at send-time."
""
"``Bcc``"
" Because copies of the mail saved by the MUA at send-time will have ``Bcc``, but copies"
" reflected back from the list server won't."
""
"``Reply-To``"
" Since a mail could be ``Cc``'d to two lists with different ``Reply-To`` munging"
"options set."
)
|