Skip to content

Commit

Permalink
unittests.yml: Add macOS to the testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Nov 11, 2024
1 parent 73c8cdf commit 2cfc074
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,50 @@ on:
jobs:
build:
strategy:
fail-fast: true
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.10"
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: windows-latest
python-version: "3.11"
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: macos-latest
python-version: "3.13"
- os: windows-latest
python-version: "3.11"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install build dependencies
if: matrix.os == 'ubuntu-latest'
- run: python -m pip install --upgrade pip
- name: Install build dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y libpulse-dev libasound2-dev
sudo apt-get install --no-install-recommends -y portaudio19-dev
sudo apt-get install --no-install-recommends -y libpulse-dev libasound2-dev portaudio19-dev
- name: Install ffmpeg (for Whisper)
if: runner.os != 'macOS'
uses: FedericoCarboni/setup-ffmpeg@v3
- name: Install Python dependencies (Ubuntu, <=3.12)
if: matrix.os == 'ubuntu-latest' && matrix.python-version != '3.13'
if: runner.os == 'Linux' && matrix.python-version != '3.13'
run: |
python -m pip install .[dev,audio,pocketsphinx,whisper-local,whisper-api]
- name: Install Python dependencies (Ubuntu, 3.13)
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13'
if: runner.os == 'Linux' && matrix.python-version == '3.13'
run: |
python -m pip install standard-aifc setuptools
python -m pip install --no-build-isolation .[dev,audio,pocketsphinx,whisper-api]
- name: Install Python dependencies (macOS, 3.13)
if: runner.os == 'macOS'
run: |
brew install portaudio
python -m pip install pocketsphinx standard-aifc setuptools
python -m pip install --no-build-isolation .[dev,audio,whisper-api]
- name: Install Python dependencies (Windows)
if: matrix.os == 'windows-latest'
if: runner.os == 'Windows'
run: |
python -m pip install .[dev,whisper-local,whisper-api]
- name: Test with unittest
run: |
pytest --doctest-modules -v speech_recognition/recognizers/ tests/
pytest --doctest-modules --strict -v -W="ignore: aifc" speech_recognition/recognizers/ tests/
3 changes: 2 additions & 1 deletion tests/test_special_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ def setUp(self):
self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav")
self.addTypeEqualityFunc(str, self.assertSameWords)

@unittest.skipIf(sys.platform.startswith("win"), "skip on Windows")
@unittest.skipIf(sys.platform.startswith(("darwin", "win")), "skip on macOS and Windows")
def test_sphinx_keywords(self):
r = sr.Recognizer()
with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source)
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("one", 1.0), ("two", 1.0), ("three", 1.0)]), "three two one")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "tree too wan")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un")

@unittest.skipIf(sys.platform == "darwin", "skip on macOS")
def assertSameWords(self, tested, reference, msg=None):
set_tested = set(tested.split())
set_reference = set(reference.split())
Expand Down

0 comments on commit 2cfc074

Please sign in to comment.