Skip to content

Commit 0df2915

Browse files
committed
Add pre-commit and CI
1 parent 4db967e commit 0df2915

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed

.github/workflows/tests.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-python@v2
11+
with:
12+
python-version: '3.11'
13+
- name: Install aiortc dependencies
14+
run: |
15+
sudo apt update
16+
sudo apt install libavdevice-dev libavfilter-dev libopus-dev libvpx-dev libsrtp2-dev pkg-config
17+
- name: Install package
18+
run: pip install -e .[dev]
19+
- name: Unit Tests
20+
run: |
21+
cd tests/; python -m unittest discover
22+
static_analysis:
23+
runs-on: ubuntu-20.04
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-python@v2
27+
with:
28+
python-version: '3.11'
29+
- name: Install pre-commit
30+
run: pip install pre-commit
31+
- name: Static analysis
32+
run: |
33+
pre-commit run --all

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: check-ast
6+
- id: check-json
7+
- id: check-xml
8+
- id: check-yaml
9+
- id: check-merge-conflict
10+
- id: check-symlinks
11+
- id: check-executables-have-shebangs
12+
- id: check-shebang-scripts-are-executable
13+
- repo: https://github.com/pre-commit/mirrors-mypy
14+
rev: v1.7.1
15+
hooks:
16+
- id: mypy
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.1.6
19+
hooks:
20+
- id: ruff

examples/face_detection/face_detection.py

100644100755
File mode changed.

examples/videostream_cli/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ async def run_offer(args):
7171
print("Connection established and all tracks are ready")
7272

7373
video_tracks = [stream.get_incoming_video_track(cam, False) for cam in args.cameras]
74-
audio_track, channel = None, None
74+
audio_track = None
7575
if stream.has_incoming_audio_track():
7676
audio_track = stream.get_incoming_audio_track(False)
77-
if stream.has_messaging_channel():
78-
channel = stream.get_messaging_channel()
7977
while True:
8078
try:
8179
frames = await asyncio.gather(*[track.recv() for track in video_tracks])

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dependencies = [
2424

2525
[project.optional-dependencies]
2626
dev = [
27-
"parameterized>=0.8"
27+
"parameterized>=0.8",
28+
"pre-commit"
2829
]
2930

3031
[project.urls]

tests/test_integration.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import unittest
55

6-
import aiortc
76
from aiortc.mediastreams import AudioStreamTrack, VideoStreamTrack
87
from parameterized import parameterized
98

@@ -54,13 +53,13 @@ async def test_multi_camera(self, name, cameras, recv_audio, add_messaging):
5453
offer_builder.add_messaging()
5554
stream = offer_builder.stream()
5655

57-
offer = await stream.start()
56+
_ = await stream.start()
5857
self.assertTrue(stream.is_started)
5958

6059
try:
6160
async with asyncio.timeout(2):
6261
await stream.wait_for_connection()
63-
except asyncio.TimeoutError as e:
62+
except asyncio.TimeoutError:
6463
self.fail("Timed out waiting for connection")
6564
self.assertTrue(stream.is_connected_and_ready)
6665

@@ -80,7 +79,7 @@ async def test_multi_camera(self, name, cameras, recv_audio, add_messaging):
8079
try:
8180
async with asyncio.timeout(1):
8281
await track.recv()
83-
except asyncio.TimeoutError as e:
82+
except asyncio.TimeoutError:
8483
self.fail("Timed out waiting for audio frame")
8584

8685
for cam in cameras:
@@ -94,7 +93,7 @@ async def test_multi_camera(self, name, cameras, recv_audio, add_messaging):
9493
try:
9594
async with asyncio.timeout(1):
9695
await stream.get_incoming_video_track(cam, False).recv()
97-
except asyncio.TimeoutError as e:
96+
except asyncio.TimeoutError:
9897
self.fail("Timed out waiting for video frame")
9998

10099
await stream.stop()

tests/test_stream.py

100644100755
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import unittest
44

55
import aiortc
6-
from aiortc.mediastreams import AudioStreamTrack, VideoStreamTrack
7-
from parameterized import parameterized
6+
from aiortc.mediastreams import AudioStreamTrack
87

98
from teleoprtc.builder import WebRTCOfferBuilder, WebRTCAnswerBuilder
10-
from teleoprtc.stream import StreamingOffer
119
from teleoprtc.info import parse_info_from_offer
1210
from teleoprtc.tracks import TiciVideoStreamTrack
1311

@@ -40,7 +38,7 @@ async def test_offer_stream_sdp_recvonly_audio(self):
4038

4139
try:
4240
_ = await stream.start()
43-
except Exception as e:
41+
except Exception:
4442
pass
4543

4644
info = parse_info_from_offer(capture.offer.sdp)
@@ -55,7 +53,7 @@ async def test_offer_stream_sdp_sendonly_audio(self):
5553

5654
try:
5755
_ = await stream.start()
58-
except Exception as e:
56+
except Exception:
5957
pass
6058

6159
info = parse_info_from_offer(capture.offer.sdp)
@@ -70,7 +68,7 @@ async def test_offer_stream_sdp_channel(self):
7068

7169
try:
7270
_ = await stream.start()
73-
except Exception as e:
71+
except Exception:
7472
pass
7573

7674
info = parse_info_from_offer(capture.offer.sdp)

0 commit comments

Comments
 (0)