chore: add basic pytest setup (#153)

This commit is contained in:
Robert Kaussow 2022-02-26 16:45:02 +01:00 committed by GitHub
parent 41b9bcd481
commit ab7b7d285a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 133 additions and 7 deletions

View File

@ -8,6 +8,7 @@ local PythonVersion(pyversion='3.7') = {
'pip install poetry poetry-dynamic-versioning -qq',
'poetry config experimental.new-installer false',
'poetry install',
'poetry run pytest',
'poetry version',
'poetry run prometheus-pve-sd --help',
],
@ -77,6 +78,24 @@ local PipelineTest = {
PythonVersion(pyversion='3.8'),
PythonVersion(pyversion='3.9'),
PythonVersion(pyversion='3.10'),
{
name: 'codecov',
image: 'python:3.10',
environment: {
PY_COLORS: 1,
CODECOV_TOKEN: { from_secret: 'codecov_token' },
},
commands: [
'pip install codecov -qq',
'codecov --required -X gcov',
],
depends_on: [
'python37-pytest',
'python38-pytest',
'python39-pytest',
'python310-pytest',
],
},
],
depends_on: [
'lint',

View File

@ -55,6 +55,7 @@ steps:
- pip install poetry poetry-dynamic-versioning -qq
- poetry config experimental.new-installer false
- poetry install
- poetry run pytest
- poetry version
- poetry run prometheus-pve-sd --help
environment:
@ -68,6 +69,7 @@ steps:
- pip install poetry poetry-dynamic-versioning -qq
- poetry config experimental.new-installer false
- poetry install
- poetry run pytest
- poetry version
- poetry run prometheus-pve-sd --help
environment:
@ -81,6 +83,7 @@ steps:
- pip install poetry poetry-dynamic-versioning -qq
- poetry config experimental.new-installer false
- poetry install
- poetry run pytest
- poetry version
- poetry run prometheus-pve-sd --help
environment:
@ -94,6 +97,7 @@ steps:
- pip install poetry poetry-dynamic-versioning -qq
- poetry config experimental.new-installer false
- poetry install
- poetry run pytest
- poetry version
- poetry run prometheus-pve-sd --help
environment:
@ -101,6 +105,21 @@ steps:
depends_on:
- fetch
- name: codecov
image: python:3.10
commands:
- pip install codecov -qq
- codecov --required -X gcov
environment:
CODECOV_TOKEN:
from_secret: codecov_token
PY_COLORS: 1
depends_on:
- python37-pytest
- python38-pytest
- python39-pytest
- python310-pytest
trigger:
ref:
- refs/heads/main
@ -630,6 +649,6 @@ depends_on:
---
kind: signature
hmac: 9ed3991a84fdb078a647e5c0673bab3283417c894ed9b858ee939f32741e350b
hmac: e86573972517f4268f7a372b00261aae9924e4f1c014153f00391bb231271bd5
...

21
codecov.yml Normal file
View File

@ -0,0 +1,21 @@
codecov:
require_ci_to_pass: true
coverage:
status:
project:
default:
target: auto
threshold: 5%
branches:
- main
if_ci_failed: error
informational: false
only_pulls: false
patch:
default:
target: auto
threshold: 5%
branches:
- main
if_ci_failed: error
only_pulls: false

View File

View File

View File

@ -0,0 +1,42 @@
"""Global pytest fixtures."""
import pytest
@pytest.fixture
def qemus():
return [{
"diskwrite": 0,
"vmid": "100",
"name": "100.example.com",
"cpu": 0.0202130478509556,
"diskread": 0,
"template": "",
"uptime": 3101505,
"maxdisk": 26843545600,
"maxmem": 1073741824,
"pid": "1765",
"cpus": 1,
"netin": 2856071643,
"disk": 0,
"status": "running",
"netout": 12159205236,
"mem": 496179157
}, {
"diskwrite": 0,
"vmid": "101",
"name": "101.example.com",
"cpu": 0.0202130478509556,
"diskread": 0,
"template": "",
"uptime": 3101505,
"maxdisk": 26843545600,
"maxmem": 1073741824,
"pid": "1765",
"cpus": 1,
"netin": 2856071643,
"disk": 0,
"status": "running",
"netout": 12159205236,
"mem": 496179157
}]

View File

@ -0,0 +1,28 @@
"""Test Autostop class."""
import pytest
from proxmoxer import ProxmoxAPI
from prometheuspvesd import discovery
pytest_plugins = [
"prometheuspvesd.test.fixtures.fixtures",
]
@pytest.fixture
def discovery_fixture(mocker):
mocker.patch.object(
discovery.Discovery, "_auth", return_value=mocker.create_autospec(ProxmoxAPI)
)
return discovery.Discovery()
def test_exclude(discovery_fixture, qemus):
discovery_fixture.config.config["exclude_vmid"] = [100, "101"]
expected = []
filtered = discovery_fixture._exclude(qemus)
assert filtered == expected

View File

@ -19,15 +19,11 @@ classifiers = [
description = "Prometheus Service Discovery for Proxmox VE."
documentation = "https://github.com/thegeeklab/prometheus-pve-sd/"
homepage = "https://github.com/thegeeklab/prometheus-pve-sd/"
include = [
"LICENSE",
]
include = ["LICENSE"]
keywords = ["prometheus", "sd", "pve", "metrics"]
license = "MIT"
name = "prometheus-pve-sd"
packages = [
{include = "prometheuspvesd"},
]
packages = [{ include = "prometheuspvesd" }]
readme = "README.md"
repository = "https://github.com/thegeeklab/prometheus-pve-sd/"
version = "0.0.0"
@ -85,6 +81,7 @@ skip_glob = ["**/.env*", "**/env/*", "**/.venv/*", "**/docs/*"]
addopts = "prometheuspvesd --cov=prometheuspvesd --cov-report=xml:coverage.xml --cov-report=term --cov-append --no-cov-on-fail"
filterwarnings = [
"ignore::FutureWarning",
"ignore:.*distutils.*:DeprecationWarning",
"ignore:.*collections.*:DeprecationWarning",
"ignore:.*pep8.*:FutureWarning",
]