Skip to content

Commit

Permalink
Merge pull request #46 from DSProjects2024/raagul/more_tests
Browse files Browse the repository at this point in the history
Additional tests
  • Loading branch information
abhinavdv authored Mar 13, 2024
2 parents 4abad6a + 646dacc commit 8da4bae
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 195 deletions.
8 changes: 8 additions & 0 deletions thronetalk-game-of-thrones-summarizer/tests/mock_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@
world of Game of Thrones. The storylines are intricately woven, and the
characters face constant challenges and moral dilemmas as they navigate
this treacherous landscape.'''

TEST_CHARACTER = 'waymar royce'

WAYMAR_ROYCE_DIALOG_STRING = '''What d’you expect? They’re savages. One lot steals a goat from
another lot and before you know it, they’re ripping each other to pieces. How close did you get?'''

WAYMAR_ROYCE_SENTIMENT_STRING = '''What ’ expect ? They ’ savage . One lot steal goat another lot
know , ’ ripping piece . How close get ?'''
72 changes: 20 additions & 52 deletions thronetalk-game-of-thrones-summarizer/tests/mock_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,30 @@
import pandas as pd
from . import mock_constants

def mocked_read_csv_ouput_dialogues():
# *args is required to catch arguments passed while using with
# unittest's @patch, disabling the pylint warning.
# pylint: disable=unused-argument
def mocked_read_csv_ouput_dialogues(*args):
"""
Mocking pandas' read_csv function for output_dialogues.
Mock for pandas' read_csv function for output_dialogues.
"""
data_output_dialogues_raw = '''
,Text,Speaker,Episode,Season,Show,Episode_name,Episode_Number,Season_Number,dialogue_with_speaker
0,"[First scene opens with three Rangers riding through a tunnel, leaving the Wall, and going into the woods. (Eerie music in background) One Ranger splits off and finds a campsite full of mutilated bodies, including a child hanging from a tree branch. A birds-eye view shows the bodies arranged in a shield-like pattern. The Ranger rides back to the other two.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:First scene opens with three Rangers riding through a tunnel, leaving the Wall, and going into the woods. (Eerie music in background) One Ranger splits off and finds a campsite full of mutilated bodies, including a child hanging from a tree branch. A birds-eye view shows the bodies arranged in a shield-like pattern. The Ranger rides back to the other two."
1," What d’you expect? They’re savages. One lot steals a goat from another lot and before you know it, they’re ripping each other to pieces.",WAYMAR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"WAYMAR ROYCE: What d’you expect? They’re savages. One lot steals a goat from another lot and before you know it, they’re ripping each other to pieces."
2," I’ve never seen wildlings do a thing like this. I’ve never seen a thing like this, not ever in my life.",WILL,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"WILL: I’ve never seen wildlings do a thing like this. I’ve never seen a thing like this, not ever in my life."
3, How close did you get?,WAYMAR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,WAYMAR ROYCE: How close did you get?
4, Close as any man would.,WILL,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,WILL: Close as any man would.
5, We should head back to the wall.,GARED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,GARED: We should head back to the wall.
6, Do the dead frighten you?,ROYCE,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,ROYCE: Do the dead frighten you?
7, Our orders were to track the wildlings. We tracked them. They won’t trouble us no more.,GARED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,GARED: Our orders were to track the wildlings. We tracked them. They won’t trouble us no more.
8, You don’t think he’ll ask us how they died? Get back on your horse.,ROYCE,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,ROYCE: You don’t think he’ll ask us how they died? Get back on your horse.
9,[GARED grumbles.],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:GARED grumbles.
10, Whatever did it to them could do it to us. They even killed the children.,WILL,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,WILL: Whatever did it to them could do it to us. They even killed the children.
11," It’s a good thing we’re not children. You want to run away south, run away. Of course, they will behead you as a deserter … If I don’t catch you first. Get back on your horse. I won’t say it again.",ROYCE,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"ROYCE: It’s a good thing we’re not children. You want to run away south, run away. Of course, they will behead you as a deserter … If I don’t catch you first. Get back on your horse. I won’t say it again."
12,"[WILL glares, but obeys. Sometime later, the three Rangers return to the campsite, which is now completely cleared.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:WILL glares, but obeys. Sometime later, the three Rangers return to the campsite, which is now completely cleared."
13, Your dead men seem to have moved camp.,ROYCE,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,ROYCE: Your dead men seem to have moved camp.
14, They were here.,WILL,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,WILL: They were here.
15, See where they went.,GARED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,GARED: See where they went.
16,"[The three look around, swords drawn. They hear the wind and eerie calls. GARED finds a red cloth in the snow.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:The three look around, swords drawn. They hear the wind and eerie calls. GARED finds a red cloth in the snow."
17, What is it?,ROYCE,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,ROYCE: What is it?
18, It’s …,GARED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,GARED: It’s …
19,"[As he speaks, a CREATURE with glowing blue eyes rises behind ROYCE. ROYCE turns, the CREATURE strikes. The scene shifts to WILL, who hears a man crying out. The three horses stampede past him. He turns and sees someone standing very still in the distance. The figure turns – it’s the child who had been suspended in the tree, now with glowing blue eyes. WILL turns and runs.",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:As he speaks, a CREATURE with glowing blue eyes rises behind ROYCE. ROYCE turns, the CREATURE strikes. The scene shifts to WILL, who hears a man crying out. The three horses stampede past him. He turns and sees someone standing very still in the distance. The figure turns – it’s the child who had been suspended in the tree, now with glowing blue eyes. WILL turns and runs."
20,"GARED is also fleeing, and we hear strange growls and catch glimpses of the CREATURE. Both terrified RANGERS stop, some distance apart, to catch their breath. WILL sees a CREATURE behead GARED. WILL sinks to his knees and the CREATURE tosses GARED’S head to him.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:GARED is also fleeing, and we hear strange growls and catch glimpses of the CREATURE. Both terrified RANGERS stop, some distance apart, to catch their breath. WILL sees a CREATURE behead GARED. WILL sinks to his knees and the CREATURE tosses GARED’S head to him."
21,[Blackout],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:Blackout
22,"TITLE SEQUENCE[Riders from Winterfell come up behind a dazed WILL. The scene shifts to the castle, where BRAN is practicing archery and getting frustrated, under the eyes of JON SNOW and ROBB STARK. JON pats BRAN’S shoulder.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:TITLE SEQUENCERiders from Winterfell come up behind a dazed WILL. The scene shifts to the castle, where BRAN is practicing archery and getting frustrated, under the eyes of JON SNOW and ROBB STARK. JON pats BRAN’S shoulder."
23, Go on. Father’s watching.,JON,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,JON: Go on. Father’s watching.
24,[We see NED and CATELYN STARK watching from above.],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:We see NED and CATELYN STARK watching from above.
25, And your mother.,JON,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,JON: And your mother.
26,[Scene shifts to needlework practice with the girls inside the castle.],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:Scene shifts to needlework practice with the girls inside the castle.
27," Fine work, as always. Well done.",SEPTA,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"SEPTA MORDANE (to SANSA): Fine work, as always. Well done."
28, Thank you.,SANSA,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,SANSA: Thank you.
29, I love the detail that you’ve managed to get in this corners. … Quite beautiful … the stitching …,SEPTA,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,SEPTA MORDANE: I love the detail that you’ve managed to get in this corners. … Quite beautiful … the stitching …
30,"[As she murmurs to SANSA about the embroidery, ARYA struggles with her needlework and listens to the arrows hitting and the male laughter outside.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:As she murmurs to SANSA about the embroidery, ARYA struggles with her needlework and listens to the arrows hitting and the male laughter outside."
31,"[Outside, BRAN tries and misses again. Everyone laughs.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:Outside, BRAN tries and misses again. Everyone laughs."
32," And which one of you was a marksman at ten? Keep practicing, Bran. Go on.",NED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NED: And which one of you was a marksman at ten? Keep practicing, Bran. Go on."
33," Don’t think too much, Bran.",JON,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"JON: Don’t think too much, Bran."
34, Relax your bow arm.,ROBB,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,ROBB: Relax your bow arm.
35,"[BRAN pulls the arrow back. An arrow hits the bullseye. BRAN (still with his arrow), JON, and ROBB turn in surprise to see ARYA, who curtsies after her perfect shot. ROBB and JON laugh as Bran takes out after ARYA.]",NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"NARRATOR:BRAN pulls the arrow back. An arrow hits the bullseye. BRAN (still with his arrow), JON, and ROBB turn in surprise to see ARYA, who curtsies after her perfect shot. ROBB and JON laugh as Bran takes out after ARYA."
36," Quick, Bran, faster!",JON/ROBB,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,"JON/ROBB: Quick, Bran, faster!"
37,[RODRICK CASSEL and THEON GREYJOY approach NED and CATELYN on the balcony.],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:RODRICK CASSEL and THEON GREYJOY approach NED and CATELYN on the balcony.
38, Lord Stark. My lady. A guardsman just rode in from the hills. They’ve captured a deserter from the Night’s Watch.,CASSEL,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,CASSEL: Lord Stark. My lady. A guardsman just rode in from the hills. They’ve captured a deserter from the Night’s Watch.
39,[NED grimaces.],NARRATOR,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NARRATOR:NED grimaces.
40, Get the lads to saddle their horses.,NED,e1,season-01,Game-of-Thrones,Winter is Coming,1,1,NED: Get the lads to saddle their horses.
'''
lines = data_output_dialogues_raw.splitlines()
data = [line.split(',') for line in lines[1:]]
dataframe = pd.DataFrame(data[1:], columns=data[0])
# mock_output_dialogues_raw = pd.read_csv(StringIO(data_output_dialogues_raw))
mock_rows = [
[0,"Hello brother.","","","","","",1,1,"","jon snow"],
[1,"Valar Morghulis.","","","","","",1,1,"","arya stark"],
[2,"Previously on...","","","","","",1,1,"","narrator"],
[3,"The North remembers.","","","","","",1,1,"","arya stark"],
[4,"hi brother","","","","","",1,1,"","jon snow"],
[5,"Valar Morghulis.","","","","","",1,1,"","arya stark"],
[6,"Previously on...","","","","","",1,1,"","narrator"],
[7,"The North remembers.","","","","","",1,1,"","arya stark"],
]
columns = [
'', 'Text','Speaker','Episode','Season','Show','Episode_name',
'Episode_Number','Season_Number','dialogue_with_speaker','Character'
]
dataframe = pd.DataFrame(mock_rows, columns=columns)
return dataframe

# *args is required to catch arguments passed while using with
# unittest's @patch, disabling the pylint warning.
# pylint: disable=unused-argument
def mock_model_azure_api_call(*args):
'''Mocks the response of azure_api_call from model.py's Model class.'''
Expand Down
90 changes: 0 additions & 90 deletions thronetalk-game-of-thrones-summarizer/tests/test_get_metadata.py

This file was deleted.

25 changes: 10 additions & 15 deletions thronetalk-game-of-thrones-summarizer/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
from . import mock_constants

class TestModel(unittest.TestCase):
# def setUp(self):
# self.model = Model(1, 1, 1, 1)

'''Test suite for `scripts/model.py`'''
# Smoke tests
# @patch('scripts.visualization_generator.pd.read_csv',
# side_effect=mock_functions.mocked_read_csv_ouput_dialogues)
def test_smoke_test(self):
'''Smoke test for Model'''
Model(1,1,1,3)
model = Model(1,1,1,3)
self.assertIsInstance(model, Model)

# Edge tests
def test_init_error(self):
def test_edge_init(self):
'''Edge tests for Model'''
with self.assertRaises(TypeError):
Model() # pylint: disable=no-value-for-parameter
Expand All @@ -35,9 +29,9 @@ def test_init_error(self):
with self.assertRaises(ValueError):
Model(2,1,1,1)

# One-shot test
def test_create_summarizer_input_error(self):
'''One-shot test for create_summarizer_input function'''
def test_integration_create_summarizer_input(self):
'''Integration test to check if create_summarizer_input function
works with the remaining functions properly.'''
# We remove all whitespaces and compare because assertEqual fails
# for multiline f-strings
def get_message_content(season_from, episode_from, season_to, episode_to):
Expand All @@ -59,12 +53,13 @@ def get_message_content(season_from, episode_from, season_to, episode_to):
self.assertEqual(expected_message, computed_message)

@patch('utils.model.Model.azure_api_call')
def test_summarize(self, mock_summarize):
'''Test for summarize function'''
def test_integration_summarize(self, mock_summarize):
'''Integration test to check if all functionality works as expected.'''
mock_summarize.return_value = mock_constants.CHAT_COMPLETIONS_MOCK_RESPONSE

model = Model(1,1,1,2)

summary = model.summarize()
self.assertIsInstance(summary, str)
self.assertEqual(summary, mock_constants.CHAT_COMPLETIONS_MOCK_RESPONSE)

# Assert that azure_api_call was called with the correct prompt
Expand Down
Loading

0 comments on commit 8da4bae

Please sign in to comment.