This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests to the "commentAnalysis.py" (#17)
* Add unit tests to the "commentAnalysis.py" 1.'unittest' framework of python is used to develop unit tests 2. adds the __init__.py to have standard packaging template * Add documentation to run unit tests update the README.md with the commands to run unit tests
- Loading branch information
1 parent
69d04d4
commit 5262fea
Showing
2 changed files
with
66 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
ml-conversational-analytic-tool/tests/test_commentAnalysis.py
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,52 @@ | ||
import unittest | ||
import unittest.mock | ||
|
||
import commentAnalysis | ||
|
||
class TestCommentAnalysis(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.sentiment_analyzer = commentAnalysis.vader.SentimentIntensityAnalyzer() | ||
self.sentiment_analyzer.polarity_scores = unittest.mock.MagicMock(return_value={"compound": 1.0}) | ||
|
||
def test_CommentAnalyzer_init(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['test']) | ||
self.assertEqual({'test': 0}, analyzer.word_count) | ||
|
||
def test_analyzeComment(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['test']) | ||
analyzer.vader_sentiment = self.sentiment_analyzer | ||
result = analyzer.analyzeComment("This is a test PR") | ||
self.assertEqual({'test': 1, 'Sentiment': 1.0, 'Code Blocks': 0}, result) | ||
|
||
def test_analyzeComment_with_empty_comment(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['empty comment']) | ||
analyzer.vader_sentiment = self.sentiment_analyzer | ||
result = analyzer.analyzeComment("") | ||
self.assertEqual({'empty comment': 0, 'Sentiment': 1.0, 'Code Blocks': 0}, result) | ||
|
||
def test_analyzeComment_with_codeBlocks(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['code block test']) | ||
analyzer.vader_sentiment = self.sentiment_analyzer | ||
result = analyzer.analyzeComment("```This patch has blocks```, ```This is second block```") | ||
self.assertEqual({'code block test': 0, 'Sentiment': 1.0, 'Code Blocks': 2}, result) | ||
|
||
def test_preProcess(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['preProcess test']) | ||
result = analyzer.preProcess("THIS is a TEST COMMENT") | ||
self.assertEqual("this is a test comment", result) | ||
|
||
def test_countWords(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['count words test']) | ||
result = analyzer.countWords("This is a test comment") | ||
self.assertEqual({'count words test': 0}, result) | ||
|
||
def test_getSentiment(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['sentiment test']) | ||
result = analyzer.getSentiment("This is a very good PR") | ||
self.assertEqual(float, type(result)) | ||
|
||
def test_getCodeBlockCount(self): | ||
analyzer = commentAnalysis.CommentAnalyzer(['test']) | ||
result = analyzer.getCodeBlockCount("```This comment has code block``` ``` this is the 2nd code block```") | ||
self.assertEqual(2, result) |