Add pre-commit and CI

This commit is contained in:
Kacper Rączy 2023-11-29 12:33:19 -08:00
parent 4db967e4e2
commit 0df2915477
7 changed files with 64 additions and 15 deletions

33
.github/workflows/tests.yaml vendored Normal file
View File

@ -0,0 +1,33 @@
name: tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install aiortc dependencies
run: |
sudo apt update
sudo apt install libavdevice-dev libavfilter-dev libopus-dev libvpx-dev libsrtp2-dev pkg-config
- name: Install package
run: pip install -e .[dev]
- name: Unit Tests
run: |
cd tests/; python -m unittest discover
static_analysis:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install pre-commit
run: pip install pre-commit
- name: Static analysis
run: |
pre-commit run --all

20
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-json
- id: check-xml
- id: check-yaml
- id: check-merge-conflict
- id: check-symlinks
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff

0
examples/face_detection/face_detection.py Normal file → Executable file
View File

View File

@ -71,11 +71,9 @@ async def run_offer(args):
print("Connection established and all tracks are ready")
video_tracks = [stream.get_incoming_video_track(cam, False) for cam in args.cameras]
audio_track, channel = None, None
audio_track = None
if stream.has_incoming_audio_track():
audio_track = stream.get_incoming_audio_track(False)
if stream.has_messaging_channel():
channel = stream.get_messaging_channel()
while True:
try:
frames = await asyncio.gather(*[track.recv() for track in video_tracks])

View File

@ -24,7 +24,8 @@ dependencies = [
[project.optional-dependencies]
dev = [
"parameterized>=0.8"
"parameterized>=0.8",
"pre-commit"
]
[project.urls]

View File

@ -3,7 +3,6 @@
import asyncio
import unittest
import aiortc
from aiortc.mediastreams import AudioStreamTrack, VideoStreamTrack
from parameterized import parameterized
@ -54,13 +53,13 @@ class TestStreamIntegration(unittest.IsolatedAsyncioTestCase):
offer_builder.add_messaging()
stream = offer_builder.stream()
offer = await stream.start()
_ = await stream.start()
self.assertTrue(stream.is_started)
try:
async with asyncio.timeout(2):
await stream.wait_for_connection()
except asyncio.TimeoutError as e:
except asyncio.TimeoutError:
self.fail("Timed out waiting for connection")
self.assertTrue(stream.is_connected_and_ready)
@ -80,7 +79,7 @@ class TestStreamIntegration(unittest.IsolatedAsyncioTestCase):
try:
async with asyncio.timeout(1):
await track.recv()
except asyncio.TimeoutError as e:
except asyncio.TimeoutError:
self.fail("Timed out waiting for audio frame")
for cam in cameras:
@ -94,7 +93,7 @@ class TestStreamIntegration(unittest.IsolatedAsyncioTestCase):
try:
async with asyncio.timeout(1):
await stream.get_incoming_video_track(cam, False).recv()
except asyncio.TimeoutError as e:
except asyncio.TimeoutError:
self.fail("Timed out waiting for video frame")
await stream.stop()

10
tests/test_stream.py Normal file → Executable file
View File

@ -3,11 +3,9 @@
import unittest
import aiortc
from aiortc.mediastreams import AudioStreamTrack, VideoStreamTrack
from parameterized import parameterized
from aiortc.mediastreams import AudioStreamTrack
from teleoprtc.builder import WebRTCOfferBuilder, WebRTCAnswerBuilder
from teleoprtc.stream import StreamingOffer
from teleoprtc.info import parse_info_from_offer
from teleoprtc.tracks import TiciVideoStreamTrack
@ -40,7 +38,7 @@ class TestOfferStream(unittest.IsolatedAsyncioTestCase):
try:
_ = await stream.start()
except Exception as e:
except Exception:
pass
info = parse_info_from_offer(capture.offer.sdp)
@ -55,7 +53,7 @@ class TestOfferStream(unittest.IsolatedAsyncioTestCase):
try:
_ = await stream.start()
except Exception as e:
except Exception:
pass
info = parse_info_from_offer(capture.offer.sdp)
@ -70,7 +68,7 @@ class TestOfferStream(unittest.IsolatedAsyncioTestCase):
try:
_ = await stream.start()
except Exception as e:
except Exception:
pass
info = parse_info_from_offer(capture.offer.sdp)