Commit Graph

50 Commits

Author SHA1 Message Date
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
François Freitag
53ca608bc0
linkcheck: Test redirect following for HEAD and GET 2020-11-11 18:32:53 +01:00
François Freitag
6ea0a123c6
Rename test-linkcheck-localserver{,-anchor}
Precise the `linkcheck_anchors` option is enabled. Frees the name
`test-linkcheck-localserver` for future tests without that option.
2020-11-11 18:32:52 +01:00
Takeshi KOMIYA
386929ec0f
Merge pull request #8409 from francoisfreitag/linkcheck-tests
linkcheck: Remove unused arguments from tests
2020-11-12 02:17:52 +09:00
François Freitag
c90eef1f67
linkcheck: Remove unused arguments from tests 2020-11-11 13:48:45 +01:00
François Freitag
0949735210
Sort imports with isort
Keep imports alphabetically sorted and their order homogeneous across
Python source files.

The isort project has more feature and is more active than the
flake8-import-order plugin.

Most issues caught were simply import ordering from the same module.
Where imports were purposefully placed out of order, tag with
isort:skip.
2020-11-11 13:19:05 +01:00
François Freitag
0178437f3c
Rewrite test_inspect_main_url to avoid mocking
Makes the test more realistic by issuing an HTTP request.
Reduces coupling between test and the code under test.

The `http_server` helper was factored out into a new tests.utils module.
2020-11-08 22:30:49 +01:00
François Freitag
5ea8ee133d
Fix #8268: make linkcheck report HTTP errors 2020-10-03 14:33:29 +02:00
Takeshi KOMIYA
f95ba21f4a Close #5208: linkcheck: Support checks for local links 2020-07-19 19:08:14 +09:00
Takeshi KOMIYA
a7725ad8ca Close #7247: linkcheck: Add linkcheck_request_headers 2020-06-01 01:48:46 +09:00
Takeshi KOMIYA
95b98d97d5 test: clean up 2020-03-01 17:44:10 +09:00
Wes Turner
fd94270f1c ENH: linkcheck: also write all links to output.json
* TST: linkcheck: make tests more flexible
* CLN: linkcheck: flake8, mypy
* REF: linkcheck: docpath->filename, write_jsonline->write_linkstat
* REF: linkcheck: remove redundant call to doc2path
* TST: linkcheck: show JSON obj structure in test
* REF: linkcheck: remove docname from JSON obj because it's redundant (use path2doc(filename) if necessary)
* TST: linkcheck: don't test row[info] output (see comments for examples)
2020-02-12 16:29:26 -05:00
Takeshi KOMIYA
4dd8b1022f test: Use read_text() and read_bytes() 2020-02-01 11:58:51 +09:00
Takeshi KOMIYA
eaf495c3c4 A happy new year! 2020-01-01 14:27:43 +09:00
Jonas Haag
df2f80c755 Add linkcheck_auth option 2019-11-25 09:53:45 +01:00
Takeshi KOMIYA
9b2c1c679a Fix #6444: test: replace example.com by existing page 2019-06-05 23:42:24 +09:00
Takeshi KOMIYA
f551915e9f Close #5196: linkcheck also checks remote images exist 2019-02-06 00:21:52 +09:00
Takeshi KOMIYA
76e9f57c2e Merge branch '1.8' 2019-01-02 16:16:25 +09:00
Takeshi KOMIYA
1b1ebd2c75 A happy new year! 2019-01-02 16:00:30 +09:00
Jon Dufresne
bade33c7e4 Remove unnecessary encoding cookie from Python source files
In Python 3, the default encoding of source files is utf-8. The encoding
cookie is now unnecessary and redundant so remove it. For more details,
see the docs:

https://docs.python.org/3/howto/unicode.html#the-string-type

> The default encoding for Python source code is UTF-8, so you can
> simply include a Unicode character in a string literal ...

Includes a fix for the flake8 header checks to stop expecting an
encoding cookie.
2018-12-16 12:22:12 -08:00
Takeshi KOMIYA
b56f4f9022 Remove print_function feature 2018-12-15 23:16:10 +09:00
Timotheus Kampik
f605012617 #4886 remove obsolete * 2018-07-17 20:40:49 +02:00
Timotheus Kampik
c126067f4e #4886 add tests
to better cover the current link check ignore configuration
 behavior
2018-07-16 23:17:44 +02:00
Takeshi KOMIYA
2426cedb8b A happy new year! 2018-01-01 01:06:58 +09:00
Takeshi KOMIYA
c57e47e042 Year++ 2017-03-26 11:49:34 +09:00
shimizukawa
baaef9146d pytest: remove deprecated with_app decorator functions 2017-01-06 01:14:47 +09:00
Darragh Bailey
22765990f0 Allow skipping anchor checking by regex
To avoid needing to turn off anchor checking across the entire
documentation allow skipping based on matching the anchor against a
regex.

Some sites/pages use JavaScript to perform anchor assignment in a
webpage, which would require rendering the page to determine whether
the anchor exists. Allow fine grain control of whether the anchor is
checked based on pattern matching, until such stage as the retrieved
URLs can be passed through an engine for deeper checking on the HTML
doctree.
2016-10-27 10:52:04 +01:00
Hiroaki Itoh
42604a1ff6 Fix #2990: linkcheck raises "Can't convert 'bytes' object to str implicitly" error if linkcheck_anchors enabled 2016-10-06 18:59:24 +09:00