Commit graph

95 commits

Author SHA1 Message Date
Jelle van der Waa
fd00db13c5 pyproject: Ignore ICN001 ruff rule
Cockpit projects to not adhere to the convention to import datetime as
dt.
2026-10-16 17:10:14 +02:00
Jelle van der Waa
5b95358345 pyproject: introduce Codespell configuration
There are still many false positives in pkg/src/test to enable codespell
but at least documentation can be linted with this configuration.
2026-08-18 11:58:12 +02:00
Jelle van der Waa
837a2ad422 test: Add http-stream2 channel unit tests
Introduce pytest unittests to easily implement and test new channel
options. Unlike the QUnit test-http.js test this also allows us to test
UNIX sockets and TLS easily.
2026-06-17 09:36:41 +02:00
Freya Gustavsson
b37097f941 test: Add misc.print to mypy parsing
Adds `print.py` to mypy config and fixes an unused ignore.

Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
2026-04-23 13:10:05 +02:00
Allison Karlitskaya
d163c4ee61 pyproject: add "test.pytest" to "known first party"
Otherwise when we do our incremental checks in the commit hook, ruff
doesn't see the file and assumes it's a system import.
2026-03-31 13:52:05 +02:00
Jelle van der Waa
fd51e22997 pyproject: add minimal ty configuration
ty is a new Python type checker implemented in Rust, its quite a bit
faster then mypy but still experimental.
2026-03-20 16:29:07 +01:00
Allison Karlitskaya
7be5bec904 peer, superuser: add/modernize some typing
Enable strict mode and add the places where complaints popped up.

One not-entirely-mechanical thing: we replace the call to .stop() with a
call to .shutdown().  .stop() is decorated as a D-Bus method (which
unfortunately currently erases type information), which causes
complaints at the call site.  But it just calls .shutdown() anyway, so
we may as well just do that directly ourselves.
2026-01-21 09:11:40 +01:00
Martin Pitt
ae915c4dc5 test: Test beiboot derived package loader
We are going to change how this works, let's not break it.
2025-10-08 12:50:43 +02:00
Martin Pitt
c5d0d16bbf bridge: Strictly type packages.py
Use `get_dict` in `Packages.show()` to get typed accessors.

The two `@bus.Interface.Method` decorated methods cause

> Untyped decorator makes function "reload" untyped  [misc]

There's no immediate fix for that, ignore these errors for now.
2025-10-08 12:50:43 +02:00
Martin Pitt
df071789f0 test: Type test_packages.py 2025-10-08 12:50:43 +02:00
Allison Karlitskaya
ec49e531b3 pyproject.toml: add Python 3.14 to unit tests
This is already widely available since some time as a pre-release.  We
may as well start testing it.
2025-09-23 18:57:17 +02:00
Allison Karlitskaya
5acce3c6da tox: eighty-six 3.6
When we landed d53b3e8400 ("pytests: update fixtures to not use
deprecated event_loop") we promised ourselves "this is the last time".
The intensity of hacks required to keep up with being able to run the
same set of tests under modern Python versions and a long-dead version
which isn't getting any new releases of pytest or its plugins is just
too much.

And here we are again.  Since fb319e4f43 ("Pin pytest-asyncio version
to unbreak main") we've been avoiding taking a new pytest-asyncio
because it breaks our fragile pile of hacks yet again.  It's time.

Drop support for running the pytest unit tests tests under Python 3.6
and remove the massive pile of hacks we had for that.  Without any
further effort this has already unbroken the latest pytest-asyncio
version, so we can unpin it.

We still have full coverage of the bridge code on Python 3.6 via
integration testing (beiboot vs container-ws on RHEL 8) and the fact
that we're not as actively hacking on the bridge code anymore means that
any time that was once saved by getting "quick fails" from unit tests is
no longer worth the large and growing amount of effort required to keep
those tests from constantly breaking.
2025-09-23 18:57:17 +02:00
Allison Karlitskaya
289b449e3a pyproject: tune down ruff format
Let's do the same thing as in bots, and for the same reasons.
2025-09-23 18:57:17 +02:00
Jelle van der Waa
fb319e4f43 Pin pytest-asyncio version to unbreak main
Our tests hang when running with pytest-asyncio > 1.1.0 so temporarily
pin them for now.

Related: #22429
2025-09-12 16:23:35 +02:00
Allison Karlitskaya
346753c90e test-run: add type annotations, enable strict
We're about to start making some big changes here, so start by adding
typing.
2025-09-08 20:07:13 +02:00
Jelle van der Waa
9dadde06d5 pyproject.toml: rename rule TCH -> TH
This was remapped in ruff 0.8:
https://github.com/astral-sh/ruff/releases/tag/0.8.0
2025-07-18 09:07:24 +02:00
Martin Pitt
a383e99ed3 test: Type submanlib 2025-07-17 12:35:15 +02:00
Jelle van der Waa
a0cbc51766 cockpit: strictly type the pcp channel 2025-07-12 09:24:55 +02:00
Jelle van der Waa
daa32abe9b cockpit: strictly type the stream channel 2025-07-12 09:24:55 +02:00
Jelle van der Waa
d3f2221c8f cockpit: strictly type metrics channel 2025-07-12 09:24:55 +02:00
Jelle van der Waa
32eb5384f1 cockpit: strictly type http_channel
The 'type: ignore' comment was unused.
2025-07-10 07:58:50 +02:00
Jelle van der Waa
6a56393157 cockpit: fully strictly type bootloader 2025-07-10 07:58:50 +02:00
Jelle van der Waa
1109a73c67 cockpit: strictly type cockpit.samples 2025-07-10 07:58:50 +02:00
Jelle van der Waa
38e378c884 cockpit: copy typing signature from ferny's InteractionHandler
This implements an InteractionHandler from ferny so use the same typing
signature. Also fixes `mypy --strict` complaining about missing
parameters for generic type "Tuple".
2025-07-10 07:58:50 +02:00
Martin Pitt
10590dc5dd sosreport: Query sos policy for default tmp dir
sos 4.6.2 changed the tmp dir policy [1] from a static /var/tmp to a
dynamic per-distro policy, which happens to be /tmp on Debian/Ubuntu
right now. This is wrong, and there is no official way to query it [2].

To cope, query the sos policy for the tmp-dir, and only fall back to
static /var/tmp if that fails.

[1] https://github.com/sosreport/sos/pull/4062
[2] https://github.com/sosreport/sos/issues/4074
2025-07-09 09:24:50 +02:00
tomasmatus
f509b90a60 pytest: set default value for asyncio_default_fixture_loop_scope 2025-06-26 15:15:27 +02:00
tomasmatus
d53b3e8400 pytests: update fixtures to not use deprecated event_loop
pytest_asyncio dropped `event_loop` fixture in version 1.0.0
2025-06-26 15:15:27 +02:00
tomasmatus
34cffc160a workflows: add py3.6 to tox workflow, drop py3.8
Tox workflow is missing py3.6 and py3.8. Py3.6 can be installed but
py3.8 is no longer available so I propose we drop it.

As per tox FAQ we need to set `requires = virtualenv<20.22.0` as never
virtualenv version dropped support for version <=py3.6.

https://tox.wiki/en/latest/faq.html#testing-end-of-life-python-versions
2025-06-25 13:40:57 +02:00
Jelle van der Waa
a181d0d4a1
pyproject.toml: workaround asyncio 1.0 compatibility issues (#22050)
Works test issues on Python > 3.8 with asyncio version 1.0

Related: #22049
2025-05-27 13:52:50 +02:00
Jelle van der Waa
2590e785e5 cockpit: channels: strictly type the trivial channel 2025-04-22 13:32:30 +02:00
Jelle van der Waa
555775c104 test: type storagelib fully
Storagelib is shared between projects so useful to have typed. Typing
this mixin requires extending it to MachineCase to have access to the
TestCase functions and browser/machine from MachineCase.
2025-03-14 16:03:01 +01:00
Jelle van der Waa
4a3070671b test: type netlib fully 2025-03-12 11:56:11 +01:00
Jelle van der Waa
b80722824a test: type packagelib in strict mode
Useful when working on integration tests and wanting to quickly see the
required types for `createPackage`.
2025-03-10 13:10:57 +01:00
Martin Pitt
e395923115 test: Move static-code into common/
It conceptually fits better there, as it's shared by all external
projects. That makes importing easier as it doesn't have to be
enumerated separately in COCKPIT_REPO_FILES any more.
2024-12-05 14:23:20 +01:00
Jelle van der Waa
e9e1fcf58b cockpit: Implement PCP metrics channel in the Python bridge
The Python bridge still used the separate `cockpit-pcp` bridge for
metrics gathering. For us to remove the full C bridge implementation the
separate PCP bridge also has to be rewritten.

This rewrite is a more or less Python copy of the C implementation using
the Python PCP module. Even though the Python PCP module offers a
"higher level" fetchGroup API but preliminary testing has found this has
some issues with changing multi instance values and instances can not be
omitted with a fetch group (but this can be done in our own code)

Co-Authored-By: Allison Karlitskaya <allison.karlitskaya@redhat.com>
Co-Authored-By: Tomas Matus <tomatus777@gmail.com>
2024-09-25 10:27:22 +02:00
Allison Karlitskaya
76e18fc8b8 qunit: add support for precise coverage reporting
You can now do something like this:

  $ pytest -k test_browser --js-cov-files='*/fsinfo.ts'

and get results like this:

  pkg/lib/cockpit/fsinfo.ts:33:49-33:63 json_merge
                                                         ▼ from here
      33         const updated = is_json_dict(current) ? { ...current } : { };
                                                                      ▲ to here

  pkg/lib/cockpit/fsinfo.ts:36:33-38:14 json_merge
                                         ▼ from here
      36             if (value === null) {
      37                 delete updated[key];
      38             } else {
                     ▲ to here

Since we also use the same approach for collecting data for integration
tests (Profiler.takePreciseCoverage), we could easily add support there
as well.
2024-08-27 17:35:49 +02:00
Allison Karlitskaya
2c11e25896 pyproject.toml: tweak pyright config
Unfortunately, `root=` doesn't mean what I thought it did.  It does
select the files to be considered for the given overrides, but it also
adds the given directory to the search path.

Having `root="test"` is a problem because it contains a `pytest`
subdirectory, which is what pyright thinks you're talking about if you
say `import pytest`.

Ideally we'd be able to say that all code found in `test/` gets access
to testlib, without adding `test/` itself.  I also tried to say that
`src/` doesn't get access to testlib but `.` does, but this resulted in
`testlib` being accessible from files in `src/` as well.

Let's just simplify this to be more like our mypy setup.  Really: if
you're importing testlib from the bridge, you're gonna find out about
the problem with that pretty quickly anyway.

Let's turn on strict while we're at it.  We don't actually run pyright,
but it gets more messages into the editor, which is nice.
2024-08-15 21:00:31 +02:00
Allison Karlitskaya
3978a5b129 test/common: drop cdp vestiges
Nothing uses these anymore.
2024-08-15 09:17:47 +02:00
Allison Karlitskaya
60df28c1a6 test_browser: move from CDP to Webdriver BiDi
We do this by internalizing some of the code from tap-cdp (which we
delete).  The main thing blocking us from doing that before was the
synchronous interface of our CDP module, but our new webdriver_bidi has
a nice async interface for us to use.

There are a few issues with running the Qunit tests under tox, and since
there's not a lot of value in running browser-based tests in tox, just
don't.  We might revisit that later, particularly if we move to having
the tests running against a python-based webserver.

We also disable running the Qunit tests during Debian package builds:
there's no qunit bundles in the tarball anyway, but just sourcing
test_browser.py requires aiohttp to be installed (which it isn't).
2024-08-15 09:17:47 +02:00
Allison Karlitskaya
41dea51f19 pyproject.toml: teach pytest about testlib paths
Doing this at the toplevel lets us drop some hacks for adding those
paths for our verify/ test cases.  Plus: we'll soon be using test/common
from outside of verify/, so the logic of wanting to isolate it to that
subdirectory no longer exists.

mypy already knows about it, but for the sake of LSP users, let pyright
know about it too.
2024-08-15 09:17:47 +02:00
Martin Pitt
0ec830da3d test: Port from CDP to BiDi browser automation
This slightly changes the API of `Browser.keys()` with modifiers. We
only use that once inside of testlib.py and twice in
check-system-terminal (and nowhere in external projects), so just adjust
the three callers.

The `Browser.get_js_log()` output format also changes slightly, to be
much more detailed. Adjust tests accordingly.

Skip `TestGrafanaClient` and `TestPages.testAllLanguages` on Chromium
for now. There is a really weird bug where Cockpit/Grafana spontaneously
logs out itself, but *only* in headless Chromium. So run the
test only on Firefox for the time being.

As penance, enable testUpload*() on Firefox, the BiDi API works fine
there. We can enable other tests on Firefox as a follow-up as well (they
need some work unrelated to BiDi though).

This removes excess right/bottom padding from two mobile pixel tests,
update them.

https://issues.redhat.com/browse/COCKPIT-1143
2024-08-13 05:03:01 -04:00
Allison Karlitskaya
37916f810e pyproject.toml: Vulture: ignore pytest fixtures 2024-07-17 07:59:10 -04:00
Allison Karlitskaya
dcefbb2581 testlib: fix Pillow type annotations
Pillow upstream added a `py.typed` file in their last release, which is
causing us problems because:

  - we `from PIL import Image`, which kinda looks like the class `Image`
    in the `PIL` module, but is actually a submodule.  In particular,
    `PIL.Image.open()` is not a static method, but a function call, and
    it doesn't return `PIL.Image`, but rather `PIL.Image.Image`.  Fix a
    couple of annotations.

  - our hacks for setting `Image = None` if the import is missing are no
    longer working (since the import now has a better type than `Any`).
    Let's make the import unconditional.  `dnf install python3-pillow`.

  - several methods are unannotated in the upstream code, leading to
    warnings about "untyped call from typed code".  We use an #ignore
    for those; cf. https://github.com/python-pillow/Pillow/issues/8029
2024-04-30 13:17:02 +02:00
Allison Karlitskaya
d474bdca0a test/static-code: copy mypy setup from bots/
Move our list of static files out of test/static-code (which is shared
with other projects).  Add testlib to that list.

This reduces the cost of running mypy on a warm cache from 20s to ~0.3s,
while expanding checking to every single Python file in the source tree.

A overall `test/static-code` run (minus `node_modules`) decreases from
~24s to ~4s.  The majority of that time is now in the json validity
checking rule (since it runs a separate python invocation for each
file).
2024-04-23 00:13:10 +02:00
Allison Karlitskaya
60d54b8a31 tools: rename vulture(- → _)suppressions
We are about to ask mypy to run on the entire source tree, and it
doesn't like having `-` in module names.  Use a `_` instead.
2024-04-23 00:13:10 +02:00
Allison Karlitskaya
6298dd93c8 test/static-code: drop flake8
`ruff` in preview mode now implements the various E[123] rules that we
were depending on flake8 for.  Drop it.
2024-04-16 14:08:52 +02:00
Allison Karlitskaya
5b6c1ce8ae pyproject: enable 'preview' ruff rules
Now that we gate our ruff updates via the tasks container, we can afford
to be a bit more future-oriented here.

This brings in a nice raft of fix-ups, including my personal favourite:

  RUF003 Comment contains ambiguous `µ` (MICRO SIGN). Did you mean `μ` (GREEK SMALL LETTER MU)?

Sure... why not?

The majority of fixes here are from a single rule suggesting to rewrite

  a and b or c

as

  (a and b) or c

But in most (but not all) cases in our code we actually want to write
that as

  b if a else c

I've also added some type annotations to help me make the right choice
in places where it wasn't immediately clear.
2024-04-16 14:08:52 +02:00
Allison Karlitskaya
dada0dcc54 pyproject.toml: stop linting in venvs
Lacking a proper requirements.txt file, we're at the mercy of whatever
got randomly uploaded to pypy last night, and we've been seeing a lot of
breaks lately.

We already run our ruff/mypy/etc. stuff as part of our unit tests
workflow, so let's stop running it in venv.  The idea is that we should
pass against the current version of the tasks container (which will
probably shift at some point to being our pinned version of the tasks
container).

While we're at it, drop Python 3.7 (which the world seems to have
collectively decided to stop caring about) and add Python 3.13 (which
has been in Fedora 39 for a while already).  Note: we do *not* drop
Python 3.6 — although it is no longer an officially supported release,
it's used in RHEL 7 and RHEL 8 and Fedora intends to keep packaging it.
2024-03-11 12:52:01 +01:00
Allison Karlitskaya
9b221db9b6 ruff: move linter settings to [lint] section
New ruff warns to stderr that the old way is deprecated.  That's enough
to convince test/static-code that an error is being reported.

Let's move this over.
2024-02-02 16:16:19 +01:00
Martin Pitt
9fa8581e41 mypy: Ignore external modules without annotations
These are imported in scripts in src/ and pkg/, which we will soon start
covering.
2023-11-02 09:45:34 +01:00