Skip to content

Commit

Permalink
Merge pull request #393 from richardsheridan/test_suite_cleanup
Browse files Browse the repository at this point in the history
Test suite cleanup
  • Loading branch information
richardsheridan authored Nov 23, 2023
2 parents c23737c + 4dd8547 commit d37528a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ jobs:
url: https://pypi.org/p/trio-parallel
permissions:
id-token: write
# contents: write # TODO: Is this the right permission to fix gh release upload?
steps:
- name: Download build artifact
uses: actions/[email protected]
Expand All @@ -351,9 +350,23 @@ jobs:
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# TODO: what permission do I need to get this to work?
# - name: Upload to GitHub
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# gh release upload ${{ github.ref_name }} dist/* --repo ${{ github.repository }}

Update:
name: Update GitHub Release
if: github.event_name == 'release'
needs: All
timeout-minutes: 1
runs-on: ubuntu-latest
# permissions:
# contents: write #TODO this should be default but maybe must be set
steps:
- name: Download build artifact
uses: actions/[email protected]
with:
name: Build
path: dist
- name: Upload to GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.ref_name }} dist/* --repo ${{ github.repository }}
2 changes: 1 addition & 1 deletion trio_parallel/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class WorkerContext(metaclass=NoPublicConstructor):
)
worker_type: WorkerType = attr.ib(
default=WorkerType.SPAWN,
validator=attr.validators.in_(WorkerType),
validator=attr.validators.in_(set(WorkerType)),
)
_worker_class: Type[AbstractWorker] = attr.ib(repr=False, init=False)
_worker_cache: WorkerCache = attr.ib(repr=False, init=False)
Expand Down
4 changes: 1 addition & 3 deletions trio_parallel/_tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def test_startup_failure_doesnt_hang(tmp_path):
"import trio,trio_parallel; trio.run(trio_parallel.run_sync, int)\n",
)
result = subprocess.run(
# note str used because cpython subprocess added the feature
# to understand path-like objects in version 3.8
[sys.executable, str(script_path)],
[sys.executable, script_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False, # we expect a failure
Expand Down
52 changes: 31 additions & 21 deletions trio_parallel/_tests/test_impl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Tests of public API with mocked-out workers ("collaboration" tests)"""
import sys
import warnings
from typing import Callable, Optional

import pytest
Expand Down Expand Up @@ -136,29 +135,40 @@ async def test_cache_scope_args(mock_context):
assert worker.idle_timeout == 33


async def test_erroneous_scope_inputs(): # pragma: no cover, ugly branching
with pytest.raises(TypeError):
async with _impl.open_worker_context(idle_timeout=[-1]):
pytest.fail("should be unreachable")
with pytest.raises(TypeError):
async with _impl.open_worker_context(init=0):
pytest.fail("should be unreachable")
with pytest.raises(TypeError):
async with _impl.open_worker_context(retire=None):
pytest.fail("should be unreachable")
def _idfn(val):
k = next(iter(val))
v = val[k]
return f"{k}-{v}"


@pytest.mark.parametrize(
"kwargs",
[
dict(idle_timeout=[-1]),
dict(init=0),
dict(retire=None),
dict(grace_period=None),
],
ids=_idfn,
)
async def test_erroneous_scope_types(kwargs):
with pytest.raises(TypeError):
async with _impl.open_worker_context(grace_period=object()):
pytest.fail("should be unreachable")
with pytest.raises(ValueError):
with warnings.catch_warnings(): # spurious DeprecationWarning on 3.7
warnings.simplefilter("ignore")
async with _impl.open_worker_context(worker_type="wrong"):
pytest.fail("should be unreachable")
with pytest.raises(ValueError):
async with _impl.open_worker_context(grace_period=-1):
async with _impl.open_worker_context(**kwargs):
pytest.fail("should be unreachable")


@pytest.mark.parametrize(
"kwargs",
[
dict(worker_type="wrong"),
dict(grace_period=-1),
dict(idle_timeout=-1),
],
ids=_idfn,
)
async def test_erroneous_scope_values(kwargs):
with pytest.raises(ValueError):
async with _impl.open_worker_context(idle_timeout=-1):
async with _impl.open_worker_context(**kwargs):
pytest.fail("should be unreachable")


Expand Down
2 changes: 1 addition & 1 deletion trio_parallel/_tests/test_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def test_ki_does_not_propagate(worker):
async def test_unpickleable(job, worker):
from pickle import PicklingError

with pytest.raises((PicklingError, AttributeError)):
with pytest.raises(PicklingError):
(await worker.run_sync(job)).unwrap()


Expand Down
2 changes: 0 additions & 2 deletions trio_parallel/_tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
All workers should pass these tests, regardless of implementation
"""
import math
import os
import sys

import pytest
import trio
Expand Down

0 comments on commit d37528a

Please sign in to comment.