-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from malmeloo/feat/unit-tests
tests: Add very basic unit tests
- Loading branch information
Showing
8 changed files
with
183 additions
and
4 deletions.
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
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ jobs: | |
run: | | ||
python -m pip install poetry | ||
poetry config virtualenvs.in-project true | ||
poetry install | ||
poetry install --with dev | ||
- uses: pre-commit/[email protected] | ||
|
||
|
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,57 @@ | ||
name: Run unit tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
|
||
jobs: | ||
versions: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
py-versions: ${{ steps.supported-versions.outputs.py-versions }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry config virtualenvs.in-project true | ||
poetry install --with dev | ||
- id: supported-versions | ||
name: Get supported versions | ||
run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
|
||
needs: versions | ||
strategy: | ||
matrix: | ||
py-version: ${{ fromJson(needs.versions.outputs.py-versions) }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "${{ matrix.py-version }}" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry config virtualenvs.in-project true | ||
# Only install main dependencies | ||
poetry install --with test | ||
- name: Run unit tests | ||
run: poetry run pytest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
from itertools import count | ||
from pathlib import Path | ||
from typing import Generator | ||
|
||
import tomli | ||
from packaging.specifiers import SpecifierSet | ||
from packaging.version import Version | ||
|
||
|
||
def get_python_versions() -> Generator[str, None, None]: | ||
"""Get all python versions this package is compatible with.""" | ||
with Path("pyproject.toml").open("rb") as f: | ||
pyproject_data = tomli.load(f) | ||
|
||
specifier = SpecifierSet(pyproject_data["tool"]["poetry"]["dependencies"]["python"]) | ||
|
||
below_spec = True | ||
for v_minor in count(): | ||
version = Version(f"3.{v_minor}") | ||
|
||
# in specifier: yield | ||
if version in specifier: | ||
below_spec = False | ||
yield str(version) | ||
continue | ||
|
||
# below specifier: skip | ||
if below_spec: | ||
continue | ||
|
||
# above specifier: return | ||
return | ||
|
||
|
||
print(json.dumps(list(get_python_versions()))) |
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,11 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize('execution_number', range(100)) | ||
def test_import(execution_number): | ||
import findmy | ||
|
||
kp = findmy.KeyPair.new() | ||
assert len(kp.private_key_bytes) == 28 | ||
assert len(kp.adv_key_bytes) == 28 | ||
assert len(kp.hashed_adv_key_bytes) == 32 |