Skip to content

Commit

Permalink
Fix github action to trigger all unit and integration tests. (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
HanFa authored Feb 16, 2025
1 parent 8f99d7f commit d81da19
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 110 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/docker-build.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/docker-release.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/docker-workload-release.yaml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/easyvideotrans-pr-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: EasyVideoTrans Docker PR Build

on:
pull_request:
branches: [ master ]

jobs:
build:
runs-on: self-hosted

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build EasyVideoTrans service
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: hanfa/easyvideotrans:${{github.event.pull_request.number}}

- name: Build EasyVideoTrans workloads
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile-gpu-workload
push: false
tags: hanfa/easyvideotrans-workloads:${{github.event.pull_request.number}}
32 changes: 32 additions & 0 deletions .github/workflows/easyvideotrans-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: EasyVideoTrans Service Docker Image Release

on:
workflow_run:
workflows: [ "EasyVideoTrans application test" ]
branches: [ "master" ]
types:
- completed

jobs:
build:
runs-on: self-hosted

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: hanfa/easyvideotrans:latest
32 changes: 32 additions & 0 deletions .github/workflows/easyvideotrans-workloads-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: EasyVideoTrans Workloads Docker Image Release

on:
workflow_run:
workflows: [ "EasyVideoTrans application test" ]
branches: [ "master" ]
types:
- completed

jobs:
build:
runs-on: self-hosted

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: hanfa/easyvideotrans-workloads:latest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pytvzhen-web application test
name: EasyVideoTrans application test

on:
push:
Expand Down Expand Up @@ -28,5 +28,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run PytvzhenAPI integration tests
run: python -m unittest -v test_app.PytvzhenAPITest
- name: Install PyTest
run: pip install pytest
- name: Run all EasyVideoTrans tests
run: pytest .
4 changes: 2 additions & 2 deletions test_app.py → app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from src.service.tts.edge_tts import EdgeTTSClient


class PytvzhenUnitTest(unittest.TestCase):
class EasyVideoTransUnitTest(unittest.TestCase):

def test_video_url_rule_to_base_succeeds(self):
assert url_rule_to_base("/videos/<video_id>") == "/videos"
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_edge_tts_run_convert_srt_to_voice_edge_coroutines_cancel_pending_tasks_
assert EdgeTTSClient._run_convert_srt_to_voice_edge_coroutines(coroutines) == 2


class PytvzhenAPITest(unittest.TestCase):
class EasyVideoTransAPITest(unittest.TestCase):

def setUp(self):
self.test_dir = tempfile.mkdtemp()
Expand Down
16 changes: 8 additions & 8 deletions inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def client():
yield client


@patch("workloads.inference.os.path.exists", return_value=True)
@patch("workloads.inference.os.path.getsize", return_value=1024) # Mock file size
@patch("workloads.inference.load_spectrogram", return_value=("mock_spectrogram", 44100))
@patch("inference.os.path.exists", return_value=True)
@patch("inference.os.path.getsize", return_value=1024) # Mock file size
@patch("inference.load_spectrogram", return_value=("mock_spectrogram", 44100))
@patch.object(separator, "separate_tta", return_value=("mock_bg_spec", "mock_v_spec"))
@patch("workloads.lib.spec_utils.spectrogram_to_wave", return_value=np.array([[0.1, 0.2], [0.3, 0.4]]))
@patch("workloads.inference.sf.write") # Mock sound file write function
@patch("inference.sf.write") # Mock sound file write function
def test_audio_separation_success(mock_sf_write, mock_spec_to_wave, mock_separate, mock_load_spec, mock_getsize,
mock_exists, client):
"""Test successful audio separation."""
Expand All @@ -40,7 +40,7 @@ def test_audio_separation_missing_file_path(client):
assert "error" in data and "Invalid request" in data["error"]


@patch("workloads.inference.os.path.exists", return_value=False)
@patch("inference.os.path.exists", return_value=False)
def test_audio_separation_file_not_found(mock_exists, client):
"""Test when the provided file path does not exist."""
response = client.post("/audio-sep", json={"file_name": "invalid_path.wav"})
Expand All @@ -49,9 +49,9 @@ def test_audio_separation_file_not_found(mock_exists, client):
assert "error" in data and "File not found" in data["error"]


@patch("workloads.inference.os.path.exists", return_value=True)
@patch("workloads.inference.os.path.getsize", return_value=100)
@patch("workloads.inference.load_spectrogram", side_effect=Exception("Spectrogram error"))
@patch("inference.os.path.exists", return_value=True)
@patch("inference.os.path.getsize", return_value=100)
@patch("inference.load_spectrogram", side_effect=Exception("Spectrogram error"))
def test_audio_separation_internal_error(mock_load_spectrogram, mock_getsize, mock_exists, client):
"""Test when an internal error occurs during processing."""
response = client.post("/audio-sep", json={"file_name": "audio.wav"})
Expand Down
4 changes: 2 additions & 2 deletions src/test_workload_client.py → src/workload_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_separate_audio_success(self, mock_post):
mock_post.assert_called_once_with(
"http://localhost:8199/audio-sep",
json={"file_name": "test_audio.wav"},
timeout=120
timeout=180
)

@patch("requests.post")
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_transcribe_audio_success(self, mock_post):
mock_post.assert_called_once_with(
"http://localhost:8199/audio-transcribe",
json={"file_name": "test_audio.wav", "output_filenames": ["transcript.txt", "summary.txt"]},
timeout=60
timeout=180
)

@patch("requests.post")
Expand Down

0 comments on commit d81da19

Please sign in to comment.