-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add software tests and CI configuration #39
Open
amotl
wants to merge
8
commits into
wernerfred:master
Choose a base branch
from
cicerops:add-ci
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12bb63b
build: Add project tooling
amotl 9fcc332
test: Add software test framework
amotl f4c4ad3
ci: Run software tests on GHA
amotl a510e7b
ci: Install Net-SNMP package as prerequisite
amotl 95bdaf2
chore: Update package metadata with corresponding Python versions
amotl 5de95a4
docs: Update badges in README
amotl aace147
fix: Installing package in editable mode croaked badly
amotl d2795ad
fix: Adjust license in `setup.py` to "MIT"
amotl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
|
||
tests: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ "ubuntu-latest", "macos-latest" ] | ||
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ] | ||
fail-fast: false | ||
|
||
env: | ||
OS: ${{ matrix.os }} | ||
PYTHON: ${{ matrix.python-version }} | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} | ||
steps: | ||
|
||
- name: Acquire sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: x64 | ||
cache: 'pip' | ||
cache-dependency-path: 'setup.py' | ||
|
||
- name: Install prerequisites (Linux) | ||
if: matrix.os == 'ubuntu-latest' | ||
run: | | ||
sudo apt install --yes libsnmp-dev snmp-mibs-downloader | ||
|
||
- name: Install prerequisites (macOS) | ||
if: matrix.os == 'macos-latest' | ||
run: | | ||
brew install net-snmp | ||
|
||
- name: Run linter | ||
run: | | ||
make lint | ||
|
||
- name: Run tests, with coverage | ||
run: | | ||
make test | ||
|
||
- name: Upload coverage results to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml | ||
flags: unittests | ||
env_vars: OS,PYTHON | ||
name: codecov-umbrella | ||
fail_ci_if_error: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.venv* | ||
__pycache__ | ||
*.egg-info | ||
.coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$(eval venv := .venv) | ||
$(eval pip := $(venv)/bin/pip) | ||
$(eval python := $(venv)/bin/python) | ||
$(eval black := $(venv)/bin/black) | ||
$(eval isort := $(venv)/bin/isort) | ||
$(eval pytest := $(venv)/bin/pytest) | ||
$(eval twine := $(venv)/bin/twine) | ||
$(eval flake8 := $(venv)/bin/pflake8) | ||
$(eval proselint := $(venv)/bin/proselint) | ||
|
||
setup-virtualenv: | ||
@test -e $(python) || python3 -m venv $(venv) || python -m venv $(venv) | ||
|
||
format: setup-virtualenv | ||
$(pip) install --requirement=requirements-utils.txt | ||
$(black) . | ||
$(isort) . | ||
|
||
lint: setup-virtualenv | ||
$(pip) install --requirement=requirements-utils.txt | ||
$(flake8) --exit-zero *.py | ||
$(MAKE) proselint | ||
|
||
proselint: | ||
$(proselint) *.md || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Let's start in relaxed mode. |
||
|
||
test: setup-virtualenv | ||
$(pip) install --editable=.[test] | ||
$(pytest) | ||
|
||
publish: setup-virtualenv | ||
$(pip) install build twine | ||
$(python) -m build | ||
$(twine) upload --skip-existing --verbose dist/*{.tar.gz,.whl} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[tool.black] | ||
line-length = 120 | ||
|
||
[tool.isort] | ||
profile = "black" | ||
line_length = 120 | ||
multi_line_output = 3 | ||
|
||
[tool.flake8] | ||
max-line-length = 120 | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "2.0" | ||
addopts = "-rsfEX -p pytester --strict-markers --verbosity=3 --cov --cov-report=term-missing --cov-report=xml" | ||
log_level = "DEBUG" | ||
testpaths = ["testing"] | ||
xfail_strict = true | ||
markers = [ | ||
] | ||
|
||
[tool.coverage.run] | ||
omit = [ | ||
"testing/*", | ||
] | ||
|
||
[tool.coverage.report] | ||
fail_under = 0 | ||
show_missing = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
black | ||
isort | ||
pyproject-flake8 | ||
flake8<5 | ||
proselint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
|
||
|
||
def run_program(*args) -> int: | ||
""" | ||
Run `check_synology` program and return exit code. | ||
|
||
Support a variable number of command line options. | ||
""" | ||
sys.argv = ["check_synology", *args] | ||
try: | ||
import check_synology | ||
except SystemExit as ex: | ||
return ex.code % 256 | ||
|
||
|
||
def test_no_options(capsys): | ||
""" | ||
Verify running the program without options croaks as expected. | ||
""" | ||
exitcode = run_program() | ||
response = capsys.readouterr() | ||
assert exitcode == 2 | ||
assert response.out == "" | ||
assert ( | ||
"check_synology: error: the following arguments are required: " | ||
"hostname, username, authkey, privkey, mode" in response.err | ||
) | ||
|
||
|
||
def test_help(capsys): | ||
""" | ||
Verify running the program with the `--help` option works as expected. | ||
""" | ||
exitcode = run_program("--help") | ||
response = capsys.readouterr() | ||
assert exitcode == 0 | ||
assert "the hostname" in response.out | ||
assert "critical value for selected mode" in response.out | ||
assert response.err == "" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
--exit-zero
, it will currently not bail out on any findings. We will satisfy the linters with a subsequent patch.