Commit Graph

77 Commits

Author SHA1 Message Date
Adam Turner
f4c8a0a68e Insert `from __future__ import annotations` 2023-01-01 20:48:37 +00:00
Adam Turner
b91f6617ed Enable Ruff's pylint 'PLC2201' check
Address all cases where the comparison order check is violated
2022-12-30 00:06:11 +00:00
Jean-François B
7418d2ccc4
Deactivate (provisorily) Python12-dev testing (#11035)
* fix flake8 warnings

* Deactivate (provisorily) testing with 3.12-dev

(refs:
https://github.com/sphinx-doc/sphinx/pull/10995#issuecomment-1330310586
)

* Escape # in tox.ini for tox 4 compatibility ('du-latest' tests)

Co-authored-by: Daniel Eades <danieleades@hotmail.com>
2022-12-16 12:41:54 +01:00
n-peugnet
1553cc3b36 linkcheck: Check the source URL of raw directives
Add raw directives' source URL to the list of links to check with linkcheck.
By the way, refactor HyperlinkCollector by adding `add_uri` function.
Add test for linkcheck raw directives source URL
2022-08-17 14:57:58 +02:00
Adam Turner
24e3b7c8c8 .read_text() -> .read_text(encoding='utf8') 2022-04-27 03:04:19 +01:00
Adam Turner
55669f6cfc Specify encoding 2022-04-22 04:21:12 +01:00
Adam Turner
5775912455 Collapse single line docstrings 2022-02-20 03:13:45 +00:00
Adam Turner
6bb7b891a1 Remove copyright and licence fields 2022-02-20 03:06:23 +00:00
Adam Turner
5694e0ce60 Fix module docstring indentation 2022-02-20 00:35:13 +00:00
Adam Turner
4f5a3269a6 Fix module docstring first line 2022-02-20 00:11:08 +00:00
Adam Turner
6b8bccec59 Remove module titles in docstrings 2022-02-19 23:17:29 +00:00
Takeshi KOMIYA
b84771dcd2 A happy new year! 2022-01-01 18:45:03 +09:00
Christian Roth
10023da895 linkcheck: Exclude links from matched documents 2021-12-08 10:01:45 +01:00
oleg.hoefling
36a6fcaef1
don't print file extension twice in linkcheck warnings
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2021-09-27 22:12:57 +02:00
Takeshi KOMIYA
a35b009adc Fix #9435: linkcheck: Failed to check anchors in github.com
The approach of `rewrite_github_anchor` makes some anchors valid.  But
it also makes other kind of anchors invalid.  This disables the handler
to make them valid again (while 4.1.x release).
2021-07-18 13:03:57 +09:00
Takeshi KOMIYA
5e5bca98f7
Merge branch '4.x' into 6525_linkcheck_warn_redirects 2021-07-07 02:09:50 +09:00
Takeshi KOMIYA
7e71b759d7
Merge branch '4.x' into 4.0.x 2021-06-13 17:20:01 +09:00
Justin Mathews
36c662eca5
positive test assertion
Co-authored-by: François Freitag <mail@franek.fr>
2021-06-10 11:43:14 -04:00
Justin Mathews
9b2a1e20e2
explicitly close the connection
Co-authored-by: François Freitag <mail@franek.fr>
2021-06-10 11:42:36 -04:00
Justin Mathews
134a8d8f54
reuse existing test link
Co-authored-by: François Freitag <mail@franek.fr>
2021-06-10 11:41:47 -04:00
Justin Mathews
a4621fb73e
test with http
Co-authored-by: François Freitag <mail@franek.fr>
2021-06-10 11:41:11 -04:00
Justin Mathews
db9adaceaf Trigger the bad web server behaviour with the http_server context manager instead of relying on an external website. 2021-06-09 23:40:40 -04:00
Justin Mathews
57c866caf1 catch ConnectionError on HEAD 2021-06-07 17:53:36 -04:00
Justin Mathews
84d4a5b97a failing test for linkcheck of US Patent page 2021-06-07 17:53:32 -04:00
Takeshi KOMIYA
92335bd6e6 Close #9016: linkcheck builder failed to check the anchors of github.com 2021-06-01 00:31:15 +09:00
Takeshi KOMIYA
988a79de65 linkcheck: Emit a warning for disallowed redirects
Now linkcheck builder integrates `linkcheck_warn_redirects` into
`linkcheck_allowed_redirects`.  As a result, linkcheck builder will
emit a warning when "disallowed" redirection detected via
`linkcheck_allowed_redirects`.
2021-05-31 21:53:09 +09:00
Takeshi KOMIYA
4201a84b35 Add testcase for combination of allow_redirects and warn_redirects 2021-05-21 02:04:01 +09:00
Takeshi KOMIYA
ce9e2e6c74 Rename linkcheck_ignore_redirects to linkcheck_allowed_redirects 2021-05-20 23:26:16 +09:00
Takeshi KOMIYA
707319aab2 Close #6525: linkcheck: Add linkcheck_ignore_redirects
Add a new confval; linkcheck_ignore_redirects to ignore hyperlinks
that are redirected as expected.
2021-05-16 02:48:03 +09:00
Takeshi KOMIYA
05eb2ca06f Close #6525: linkcheck: Add linkcheck_warn_redirects
Add a new confval; `linkcheck_warn_redirects` to emit a warning when
the hyperlink is redirected.  It's useful to detect unexpected redirects
under the warn-is-error mode.
2021-05-16 02:29:03 +09:00
Takeshi KOMIYA
26d9a8962e Fix the testcase for linkcheck refers removed URLs
Some public URLs are disabled now.
For more details, see https://github.com/sphinx-doc/sphinx/issues/8309
2021-03-27 17:10:09 +09:00
Takeshi KOMIYA
7252abab1c refactor: linkcheck: Refine the constructor of Checker and CheckWorker
Make the constructors of Checker and CheckWorker classes less-coupled
with linkcheck builder.
2021-02-12 23:20:07 +09:00
Takeshi KOMIYA
5c223d20d6 refactor: linkcheck: Separate thread manager feature from builder class
To reduce the complexity of the linkcheck builder, this separates
the thread manager feature from the builder class as
HyperlinkAvailabilityChecker.
2021-02-12 23:19:01 +09:00
Takeshi KOMIYA
f02fb7a8cc refactor: linkcheck: Separate worker feature from builder class
To reduce the complexity of the linkcheck builder, this separates
the worker feature from the builder class.
2021-02-05 22:52:28 +09:00
François Freitag
c7eb7cd127
Linkcheck: Use app.build() to trigger the test build
Instead of using application members to access the builder and trigger a
build, use the main app interface.
It ensures the builder setup is realistic, builder cleanups are executed
and the build-finished events are emitted.
2021-01-27 18:55:36 +01:00
Takeshi KOMIYA
cead0f6ddf linkcheck: Fix race condition that could lead to checking the availability of the same URL twice
So far, linkcheck scans all of references and images from documents, and
checks them parallel.  As a result, some URL would be checked twice (or
more) by race condition.

This collects the URL via post-transforms, and removes duplicated URLs
before checking availability.

refs: #4303
2021-01-20 20:58:27 +09:00
Takeshi KOMIYA
f996859420 A happy new year!
.. note::

   $ find sphinx tests LICENSE doc/conf.py -type f -exec sed -i '' -e 's/2007\-20../2007-2021/' {} \;
   $ git co sphinx/locale/**/*.js sphinx/templates/epub3/mimetype
2021-01-01 13:40:48 +09:00
François Freitag
a1b8b1febb
Ensure linkcheck items are comparable
Linkcheck organizes the URLs to checks in a PriorityQueue. The items are
tuples (priority, url, docname, lineno).

Tuples where the lineno is `None` are not comparable with tuples that
have an integer lineno, and PriorityQueue items must be comparable (see
https://bugs.python.org/issue31145).

Fixes an issue when a document contains two links to the same URL, one
with an int line number and the other without line number metadata (such
as an image :target: attribute).

Using 0 instead of None to represent no line number should not lead to
observable changes, the result logger only logs the line number when it
is truthy.

Close #8565
2020-12-22 21:18:31 +01:00
Jon Dufresne
c1437d5f79 Replace modify_env() with pytest monkeypatch.setenv()
The same test utility function is built into pytest. Can avoid the
duplication.

https://docs.pytest.org/en/latest/monkeypatch.html#monkeypatching-environment-variables
2020-11-27 14:10:36 -08:00
François Freitag
6b90a63f08 Fix #6629: linkcheck: Handle rate-limiting
Follow the Retry-After header if present, otherwise use an exponential
back-off.
2020-11-25 17:34:55 +01:00
Takeshi KOMIYA
046c289f76 linkcheck: Add a testcase for infinite redirect loop on HEAD request 2020-11-23 01:52:44 +09:00
François Freitag
419e145e36
Make tests/ a Python package
Allows relative imports.
2020-11-20 19:43:02 +01:00
Takeshi KOMIYA
21a3bd4127 refactor: Fix flake8 violations under tests/ directory 2020-11-15 17:15:40 +09:00
François Freitag
d453088b58
linkcheck: Prevent REQUESTS_CA_BUNDLE leak in tests
Test `test_connect_to_selfsigned_nonexistent_cert_file` serves two
purposes:
- verify the behavior when the CA bundle file path is incorrect
- flag a leak of REQUESTS_CA_BUNDLE

Assumes that test runs after
`test_connect_to_selfsigned_with_requests_env_var`. Not great, but
better than no testing.
2020-11-14 19:58:02 +01:00
Takeshi KOMIYA
a638658510
Merge pull request #8421 from francoisfreitag/test-self-signed
linkcheck: Verify behavior with self-signed certs
2020-11-14 21:15:13 +09:00
François Freitag
10e11f3133
linkcheck: Verify behavior with self-signed certs 2020-11-14 12:59:29 +01:00
François Freitag
99c8765822
linkcheck: Remove unused argument from test_invalid_ssl
Not updated after c90eef1f67.
2020-11-14 12:49:47 +01:00
François Freitag
040a1e7743 linkcheck: test invalid SSL is reported as broken
`linkcheck` logic suggests that SSL errors were originally expected to
be ignored.

Blaming the corresponding lines point to issue #3008: linkcheck to
website with self-signed certificates. That issue was fixed by commit
4c7bec6460, which ignored SSL errors.
Probably because back then, users could not specify a CA bundle.

A broken SSL certificate is a real issue, it should not be ignored.
Users wishing to ignore issues for a specific link can use the
`linkcheck_ignore` option.

The current behavior is to report the site as broken, keep it.
2020-11-12 19:58:04 +01:00
François Freitag
ce9d4c1e68
linkcheck: Rewrite headers tests without mocking
Makes the test more realistic by issuing an HTTP request.
Reduces coupling between test and the code under test.
2020-11-11 21:24:06 +01:00
François Freitag
341b98f794
linkcheck: Rewrite auth tests without mocking
Makes the test more realistic by issuing an HTTP request.
Reduces coupling between test and the code under test.
2020-11-11 21:22:59 +01:00