Commit graph

32 commits

Author SHA1 Message Date
Brian C. Lane
8c35e072cc tox: Limit it to virtualenv < 20.22.0 for py36 support 2025-06-17 00:21:21 -07:00
Brian C. Lane
3f91723402 Tests/tox: Fedora 43 is now using python 3.14
Add testing on pythong 3.14 and keep testing on python 3.13 for the
current stable Fedora version (42 at this time).

Use osbuild-ci:latest-202506112350 for tests.yml
2025-06-17 00:21:21 -07:00
Tomáš Hozza
a3428e282d sbom/spdx: use compliant license expressions
Introduce a new class `SpdxLicenseExpressionCreator`, responsible for
converting license texts extracted from packages, into an SPDX-compliant
license expressions. If the `license_expression` Python package is
available on the system, it is used to determine the license text
extracted from a package is a valid SPDX license expression. If it is,
it's returned as is back to the caller. If it is not, or of the package
is not available on the system, the license text is wrapped in a
`ExtractedLicensingInfo` instance.

The `SpdxLicenseExpressionCreator` object keeps track of all generated
`ExtractedLicensingInfo` instances and de-duplicates them based on the
license text. This means that if two packages use the same
SPDX-non-compliant license text, they will be wrapped by an
`ExtractedLicensingInfo` instance with the same `LicenseRef-` ID.

The reason for fallback when `license_expression` package is not
available is that it is not available on RHEL and CentOS Stream. This
implementation allows us to ship the functionality in RHEL and
optionally enabling it by installing `license_expression` from a 3rd
party repository. In any case, the generated SBOM document will always
contain valid SPDX license expressions.

Extend unit tests to cover the newly added functionality.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>

FIXUP: sbom/spdx: use compliant license expressions

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Tomáš Hozza
a6c7b56d98 Tests/tox: latest Fedora uses Python 3.13, so use it
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-11-28 13:29:12 +01:00
Tomáš Hozza
c44657377e Lint/pylint: update to the latest upstream version v3.3.1
Update pylint to the latest upstream version, to fix a false positive
with Python 3.13, that was resolved in `astroid` dependency in version
`3.3.5`. In order to update the dependency, the `pylint` version itself
needs to be bumped to at least version `3.0.0`.

The error was:
test/run/test_stages.py:21:0: E0611: No name 'Mapping' in module 'collections.abc' (no-name-in-module)

More details: https://github.com/pylint-dev/pylint/issues/10000

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-11-25 10:09:18 +01:00
Tomáš Hozza
8b62e9d901 Lint/autopep8: update to the latest upstream version v2.3.1
This is needed to resolve fialure to find `lib2to3` module on F41, which
was removed since Python 3.13 used by default there.

Update autopep8 and pycodestyle to the latest upstream releases.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-11-25 09:23:51 +01:00
Michael Vogt
6788a2c840 devices: add pytest conftest infra for devices
This is similar to the other `inputs`, `sources` etc conftest.py
modules and allows us to write unit test for the devices code.
2024-08-26 14:16:01 +02:00
Achilleas Koutsou
af913d91f4 tox: add toml test envs
Add four toml test environments, testing that osbuild.util.toml works
for reading and writing with all our supported toml module combinations.
2024-08-21 19:26:31 +02:00
Michael Vogt
5d3dac9fb9 tox,workflow: pass tests to run via tox {posargs} instead of env
Using an environ for passing the tests is a bit of a headache when
it comes to quoting which is important when trying to write something
like: `-k "not test_stages.py"`.

I (personally) also find it slightly nicer/more intuitive to be able to do:
```
$ tox -e py36 -- ./test/mod
```
compared to
```
$ TEST_CATEGORY="./test/mod" tox -e py36
```
2024-04-16 15:16:49 +02:00
Achilleas Koutsou
9b3a157a91 tox: enable verbose output for pytest
This will list the test names and the reason for any skipped tests,
which can be useful for troubleshooting and tracing.
2024-04-16 07:38:18 +02:00
Michael Vogt
d504165c80 mounts: add mounts_module_fixture to allow testing mount modules
Similar to `stages` and `sources` we need some basic infrastructure
so that we can use a `mounts_module` fixture for the coming tests
to the mount modules.
2024-04-11 17:40:21 +02:00
Michael Vogt
b9b296a7e5 testutil: add AtomicCounter() as a threadsafe counter
The existing code in the reqs counting is not really thread safe,
this commit fixes that.
2024-04-09 03:02:45 +02:00
Michael Vogt
249107a028 stages,test: fix lint errors and add basic unit tests
Add very simple unit tests as a starting point for the new
parsing functions in `util/parsing.py`.
2024-03-25 18:26:53 +01:00
Michael Vogt
16d30254c4 tox,osbuild: deal with stages that have external json data
Some existing code/test assumes that anything in `stages/` is
executable. This commit fixes this and excludes e.g. json from
lintables.
2024-03-14 13:37:57 +01:00
Michael Vogt
3dd12931e4 tox.ini: update autopep8/pyocdestyle to support py3.12 2024-03-14 13:25:55 +01:00
Simon de Vlieger
82218c91a1 tox: remove isort
The role of the `isort` check is now performed by `ruff` instead of
`isort`.
2024-03-05 16:10:27 +01:00
Simon de Vlieger
7fc06acffc tox: update ruff dependency
Renames a property that should now live under `lint` to silence a
warning in newer `ruff`.
2024-03-05 16:10:27 +01:00
Michael Vogt
2d71935a91 inputs: add new "inputs_module" fixture 2024-02-27 15:07:42 +01:00
Michael Vogt
119172e8dd test: add sources_module fixture for sources unit tests
Similar to the `stage_module` fixture for stage tests this adds
a fixture to test sources modules of osbuild.

The code from `stage_module` and `sources_module` is similar and
could be combined but pytest makes it hard to do this without
having a shared root dir. Given that it's just four lines it
seems easier to just life with the tiny bit of code duplication.
2024-02-21 17:55:37 +01:00
Michael Vogt
5c47be179c tox: add all non shell file in tools/ to lintables
Right now the tools directory is not checked by pylint because
it will not auto-detect what files are python files and instead
just skip the dir if it does not have a __init__.py.

This commit uses `tox-backticks` to run a custom find to ensure
the python files are explicitely added. I'm not sure we can
use tox-backticks or we need it packages for fedora/rhel?

If we cannot use it we need to look into either a custom tox
plugin to support more rich globbing or just move out
`tools/set-env-variables.sh` as it's the only non-python code
in the repo and it will trip up pylint (syntax error).
2024-02-20 14:52:23 -08:00
Michael Vogt
d8835150c2 osbuild: add "mypy-strict" check 2024-01-23 12:01:45 +01:00
Michael Vogt
7f3dbb2e2d tox.ini: run lint on test/ dir too 2024-01-02 19:31:31 +01:00
Michael Vogt
4e3fc6a625 osbuild: pytoml is deprecated, replace with toml
Pytoml is no longer being maintained: https://github.com/avakar/pytoml
The author suggest switching to toml.

We already use the
```
try:
    import toml
except ModuleNotFoundError:
    import pytoml as toml
```
pattern in stages/org.osbuild.containers.storage.conf so use it in the tests too to prefer "toml" instead of pytoml.
2023-12-12 14:06:50 -08:00
Alexander Larsson
891bbcec17 Add test for org.osbuild.containers.storage.conf stage 2023-12-12 09:54:38 +01:00
Michael Vogt
26fa3aec8c tox: move to pylint 3.0.2 for py312 support
With python 3.12 our pylint version breaks because of
https://github.com/pylint-dev/astroid/issues/2201

This is fixed in 3.0.0a6 but it seems sensible to move
to 3.0.2.
2023-11-15 18:31:56 +01:00
Michael Vogt
d52738d70c tools: add "tools" dir to LINTABLES and fix issues
The `./tools` dir was not part of the LINTABLES in the `tox.ini`
which meant that pep8/pylint etc checks were not run on the tools
there.

This commit adds it and fixes the issues that `make lint` found.
2023-11-13 10:10:12 +01:00
Michael Vogt
ce8bc6dc1f stages(kickstart): run ksvalidator as part of the tests
Run `ksvalidator` as part of the test_kickstart.py tests. This
ensures that the file we write is valid.
2023-11-08 18:49:35 +01:00
Michael Vogt
0edbe0cf96 tests: run the test_stages category in parallel
Run the `test_stages` test in parallel in the github runner. This
test currently takes about 1:30h to 2:30h and running it in parallel
will give us big wins in terms of test time. The time is observed
to go down to 0:30h to 1h.

Note that the other tests are not run in parallel. The reason is
that they fail randomly, it looks like insufficient isolation
between them. Some are easy to fix, e.g.:
721521220b
but it's probably not worth it as the other tests run a lot faster.
2023-11-08 08:10:34 +01:00
Michael Vogt
ed95c10530 stages: add new unit test for kickstart stage
This commit adds a simple and lightweight unit test for the new
kickstart options. It's pretty simple but also cheap and runs
fast.
2023-11-07 15:12:08 +01:00
Brian C. Lane
a7541ad8b4 tox: Pin pycodestyle to 2.10.0
They changed their API in 2.11.0 and broke autopep8
See:
https://github.com/hhatto/autopep8/issues/689
and
https://github.com/hhatto/autopep8/pull/696
2023-08-10 13:04:14 +02:00
Brian C. Lane
2047a8efbc autopep8: Increase aggressive level 2023-08-10 13:04:14 +02:00
Simon de Vlieger
d60690ce46 tox: add tox
`tox` is a standard testing tool for Python projects, this allows you to
test locally with all your installed Python version with the following
command:

`tox -m test -p all`

To run the tests in parallel for all supported Python versions.

To run linters or type analysis:

```
tox -m lint -p all
tox -m type -p all
```

This commit *also* disables the `import-error` warning from `pylint`,
not all Python versions have the system-installed Python libraries
available and they can't be fetched from PyPI.

Some linters have been added and the general order linters run in has
been changed. This allows for quicker test failure when running
`tox -m lint`. As a consequence the `test_pylint` test has been removed
as it's role can now be fulfilled by `tox`.

Other assorted linter fixes due to newer versions:
- use a str.join method (`consider-using-join`)
- fix various (newer) mypy and pylint issues
- comments starting with `#` and no space due to `autopep8`

This also changes our CI to use the new `tox` setup and on top of that
pins the versions of linters used. This might move into separate
requirements.txt files later on to allow for easier updating of those
dependencies.
2023-08-01 15:01:13 +02:00