Skip to content

Commit 7a85cfa

Browse files
committed
fixed test
1 parent 4214938 commit 7a85cfa

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

docs/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,45 @@
5555
## 🗂️ Folder Structure
5656

5757
```
58+
yt-transcript-gpt/
59+
├── .devcontainer/
60+
│ └── devcontainer.json
61+
├── .github/
62+
│ ├── ISSUE_TEMPLATE/
63+
│ │ ├── bug_report.md
64+
│ │ └── feature_request.md
65+
│ ├── PULL_REQUEST_TEMPLATE.md
66+
│ ├── RELEASE_TEMPLATE.md
67+
│ └── workflows/
68+
│ └── ci.yml
69+
├── .gitignore
70+
├── assets/
71+
│ ├── screenshots/
72+
│ │ └── screenshot.png
73+
│ └── yt-transcript-gpt-banner.jpg
74+
├── docs/
75+
│ ├── CHANGELOG.md
76+
│ ├── CODE_OF_CONDUCT.md
77+
│ ├── CONTRIBUTING.md
78+
│ ├── README.md
79+
│ ├── SECURITY.md
80+
│ ├── STATUS.md
81+
│ └── USAGE.md
82+
├── LICENSE
83+
├── pyproject.toml
84+
├── requirements.txt
85+
├── src/
86+
│ ├── app/
87+
│ │ ├── __init__.py
88+
│ │ ├── gemini_ai.py
89+
│ │ ├── main.py
90+
│ │ ├── transcript_extractor.py
91+
│ │ ├── ui.py
92+
│ │ └── utils.py
93+
│ └── main.py
94+
└── tests/
95+
├── test_gemini_ai.py
96+
└── test_transcript_extractor.py
5897
5998
```
6099

tests/test_gemini_ai.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def setUp(self, mock_configure, mock_model):
2020
self.transcript_text = "This is a test transcript."
2121

2222
def test_initialization_with_key(self):
23-
with patch("src.app.gemini_ai.genai.configure") as mock_configure, \
24-
patch("src.app.gemini_ai.genai.GenerativeModel") as mock_model:
25-
23+
with patch("src.app.gemini_ai.genai.configure") as mock_configure, patch(
24+
"src.app.gemini_ai.genai.GenerativeModel"
25+
) as mock_model:
26+
2627
gemini_ai = GeminiAI(api_key="test_key")
2728
mock_configure.assert_called_once_with(api_key="test_key")
2829
mock_model.assert_called_once_with("gemini-1.5-flash")
@@ -42,14 +43,14 @@ def test_generate_summary_success(self):
4243
mock_response = MagicMock()
4344
mock_response.text = "This is a summary."
4445
self.mock_model_instance.generate_content.return_value = mock_response
45-
46+
4647
summary = self.gemini_ai.generate_summary(self.transcript_text)
4748
self.assertEqual(summary, "This is a summary.")
4849
self.mock_model_instance.generate_content.assert_called_once()
4950

5051
def test_generate_summary_failure(self):
5152
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
52-
53+
5354
summary = self.gemini_ai.generate_summary(self.transcript_text)
5455
self.assertIn("Error generating summary", summary)
5556
self.assertIn("API Error", summary)
@@ -58,90 +59,90 @@ def test_extract_key_quotes_success(self):
5859
mock_response = MagicMock()
5960
mock_response.text = "These are key quotes."
6061
self.mock_model_instance.generate_content.return_value = mock_response
61-
62+
6263
quotes = self.gemini_ai.extract_key_quotes(self.transcript_text)
6364
self.assertEqual(quotes, "These are key quotes.")
6465

6566
def test_extract_key_quotes_failure(self):
6667
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
67-
68+
6869
quotes = self.gemini_ai.extract_key_quotes(self.transcript_text)
6970
self.assertIn("Error extracting quotes", quotes)
7071

7172
def test_create_study_guide_success(self):
7273
mock_response = MagicMock()
7374
mock_response.text = "This is a study guide."
7475
self.mock_model_instance.generate_content.return_value = mock_response
75-
76+
7677
study_guide = self.gemini_ai.create_study_guide(self.transcript_text)
7778
self.assertEqual(study_guide, "This is a study guide.")
7879

7980
def test_create_study_guide_failure(self):
8081
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
81-
82+
8283
study_guide = self.gemini_ai.create_study_guide(self.transcript_text)
8384
self.assertIn("Error creating study guide", study_guide)
8485

8586
def test_generate_qa_success(self):
8687
mock_response = MagicMock()
8788
mock_response.text = "Q: Test question?\nA: Test answer."
8889
self.mock_model_instance.generate_content.return_value = mock_response
89-
90+
9091
qa = self.gemini_ai.generate_qa(self.transcript_text)
9192
self.assertEqual(qa, "Q: Test question?\nA: Test answer.")
9293

9394
def test_generate_qa_failure(self):
9495
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
95-
96+
9697
qa = self.gemini_ai.generate_qa(self.transcript_text)
9798
self.assertIn("Error generating Q&A", qa)
9899

99100
def test_create_flashcards_success(self):
100101
mock_response = MagicMock()
101102
mock_response.text = "FRONT: Test term\nBACK: Test definition\n---"
102103
self.mock_model_instance.generate_content.return_value = mock_response
103-
104+
104105
flashcards = self.gemini_ai.create_flashcards(self.transcript_text)
105106
self.assertEqual(flashcards, "FRONT: Test term\nBACK: Test definition\n---")
106107

107108
def test_create_flashcards_failure(self):
108109
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
109-
110+
110111
flashcards = self.gemini_ai.create_flashcards(self.transcript_text)
111112
self.assertIn("Error creating flashcards", flashcards)
112113

113114
def test_highlight_insights_success(self):
114115
mock_response = MagicMock()
115116
mock_response.text = "🔍 Key Insights: Test insights"
116117
self.mock_model_instance.generate_content.return_value = mock_response
117-
118+
118119
insights = self.gemini_ai.highlight_insights(self.transcript_text)
119120
self.assertEqual(insights, "🔍 Key Insights: Test insights")
120121

121122
def test_highlight_insights_failure(self):
122123
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
123-
124+
124125
insights = self.gemini_ai.highlight_insights(self.transcript_text)
125126
self.assertIn("Error extracting insights", insights)
126127

127128
def test_chat_with_transcript_success(self):
128129
mock_response = MagicMock()
129130
mock_response.text = "This is an answer."
130131
self.mock_model_instance.generate_content.return_value = mock_response
131-
132+
132133
answer = self.gemini_ai.chat_with_transcript(
133134
self.transcript_text, "What is this?"
134135
)
135136
self.assertEqual(answer, "This is an answer.")
136137

137138
def test_chat_with_transcript_failure(self):
138139
self.mock_model_instance.generate_content.side_effect = Exception("API Error")
139-
140+
140141
answer = self.gemini_ai.chat_with_transcript(
141142
self.transcript_text, "What is this?"
142143
)
143144
self.assertIn("Error in chat", answer)
144145

145146

146147
if __name__ == "__main__":
147-
unittest.main()
148+
unittest.main()

tests/test_transcript_extractor.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,32 @@ def test_get_transcript_youtube_api_failure(self, mock_api):
4040

4141
@patch("src.app.transcript_extractor.tempfile.TemporaryDirectory")
4242
@patch("src.app.transcript_extractor.os.listdir")
43-
@patch("builtins.open", new_callable=mock_open, read_data="WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nhello from ytdlp")
43+
@patch(
44+
"builtins.open",
45+
new_callable=mock_open,
46+
read_data="WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nhello from ytdlp",
47+
)
4448
@patch("src.app.transcript_extractor.yt_dlp")
45-
def test_get_transcript_ytdlp_success(self, mock_ytdlp, mock_file, mock_listdir, mock_tempdir):
49+
def test_get_transcript_ytdlp_success(
50+
self, mock_ytdlp, mock_file, mock_listdir, mock_tempdir
51+
):
4652
# Mock the temporary directory
4753
mock_temp_path = "/tmp/test"
4854
mock_tempdir.return_value.__enter__.return_value = mock_temp_path
49-
55+
5056
# Mock the yt-dlp instance
5157
mock_ydl_instance = MagicMock()
5258
mock_ydl_instance.extract_info.return_value = {
5359
"title": "Test Video",
5460
"duration": 60,
5561
"subtitles": {},
56-
"automatic_captions": {}
62+
"automatic_captions": {},
5763
}
5864
mock_ytdlp.YoutubeDL.return_value.__enter__.return_value = mock_ydl_instance
59-
65+
6066
# Mock file listing to return a VTT file
6167
mock_listdir.return_value = ["test_video.en.vtt"]
62-
68+
6369
transcript = self.extractor.get_transcript_ytdlp("dQw4w9WgXcQ")
6470
self.assertIsNotNone(transcript)
6571
if transcript:
@@ -111,7 +117,7 @@ def test_parse_vtt_content(self):
111117
112118
00:00:01.000 --> 00:00:02.000
113119
this is a test"""
114-
120+
115121
transcript = self.extractor._parse_vtt_content(vtt_content)
116122
self.assertEqual(len(transcript), 2)
117123
self.assertEqual(transcript[0]["text"], "hello world")
@@ -127,7 +133,7 @@ def test_parse_srt_content(self):
127133
2
128134
00:00:01,000 --> 00:00:02,000
129135
this is a test"""
130-
136+
131137
transcript = self.extractor._parse_srt_content(srt_content)
132138
self.assertEqual(len(transcript), 2)
133139
self.assertEqual(transcript[0]["text"], "hello world")
@@ -149,4 +155,4 @@ def test_parse_srt_timestamp(self):
149155

150156

151157
if __name__ == "__main__":
152-
unittest.main()
158+
unittest.main()

0 commit comments

Comments
 (0)