Skip to content

Commit

Permalink
test: Refactor environment variable handling in test suite
Browse files Browse the repository at this point in the history
- Add environment variables for API keys in test main file
- Update test functions with patches for new environment variables
  • Loading branch information
johnnyhuy committed Apr 4, 2024
1 parent d856b8a commit 1f0e521
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def create(self, *args, **kwargs):

class TestMain(unittest.TestCase):

@patch.dict('os.environ', {'OPENAI_API_KEY': 'mock_api_key', 'ANTHROPIC_API_KEY': 'mock_api_key'})
@patch('os.path.splitext')
@patch('transcribe_me.main.AudioSegment.from_file')
def test_split_audio(self, mock_from_file, mock_splitext):
Expand All @@ -36,6 +37,7 @@ def test_split_audio(self, mock_from_file, mock_splitext):
result = main.split_audio('file.mp3')
self.assertEqual(result, ['file_part1.mp3'])

@patch.dict('os.environ', {'OPENAI_API_KEY': 'mock_api_key', 'ANTHROPIC_API_KEY': 'mock_api_key'})
@patch('openai.audio.transcriptions.create')
@patch('builtins.open', new_callable=mock_open, read_data="data")
def test_transcribe_chunk(self, mock_open, mock_create):
Expand All @@ -44,6 +46,7 @@ def test_transcribe_chunk(self, mock_open, mock_create):
result = main.transcribe_chunk('file.mp3')
self.assertEqual(result, 'transcription')

@patch.dict('os.environ', {'OPENAI_API_KEY': 'mock_api_key', 'ANTHROPIC_API_KEY': 'mock_api_key'})
@patch('os.remove')
@patch('transcribe_me.main.split_audio')
@patch('transcribe_me.main.transcribe_chunk')
Expand Down

0 comments on commit 1f0e521

Please sign in to comment.