Skip to content

Commit

Permalink
linting updates for 10/10
Browse files Browse the repository at this point in the history
  • Loading branch information
raaguln committed Mar 8, 2024
1 parent a6dded8 commit bbf9857
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
5 changes: 4 additions & 1 deletion scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'''
init file for scripts
'''
from .get_metadata import (get_show_metadata,
write_show_metadata,
_format_episode_metadata,
get_episode_metadata,
write_episode_metadata)
write_episode_metadata)
5 changes: 1 addition & 4 deletions scripts/get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ def write_show_metadata(output_file, dict_data):
raise TypeError("output_file must be of type str.")
if len(output_file) < 5 or '.json' not in output_file:
raise ValueError('Provide a valid output_file of .json type.')

if not dict_data:
raise ValueError("Provide dict_data parameter!")
if len(dict_data.keys()) == 0:
raise ValueError('Provide a valid dictionary data to write to the output file!')
with open(output_file, 'w', encoding="utf-8") as (outfile, error):
if error:
raise IOError(error)
else:
json.dump(dict_data, outfile, sort_keys=True, indent=2)
json.dump(dict_data, outfile, sort_keys=True, indent=2)

def _format_episode_metadata(episode_metadata):
'''
Expand Down Expand Up @@ -149,7 +147,6 @@ def write_episode_metadata(output_file, episodes_data):
raise TypeError("output_file must be of type str.")
if len(output_file) < 4 or '.csv' not in output_file:
raise ValueError('Provide a valid output_file of .csv type.')

if not episodes_data:
raise ValueError("Provide episodes_data parameter!")
if len(episodes_data.keys()) == 0:
Expand Down
10 changes: 6 additions & 4 deletions thronetalk-game-of-thrones-summarizer/tests/mock_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from io import StringIO
'''
Mock functions for testing purposes.
'''
import pandas as pd

def mocked_read_csv_ouput_dialogues(*args):
def mocked_read_csv_ouput_dialogues():
"""
Mocking pandas' read_csv function for output_dialogues.
"""
Expand Down Expand Up @@ -51,6 +53,6 @@ def mocked_read_csv_ouput_dialogues(*args):
'''
lines = data_output_dialogues_raw.splitlines()
data = [line.split(',') for line in lines[1:]]
df = pd.DataFrame(data[1:], columns=data[0])
dataframe = pd.DataFrame(data[1:], columns=data[0])
# mock_output_dialogues_raw = pd.read_csv(StringIO(data_output_dialogues_raw))
return df
return dataframe
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
# # def test_get_show_metadata_smoke(self):
# # '''Smoke test to make sure the function runs properly.'''
# # get_show_metadata("0944947")

# # def test_write_show_metadata_smoke(self):
# # '''Smoke test to make sure the function runs properly.'''
# # write_show_metadata(self.mock_path, self.mock_data)

# # def test__format_episode_metadata_smoke(self):
# # '''Smoke test to make sure the function runs properly.'''
# # _format_episode_metadata(self.mock_data)

# # def test_get_episode_metadata_smoke(self):
# # '''Smoke test to make sure the function runs properly.'''
# # get_episode_metadata()

# # def test_write_episode_metadata_smoke(self):
# # '''Smoke test to make sure the function runs properly.'''
# # write_episode_metadata(self.mock_path, self.mock_data)
Expand Down Expand Up @@ -73,7 +69,6 @@
# # _format_episode_metadata()
# with self.assertRaises(ValueError):
# _format_episode_metadata({})

# # def test_edge_invalid_write_episode_metadata(self):
# # '''Edge test for write_episode_metadata function.'''
# # # Check values of first parameter
Expand All @@ -92,4 +87,4 @@
# # write_episode_metadata(self.mock_path, {})

# if __name__ == "__main__":
# unittest.main()
# unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Consists of smoke tests, one-shot test and edge tests.
'''
import unittest
from unittest.mock import patch
# from unittest.mock import patch
from utils import VisualizationGenerator
# from . import mock_functions

Expand All @@ -12,8 +12,9 @@ class TestVisualizationGenerator(unittest.TestCase):

# Edge tests
def test_init_error(self):
'''Edge tests for VisualizationGenerator'''
with self.assertRaises(TypeError):
VisualizationGenerator()
VisualizationGenerator() # pylint: disable=no-value-for-parameter
with self.assertRaises(ValueError):
VisualizationGenerator("","","","")
with self.assertRaises(ValueError):
Expand All @@ -29,26 +30,27 @@ def test_init_error(self):
# recommender = Recommender(meta=imdb, scripts=script)
# self.assertEqual(recommender.weights, [1, 1, 0.8, 0.5, 0.2, 0.2, 0.4])
# self.assertIsNotNone(recommender.vector_list)

# @patch('scripts.visualization_generator.pd.read_csv',
# side_effect=mock_functions.mocked_read_csv_ouput_dialogues)
def test_wordcloud_error(self):
vg = VisualizationGenerator(1,1,1,2)
'''Edge tests for wordcloud generation function'''
v_g = VisualizationGenerator(1,1,1,2)
with self.assertRaises(TypeError):
vg.multiWordCloud()
v_g.multiWordCloud() # pylint: disable=no-value-for-parameter
with self.assertRaises(ValueError):
vg.multiWordCloud([])
v_g.multiWordCloud([])
with self.assertRaises(ValueError):
vg.multiWordCloud(['', ''])
v_g.multiWordCloud(['', ''])

def test_sentimentAnalysisVisualization_error(self):
vg = VisualizationGenerator(1,1,1,2)
def test_sentiment_analysis_visualization_error(self):
'''Edge tests for sentiment analysis viz generation function'''
v_g = VisualizationGenerator(1,1,1,2)
with self.assertRaises(TypeError):
vg.sentimentAnalysisVisualization()
v_g.sentimentAnalysisVisualization() # pylint: disable=no-value-for-parameter
with self.assertRaises(ValueError):
vg.sentimentAnalysisVisualization([])
v_g.sentimentAnalysisVisualization([])
with self.assertRaises(ValueError):
vg.sentimentAnalysisVisualization(['', ''])
v_g.sentimentAnalysisVisualization(['', ''])

# Smoke tests
# @patch('scripts.visualization_generator.pd.read_csv',
Expand All @@ -60,4 +62,4 @@ def test_sentimentAnalysisVisualization_error(self):
# vg.sentimentAnalysisVisualization(top_3_characters)

if __name__ == "__main__":
unittest.main()
unittest.main()
3 changes: 2 additions & 1 deletion thronetalk-game-of-thrones-summarizer/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .visualization_generator import VisualizationGenerator
'''init file for utils'''
from .visualization_generator import VisualizationGenerator

0 comments on commit bbf9857

Please sign in to comment.