Commit Graph

426 Commits

Author SHA1 Message Date
Florian Bruhin 9f16a1f879 tests: Properly delete mode_manager instances
To fix a flaky tests/unit/utils/usertypes/test_timer.py::test_early_timeout_check
(where a download-update timer from an earlier test fails), I looked into what
usertypes.Timer instances where left over after a test finished.

It turns out that there were about 190 still existing "partial-match" and
"normal-inhibited" timers when breaking in test_timer.py, even when just running
tests in tests/unit/browser/ and tests/unit/utils/usertypes.

This is because we pass qapp as parent to the ModeManager we create, but that
means it will be forever alive if we don't take care of cleaning it up after a
test.

Perhaps our tests should have some sort of mechanism that checks whether there
are any "leftovers" after a test has finished (perhaps even as part of
pytest-qt?), but for now, let's just fix the issues we can directly see.
2025-05-07 13:22:10 +02:00
Florian Bruhin b5a399831b tests: Disable MAP_DISCARD workaround for fixed Qt versions 2025-04-08 19:42:16 +02:00
Florian Bruhin b0e05ee160 Qt 6.9: Only disable software rendering for darkmode tests
Looks like the "tests hanging" issue was fixed between Beta 3 and RC.

See #8444
2025-03-15 16:49:43 +01:00
Florian Bruhin b271559f82 tests: Fix without explicit platform 2025-03-12 15:02:22 +01:00
Florian Bruhin 51541add20 Fix lint 2025-03-12 14:44:19 +01:00
Florian Bruhin 328b5966ef Add initial support for running tests offscreen
Makes

    QT_QPA_PLATFORM=offscreen pytest

pass.

See #4914
2025-03-12 14:41:50 +01:00
Florian Bruhin 4cc67d3603 Qt 6.9: Force software rendering for tests
Not yet quite sure what exactly is the culprit, but this seems to help for all
tests (!) to pass with Xvfb locally.

For now only scoped to Qt 6.9.0. Will probably already need to reevaluate with
the RC, but definitely with the final release.

See #8444
2025-03-12 14:41:32 +01:00
Florian Bruhin c35fc88211 tests: Disable BPF sandbox with glibc 2.41
Fixes #8507
2025-03-12 11:29:12 +01:00
Florian Bruhin 990c4d4cfc tests: Adjust sandbox test expectations for Ubuntu 24.04
See #8424
2025-02-24 09:40:06 +01:00
Florian Bruhin eb8121ffd5 Use Callable from collections.abc as well
Did run with ruff pretending to use Python 3.10,
because otherwise it won't reformat those:

    ruff check --select 'UP035' --fix --config 'target-version = "py310"' --unsafe-fixes

This is because collections.abc.Callable inside Optional[...] and Union[...] is
broken with Python 3.9.0 and 3.9.1:

https://github.com/asottile/pyupgrade/issues/677
https://github.com/astral-sh/ruff/issues/2690
https://github.com/python/cpython/issues/87131

However, pylint can detect problematic usages (of which we only have one),
so we might as well use the new thing everywhere possible for consistency.

Also see #7098
2024-10-15 11:54:53 +02:00
Florian Bruhin 97104b2000 Use builtin list/dict/set/... types for annotations
See https://peps.python.org/pep-0585/
and https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections

Done via:

    ruff check --select 'UP006' --fix --config 'target-version = "py39"' --unsafe-fixes

followed by removing unused imports:

    ruff check --select 'F401' --fix --config 'target-version = "py39"'

and a semi-manual review to find imports that are still needed (but ruff doesn't know about yet):

    git diff | grep '^-' | grep import | grep -v "from typing"

Also see #7098.
2024-10-15 11:54:49 +02:00
Philipp Albrecht ff6668f295 Generalize (testdata) substitution in end2end tests
We replace the `(testdata)` placeholder with `testutils.abs_datapath()` in a few end2end
tests. So far we only needed to replace `(testdata)` with an OS path (e.g. in
`tests/end2end/features/spawn.feature`). By introducing `(testdata)` to an end2end test
in `tests/end2end/features/hints.feature`, we required a new use case: replacing
`(testdata)` as part of a valid file:// URI.

```
When I open file://(testdata)/some/file.txt
```

Replacing `(testdata)` in above BDD step with a plain OS path resulted in invalid URIs,
e.g. for the path "C:\\Users" above BDD step results in this invalid URI:

```
When I open file://C:\Users/some/file.txt
```

We deal with this by first isolating the `(testdata)` substitution in a single place.
Having `(testdata)` substitutions in a single place, we simply special-case the substitution
of file:// paths, which will be part of a URI.
Successful substitution for above BDD step looks like the following:

```
When I open file:///C:/Users/some/file.txt
```
2023-09-05 12:20:02 +02:00
Philipp Albrecht 3974725932 Normalize end2end data directory path
Given the following scenario:
```
When I open file://(testdata)/some/file.html
Then file://(testdata)/some/file.html should be loaded
```
If the end2end data directory is not normalized, the scenario fails because we try to
compare

```
file:///home/palbrecht/dev/qutebrowser/tests/helpers/../end2end/data/hints/link_inject.html?port=50…
```

to

```
file:///home/palbrecht/dev/qutebrowser/tests/end2end/data/hints/link_inject.html?port=50…
```

Normalizing the path resolves the `..` and fixes the issue.
2023-08-28 13:17:08 +02:00
toofar 36abc475d4 fix lint
Seems the new flake8 release is pulling down a (somewhat) new
pycodestyle that prefers is/is not over ==/!= when comparing exact
types. They should behave the same.

ref: #7807
2023-08-02 20:45:03 +12:00
Florian Bruhin 0718b25796 reuse: Initial copyright text update for myself
git ls-files | \
    xargs sed -Ei 's/Copyright [0-9]{4}(-[0-9]{4}) Florian Bruhin \(The Compiler\) <mail@qutebrowser\.org>/SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>/'
2023-07-23 12:49:05 +02:00
Florian Bruhin b2aaba6043 reuse: Adjust most license headers
git ls-files | xargs grep -l "is free software"  | xargs reuse annotate --license="GPL-3.0-or-later" --skip-unrecognised
2023-07-23 12:11:07 +02:00
Philipp Albrecht d9e8b638bf Remove vim modelines
We're deprecating vim modelines in favor of `.editorconfig`.

Removing vim modelines could be done using two one-liners. Most of the vim modelines
were followed by an empty line, so this one-liner took care of these ones:

```sh
rg '^# vim: .+\n\n' -l | xargs sed -i '/^# vim: /,+1d'
```

Then some of the vim modelines were followed by a pylint configuration line, so running
this one-liner afterwards took care of that:

```sh
rg '^# vim:' -l | xargs sed -i '/^# vim: /d'
```
2023-06-30 11:03:06 +02:00
Florian Bruhin 92243041c2 qt: Stop trying other wrappers on ImportError 2023-06-13 19:51:22 +02:00
Florian Bruhin 4793070db3 Merge branch 'qt6-v2' into master-qt6 2023-03-17 20:30:13 +01:00
toofar ff8dbc4580 lint: broad-exception-raised
Mostly pretty lazy fixes. Most of the places in the tests we were
already matching on error message, a couple of places we weren't. The
tick-tock one was the only one that wasn't being used right where it was
raised.

Some of them I just changed to RuntimeError because it was shorter than
adding the pylint directive.
2023-02-06 18:53:56 +13:00
toofar 2d66466194 Merge branch 'master' into qt6-v2
Just a few conflicts around CI and dependencies.
2022-11-20 15:48:00 +13:00
Florian Bruhin 6e54962fe4 pylint: Remove now-unneeded suppressions
The recent pytest 7.2 upgrade leads pylint to complain:

    ************* Module unit.browser.test_qutescheme
    tests/unit/browser/test_qutescheme.py:26:0: I0021: Useless suppression of 'no-name-in-module' (useless-suppression)
    tests/unit/browser/test_qutescheme.py:226:0: I0021: Useless suppression of 'no-member' (useless-suppression)

    ************* Module helpers.fixtures
    tests/helpers/fixtures.py:39:0: I0021: Useless suppression of 'no-name-in-module' (useless-suppression)
    tests/helpers/fixtures.py:639:0: I0021: Useless suppression of 'no-member' (useless-suppression)

possibly due to it not being able to infer 'py' anymore with the weird
shenanigans pytest does now?

Also, what weird glitch in the matrix is it that those just happen to be
on lines [2]26 and [6]39 for *both* files? 🤯
2022-11-08 18:27:21 +01:00
Florian Bruhin fa62360357 Remove unneeded str
Only needed in Python 3.5 times
2022-09-30 20:23:38 +02:00
Florian Bruhin 80961cee6b lint: Fix flake8 whitespace issues 2022-08-23 18:31:41 +02:00
Florian Bruhin e658ce6acf lint: Remove unused imports
Via autoflake and git add -p
2022-08-23 18:31:41 +02:00
Florian Bruhin c5a51eb0bc Drop Qt < 5.15
Fixes #7091

TODO: Add changelog
2022-08-23 18:31:41 +02:00
Florian Bruhin 437caf4516 qt 6: Fix getting enum members in tests 2022-08-23 18:31:41 +02:00
Florian Bruhin aa71f8f64f tests: Drop view.setPage(None)
This was added in e6ae8797e7 and it's unclear
whether it's still needed.

In any case, it won't work on Qt 6, as QWebEngineView::setPage does some more
work there:

https://github.com/qt/qtwebengine/blob/v5.15.9-lts/src/webenginewidgets/api/qwebengineview.cpp#L207-L210
https://github.com/qt/qtwebengine/blob/v6.3.0/src/webenginewidgets/api/qwebengineview.cpp#L659-L672

The connect() call there causes a segfault with:
QObject::connect(QWebEnginePage, QWebEngineView): invalid nullptr parameter

If we really still need this, we will either need to skip it with Qt 6, or
perhaps try sip.delete(view.page()) instead.
2022-08-23 18:31:41 +02:00
Florian Bruhin 916adc9ebe qt 6: Avoid QNetworkAccessManager::setNetworkAccessible 2022-08-23 18:31:41 +02:00
Florian Bruhin d387b1a108 tests: Adjust most imports 2022-08-23 18:31:40 +02:00
Florian Bruhin 236371cb1d Fix up various webkit/webengine imports 2022-08-23 18:31:40 +02:00
Florian Bruhin 0877fb0d78 Run scripts/dev/rewrite_enums.py 2022-08-23 18:31:38 +02:00
Florian Bruhin d47cfd99d7 Run scripts/dev/rewrite_qt_imports.sh 2022-08-23 18:09:11 +02:00
Florian Bruhin 5616a99eff Add a MessageInfo data class
Preparation for #7246
2022-06-14 17:05:23 +02:00
Florian Bruhin 7f1d92b596 Fix sandboxing test on Qt 5.12/QtWebKit/Windows 2022-03-06 23:05:13 +01:00
Florian Bruhin 44c7578bb2 tests: Disable seccomp BPF sandbox on older Chromiums
Seems to be necessary with newer libc (?) and Qt 5.12 plus 5.15.0/.1/.2.
2022-03-06 22:56:19 +01:00
Florian Bruhin 941627d778 Refactor tests to use new sandbox setting 2022-03-04 09:39:06 +01:00
Florian Bruhin f4714a9300 Use flake8-pytest-style 2022-01-04 10:30:24 +01:00
Florian Bruhin 4d13280994 pylint: Fix some legitimate issues 2021-12-03 12:04:59 +01:00
Florian Bruhin 100e87ff0e pylint: Remove now-useless suppressions 2021-12-02 17:43:45 +01:00
lufte 71a7674a70 Remove unused parameter and rename db 2021-07-09 10:06:24 -03:00
lufte 0c7b746a4e Restore the sql fixture to close DBs after testing 2021-07-09 01:10:36 -03:00
lufte 748c686bf0 Fix history unit tests 2021-06-30 21:00:43 -03:00
Florian Bruhin 8b49d87526 flatpak: Try getting ID from /.flatpak_info 2021-03-31 13:10:09 +02:00
Florian Bruhin 952402066d tests: Move flatpak patch to conftest 2021-03-31 13:10:09 +02:00
Florian Bruhin d31d63cc68 tests: Move freezer to fixtures.py 2021-03-29 23:42:14 +02:00
Florian Bruhin 577a653d94 tests: Base FakeProcess on a real QProcess
This way we can e.g. use the finished signal
2021-03-23 12:53:23 +01:00
Florian Bruhin 1ddbb2da9e Improve tests for guiprocess 2021-03-23 12:53:23 +01:00
Lembrun e8b05af233 Qtbot methods changed to snake case,snake case check added 2021-02-26 22:07:08 +01:00
Lembrun 0a453396c1 Rename utils.py to testutils.py 2021-02-25 21:28:56 +01:00