Skip to content
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

Run tests via github actions #10

Merged
merged 10 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 7 additions & 38 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish to PyPI

on:
push:
branches:
- main
tags:
- "v*.*.*"

jobs:
build:
Expand All @@ -25,21 +25,6 @@ jobs:
name: python-package-distributions
path: dist/

test:
name: Run tests with pytest
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run tests
run: pytest

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
Expand Down Expand Up @@ -77,27 +62,11 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]

- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
inputs: >-
files: |
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "*" ]

permissions:
contents: write
checks: write
pull-requests: write

jobs:
build:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -e .[dev]
- name: Run pre-commit hooks
uses: pre-commit/[email protected]
- name: Build coverage file
run: |
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=iokit tests/ | tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
2 changes: 1 addition & 1 deletion src/iokit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"save_file",
"save_temp",
]
__version__ = "0.1.0"
__version__ = "0.1.1"

from .extensions import Gzip, Json, Jsonl, Tar, Txt
from .state import State, filter_states, find_state
Expand Down
7 changes: 5 additions & 2 deletions tests/test_gzip.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from iokit import Json, Gzip, load_file, save_temp

import os

from iokit import Gzip, Json, load_file, save_temp


def random_utf8_string(length: int) -> str:
random_bytes = os.urandom(length)
string = random_bytes.decode("utf-8", errors="replace")
return string


def test_gzip_state() -> None:
data = {"a": 1, "b": 2}
state = Gzip(Json(data, name="data"))
Expand All @@ -18,6 +19,7 @@ def test_gzip_state() -> None:
assert state.load().load() == data
assert state.size > 0


def test_gzip_compression() -> None:
string = random_utf8_string(10_000)
state = Json(string, name="data")
Expand All @@ -32,6 +34,7 @@ def test_gzip_compression() -> None:
assert compressed3.load().load() == string
assert compressed9.load().load() == string


def test_gzip_save_load_file() -> None:
data = {"a": 1, "b": 2}
state = Gzip(Json(data, name="data"))
Expand Down
1 change: 0 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_json_different() -> None:
assert loaded["int"] == 42



def test_json_is_string() -> None:
state = Json("hello", name="string")
assert state.load() == "hello"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from iokit import Tar, Txt, find_state, Gzip
from iokit import Gzip, Tar, Txt, find_state


def test_tar_state() -> None:
Expand Down