Skip to content

Commit

Permalink
Merge pull request #208 from idiap/pytest
Browse files Browse the repository at this point in the history
test: switch from nose2 to pytest
  • Loading branch information
eginhard authored Jan 10, 2025
2 parents fd93176 + d749090 commit e17723a
Show file tree
Hide file tree
Showing 90 changed files with 2,990 additions and 3,364 deletions.
49 changes: 44 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
sudo apt-get install espeak espeak-ng
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git make gcc
make system-deps
- name: Install custom Trainer and/or Coqpit if requested
Expand Down Expand Up @@ -68,21 +67,20 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.9", "3.12"]
subset: ["test_tts", "test_tts2", "test_vocoder", "test_xtts", "test_zoo0", "test_zoo1", "test_zoo2"]
subset: ["test_tts", "test_tts2", "test_vocoder", "test_xtts"]
steps:
- uses: actions/checkout@v4
- name: Setup uv
uses: ./.github/actions/setup-uv
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install Espeak
if: contains(fromJSON('["test_tts", "test_tts2", "test_xtts", "test_zoo0", "test_zoo1", "test_zoo2"]'), matrix.subset)
if: contains(fromJSON('["test_tts", "test_tts2", "test_xtts"]'), matrix.subset)
run: |
sudo apt-get update
sudo apt-get install espeak espeak-ng
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git make gcc
make system-deps
- name: Install custom Trainer and/or Coqpit if requested
Expand All @@ -107,9 +105,50 @@ jobs:
name: coverage-data-${{ matrix.subset }}-${{ matrix.python-version }}
path: .coverage.*
if-no-files-found: ignore
zoo:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
partition: ["0", "1", "2"]
steps:
- uses: actions/checkout@v4
- name: Setup uv
uses: ./.github/actions/setup-uv
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install Espeak
run: |
sudo apt-get update
sudo apt-get install espeak espeak-ng
- name: Install dependencies
run: |
sudo apt-get install -y --no-install-recommends git make gcc
make system-deps
- name: Install custom Trainer and/or Coqpit if requested
run: |
if [[ -n "${{ github.event.inputs.trainer_branch }}" ]]; then
uv add git+https://github.com/idiap/coqui-ai-Trainer --branch ${{ github.event.inputs.trainer_branch }}
fi
if [[ -n "${{ github.event.inputs.coqpit_branch }}" ]]; then
uv add git+https://github.com/idiap/coqui-ai-coqpit --branch ${{ github.event.inputs.coqpit_branch }}
fi
- name: Zoo tests
run: uv run --extra server --extra languages make test_zoo
env:
NUM_PARTITIONS: 3
TEST_PARTITION: ${{ matrix.partition }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: coverage-data-zoo-${{ matrix.partition }}
path: .coverage.*
if-no-files-found: ignore
coverage:
if: always()
needs: [unit, integration]
needs: [unit, integration, zoo]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
36 changes: 15 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,42 @@ help:

target_dirs := tests TTS notebooks recipes

test_all: ## run tests and don't stop on an error.
nose2 --with-coverage --coverage TTS tests
./run_bash_tests.sh

test: ## run tests.
coverage run -m nose2 -F -v -B tests
coverage run -m pytest -x -v --durations=0 tests

test_vocoder: ## run vocoder tests.
coverage run -m nose2 -F -v -B tests.vocoder_tests
coverage run -m pytest -x -v --durations=0 tests/vocoder_tests

test_tts: ## run tts tests.
coverage run -m nose2 -F -v -B tests.tts_tests
coverage run -m pytest -x -v --durations=0 tests/tts_tests

test_tts2: ## run tts tests.
coverage run -m nose2 -F -v -B tests.tts_tests2
coverage run -m pytest -x -v --durations=0 tests/tts_tests2

test_xtts:
coverage run -m nose2 -F -v -B tests.xtts_tests
coverage run -m pytest -x -v --durations=0 tests/xtts_tests

test_aux: ## run aux tests.
coverage run -m nose2 -F -v -B tests.aux_tests
coverage run -m pytest -x -v --durations=0 tests/aux_tests
./run_bash_tests.sh

test_zoo0: ## run zoo tests.
coverage run -m nose2 -F -v -B tests.zoo_tests.test_models.test_models_offset_0_step_3 \
tests.zoo_tests.test_models.test_voice_conversion
test_zoo1: ## run zoo tests.
coverage run -m nose2 -F -v -B tests.zoo_tests.test_models.test_models_offset_1_step_3
test_zoo2: ## run zoo tests.
coverage run -m nose2 -F -v -B tests.zoo_tests.test_models.test_models_offset_2_step_3
test_zoo: ## run zoo tests.
coverage run -m pytest -x -v --durations=0 tests/zoo_tests/test_models.py

test_zoo_big: ## run tests for models that are too big for CI.
coverage run -m pytest -x -v --durations=0 tests/zoo_tests/test_big_models.py

inference_tests: ## run inference tests.
coverage run -m nose2 -F -v -B tests.inference_tests
coverage run -m pytest -x -v --durations=0 tests/inference_tests

data_tests: ## run data tests.
coverage run -m nose2 -F -v -B tests.data_tests
coverage run -m pytest -x -v --durations=0 tests/data_tests

test_text: ## run text tests.
coverage run -m nose2 -F -v -B tests.text_tests
coverage run -m pytest -x -v --durations=0 tests/text_tests

test_failed: ## only run tests failed the last time.
coverage run -m nose2 -F -v -B tests
coverage run -m pytest -x -v --last-failed tests

style: ## update code style.
uv run --only-dev black ${target_dirs}
Expand Down
2 changes: 1 addition & 1 deletion TTS/bin/compute_attention_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

# compute attentions
file_paths = []
with torch.no_grad():
with torch.inference_mode():
for data in tqdm(loader):
# setup input data
text_input = data[0]
Expand Down
15 changes: 10 additions & 5 deletions TTS/bin/compute_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
import sys
from typing import Optional

import numpy as np
from tqdm import tqdm
Expand All @@ -17,10 +18,7 @@
from TTS.utils.generic_utils import ConsoleFormatter, setup_logger


def main():
"""Run preprocessing process."""
setup_logger("TTS", level=logging.INFO, stream=sys.stderr, formatter=ConsoleFormatter())

def parse_args(arg_list: Optional[list[str]]) -> tuple[argparse.Namespace, list[str]]:
parser = argparse.ArgumentParser(description="Compute mean and variance of spectrogtram features.")
parser.add_argument("config_path", type=str, help="TTS config file path to define audio processin parameters.")
parser.add_argument("out_path", type=str, help="save path (directory and filename).")
Expand All @@ -30,7 +28,13 @@ def main():
required=False,
help="folder including the target set of wavs overriding dataset config.",
)
args, overrides = parser.parse_known_args()
return parser.parse_known_args(arg_list)


def main(arg_list: Optional[list[str]] = None):
"""Run preprocessing process."""
setup_logger("TTS", level=logging.INFO, stream=sys.stderr, formatter=ConsoleFormatter())
args, overrides = parse_args(arg_list)

CONFIG = load_config(args.config_path)
CONFIG.parse_known_args(overrides, relaxed_parser=True)
Expand Down Expand Up @@ -95,6 +99,7 @@ def main():
stats["audio_config"] = CONFIG.audio.to_dict()
np.save(output_file_path, stats, allow_pickle=True)
print(f" > stats saved to {output_file_path}")
sys.exit(0)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit e17723a

Please sign in to comment.