-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
054589b
commit c4d3a53
Showing
6 changed files
with
109 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Minimal and Full Tests | ||
on: | ||
schedule: | ||
- cron: "0 16 * * *" # Daily at noon EST | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run: | ||
name: ${{ matrix.os }} Python ${{ matrix.python-version }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
steps: | ||
- uses: s-weigand/setup-conda@v1 | ||
- uses: actions/checkout@v3 | ||
- run: git fetch --prune --unshallow --tags | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Global Setup | ||
run: | | ||
python -m pip install -U pip # Official recommended way | ||
pip install pytest-xdist | ||
- name: Install tqdm_publisher with minimal requirements | ||
run: pip install .[test] | ||
|
||
- name: Run full pytest with coverage | ||
run: pytest -rsx -n auto --dist loadscope --cov=./ --cov-report xml:./codecov.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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
__pycache__/ | ||
*.egg-info | ||
dist | ||
dist | ||
|
||
.coverage | ||
.coverage.* | ||
codecov.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
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 @@ | ||
from tqdm_publisher import TQDMPublisher | ||
import pytest | ||
from utils import create_tasks | ||
import asyncio | ||
|
||
def test_initialization(): | ||
publisher = TQDMPublisher() | ||
assert len(publisher.callbacks) == 0 | ||
|
||
@pytest.mark.asyncio | ||
async def test_subscription_and_callback_execution(): | ||
n_callback_executions = 0 | ||
|
||
def test_callback(data): | ||
nonlocal n_callback_executions | ||
n_callback_executions += 1 | ||
assert 'n' in data and 'total' in data | ||
|
||
tasks = create_tasks() | ||
publisher = TQDMPublisher(asyncio.as_completed(tasks), total=len(tasks)) | ||
callback_id = publisher.subscribe(test_callback) | ||
|
||
assert callback_id in publisher.callbacks | ||
|
||
# Simulate an update to trigger the callback | ||
for f in publisher: | ||
await f | ||
|
||
assert n_callback_executions > 0 | ||
|
||
def test_unsubscription(): | ||
def dummy_callback(data): | ||
pass | ||
|
||
tasks = [] | ||
publisher = TQDMPublisher(asyncio.as_completed(tasks), total=len(tasks)) | ||
callback_id = publisher.subscribe(dummy_callback) | ||
result = publisher.unsubscribe(callback_id) | ||
assert result == True | ||
assert callback_id not in publisher.callbacks |
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,17 @@ | ||
import asyncio | ||
import random | ||
|
||
async def sleep_func(sleep_duration: float = 1) -> float: | ||
await asyncio.sleep(delay=sleep_duration) | ||
|
||
|
||
def create_tasks(): | ||
n = 10**5 | ||
sleep_durations = [random.uniform(0, 5.0) for _ in range(n)] | ||
tasks = [] | ||
|
||
for sleep_duration in sleep_durations: | ||
task = asyncio.create_task(sleep_func(sleep_duration=sleep_duration)) | ||
tasks.append(task) | ||
|
||
return tasks |