Skip to content

Commit

Permalink
python tests with uv & typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Feb 3, 2025
1 parent fb1fb6c commit b02bf17
Show file tree
Hide file tree
Showing 32 changed files with 834 additions and 801 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-binary-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Build all platforms
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
42 changes: 26 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
build:
name: "Build + tests"
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:

Expand All @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Build
run: |
Expand All @@ -38,19 +38,21 @@ jobs:
env:
RICHGO_FORCE_COLOR: 1

- name: "Setup Python"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: 0.5.24
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pipenv'
python-version-file: "test/.python-version"

- name: "Install python dependencies"
run: |
python -m pip install --upgrade pipenv wheel
pipenv install --deploy
# some tests need root, so we have to install pytest twice
sudo python3 -m pip install --upgrade pipenv wheel
sudo pipenv install --deploy
- name: Install the project
working-directory: ./test
run: uv sync --all-extras --dev

- name: Install functional test dependencies
run: |
Expand All @@ -65,20 +67,28 @@ jobs:
CROWDSEC_TEST_NETWORK: net-test
CROWDSEC_TEST_TIMEOUT: 60
PYTEST_ADDOPTS: --durations=0 -vv --color=yes -m "not (deb or rpm)"
working-directory: ./test
run: |
# everything except for
# - install (requires root, ignored by default)
# - backends (requires root, ignored by default)
# - deb/rpm (on their own workflows)
pipenv run pytest
uv run pytest
# these need root
sudo -E pipenv run pytest ./test/backends
sudo -E pipenv run pytest ./test/install/no_crowdsec
sudo -E uv run pytest ./test/backends
sudo -E uv run pytest ./test/install/no_crowdsec
# these need a running crowdsec
docker run -d --name crowdsec -e CI_TESTING=true -e DISABLE_ONLINE_API=true -ti crowdsecurity/crowdsec
install -m 0755 /dev/stdin /usr/local/bin/cscli <<'EOT'
#!/bin/sh
docker exec crowdsec cscli "$@"
EOT
sleep 5
sudo -E pipenv run pytest ./test/install/with_crowdsec
sudo -E uv run pytest ./test/install/with_crowdsec
- name: Lint
working-directory: ./test
run: |
uv run ruff check
uv run basedpyright
34 changes: 18 additions & 16 deletions .github/workflows/tests_deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
build:
name: "Test .deb packages"
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:

Expand All @@ -24,26 +24,28 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: "Setup Python"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: 0.5.24
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pipenv'
python-version-file: "test/.python-version"

- name: "Install python dependencies"
run: |
python -m pip install --upgrade pipenv wheel
pipenv install --deploy
# some tests need root, so we have to install pytest twice
sudo python3 -m pip install --upgrade pipenv wheel
sudo pipenv install --deploy
- name: Install the project
run: uv sync --all-extras --dev
working-directory: ./test

- name: Install functional test dependencies
run: |
sudo apt update
sudo apt install -y build-essential debhelper devscripts fakeroot lintian
sudo apt install -y nftables iptables ipset build-essential debhelper devscripts fakeroot lintian
docker network create net-test
- name: Run functional tests
Expand All @@ -53,7 +55,7 @@ jobs:
CROWDSEC_TEST_NETWORK: net-test
CROWDSEC_TEST_TIMEOUT: 60
PYTEST_ADDOPTS: --durations=0 -vv --color=yes
working-directory: ./test
run: |
sudo apt install -y nftables iptables ipset
pipenv run pytest test/pkg/test_build_deb.py
sudo -E pipenv run pytest -m deb ./test/install/no_crowdsec
uv run pytest test/pkg/test_build_deb.py
sudo -E uv run pytest -m deb ./test/install/no_crowdsec
17 changes: 0 additions & 17 deletions Pipfile

This file was deleted.

Loading

0 comments on commit b02bf17

Please sign in to comment.