diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..22cbeed --- /dev/null +++ b/.github/workflows/tests.yaml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..62edf45 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/examples/face_detection/face_detection.py b/examples/face_detection/face_detection.py old mode 100644 new mode 100755 diff --git a/examples/videostream_cli/cli.py b/examples/videostream_cli/cli.py index 936dd3b..9640edc 100755 --- a/examples/videostream_cli/cli.py +++ b/examples/videostream_cli/cli.py @@ -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]) diff --git a/pyproject.toml b/pyproject.toml index ee95efe..9fad067 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,8 @@ dependencies = [ [project.optional-dependencies] dev = [ - "parameterized>=0.8" + "parameterized>=0.8", + "pre-commit" ] [project.urls] diff --git a/tests/test_integration.py b/tests/test_integration.py index 9ad5209..cf567eb 100755 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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() diff --git a/tests/test_stream.py b/tests/test_stream.py old mode 100644 new mode 100755 index fe28e83..615c9ba --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -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)