-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor project structure and workflow.
- Added new unit tests for key functions in main.py - Refactored Makefile for better organization - Added a new step "Test" in the GitHub workflow.
- Loading branch information
Showing
6 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ jobs: | |
|
||
- name: Install | ||
run: make install | ||
|
||
- name: Test | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
venv | ||
*.egg-info | ||
build | ||
build | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import unittest | ||
from unittest.mock import patch, mock_open | ||
import argparse | ||
from transcribe_me import main | ||
|
||
class MockAudioSegment: | ||
def __init__(self, length): | ||
self.length = length | ||
|
||
def __len__(self): | ||
return self.length | ||
|
||
def __getitem__(self, index): | ||
return self | ||
|
||
def export(self, *args, **kwargs): | ||
pass | ||
|
||
class MockTranscription: | ||
def __init__(self, text): | ||
self.text = text | ||
|
||
class MockAnthropic: | ||
class Messages: | ||
def create(self, *args, **kwargs): | ||
return 'summary' | ||
messages = Messages() | ||
|
||
class TestMain(unittest.TestCase): | ||
|
||
@patch('os.path.splitext') | ||
@patch('transcribe_me.main.AudioSegment.from_file') | ||
def test_split_audio(self, mock_from_file, mock_splitext): | ||
mock_splitext.return_value = ('file', '.mp3') | ||
mock_from_file.return_value = MockAudioSegment(1000) | ||
result = main.split_audio('file.mp3') | ||
self.assertEqual(result, ['file_part1.mp3']) | ||
|
||
@patch('openai.audio.transcriptions.create') | ||
@patch('builtins.open', new_callable=mock_open, read_data="data") | ||
def test_transcribe_chunk(self, mock_open, mock_create): | ||
mock_transcription = MockTranscription('transcription') | ||
mock_create.return_value = mock_transcription | ||
result = main.transcribe_chunk('file.mp3') | ||
self.assertEqual(result, 'transcription') | ||
|
||
@patch('os.remove') | ||
@patch('transcribe_me.main.split_audio') | ||
@patch('transcribe_me.main.transcribe_chunk') | ||
@patch('builtins.open', new_callable=mock_open) | ||
def test_transcribe_audio(self, mock_open, mock_transcribe_chunk, mock_split_audio, mock_remove): | ||
mock_split_audio.return_value = ['file_part1.mp3'] | ||
mock_transcription = MockTranscription('transcription') | ||
mock_transcribe_chunk.return_value = mock_transcription | ||
main.transcribe_audio('file.mp3', 'output.txt') | ||
mock_open.assert_called_with('output.txt', 'w', encoding='utf-8') | ||
mock_remove.assert_called_with('file_part1.mp3') | ||
|
||
# @patch('transcribe_me.main.anthropic.Anthropic', new=MockAnthropic()) | ||
# def test_generate_summary_openai(self): | ||
# model_config = { | ||
# "temperature": 0.1, | ||
# "max_tokens": 2048, | ||
# "model": "gpt-4", | ||
# "system_prompt": "Generate a summary with key points in bold and a Next Steps section, use Markdown, be a concise tech expert but kind to non-technical readers.", | ||
# } | ||
# result = main.generate_summary('transcription', model_config) | ||
# self.assertEqual(result, 'summary') | ||
|
||
# @patch('anthropic.Anthropic') | ||
# def test_generate_summary_anthropic(self, mock_anthropic): | ||
# mock_anthropic.return_value = 'summary' | ||
# model_config = { | ||
# "temperature": 0.1, | ||
# "max_tokens": 2048, | ||
# "model": "claude-3-sonnet-20240229", | ||
# "system_prompt": "Generate a summary with key points in bold and a Next Steps section, use Markdown, be a concise tech expert but kind to non-technical readers.", | ||
# } | ||
# result = main.generate_summary('transcription', model_config) | ||
# self.assertEqual(result, 'summary') | ||
|
||
# @patch('argparse.ArgumentParser.parse_args') | ||
# @patch('os.makedirs') | ||
# @patch('os.listdir') | ||
# @patch('os.path.exists') | ||
# @patch('transcribe_me.main.transcribe_audio') | ||
# @patch('transcribe_me.main.generate_summary') | ||
# @patch('builtins.open', new_callable=mock_open, read_data="data") | ||
# def test_main(self, mock_open, mock_generate_summary, mock_transcribe_audio, mock_exists, mock_listdir, mock_makedirs, mock_parse_args): | ||
# mock_parse_args.return_value = argparse.Namespace(command=None, input='input', output='output') | ||
# mock_listdir.return_value = ['file1', 'file2'] | ||
# mock_exists.side_effect = [False, False, True, True] | ||
# mock_generate_summary.return_value = 'summary' | ||
# main.main() | ||
# mock_makedirs.assert_called() | ||
# mock_transcribe_audio.assert_called() | ||
# mock_generate_summary.assert_called() | ||
# mock_open.assert_called() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters