File size: 1,760 Bytes
212d694
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import unittest
from mediaunmasked.analyzers.sentiment_analyzer import SentimentAnalyzer
import logging

class TestSentimentAnalyzer(unittest.TestCase):
    def setUp(self):
        self.analyzer = SentimentAnalyzer()
        logging.basicConfig(level=logging.INFO)
        self.logger = logging.getLogger(__name__)

    def test_positive_sentiment(self):
        """Test detection of positive sentiment"""
        text = "The breakthrough research shows promising results in cancer treatment, bringing hope to millions of patients worldwide."
        
        result = self.analyzer.analyze(text)
        
        self.assertIsNotNone(result)
        self.assertEqual(result['sentiment'], 'Positive')
        self.logger.info(f"Positive sentiment result: {result}")

    def test_negative_sentiment(self):
        """Test detection of negative sentiment"""
        text = "The devastating impact of the disaster has left thousands homeless and caused widespread damage to infrastructure."
        
        result = self.analyzer.analyze(text)
        
        self.assertIsNotNone(result)
        self.assertEqual(result['sentiment'], 'Negative')
        self.logger.info(f"Negative sentiment result: {result}")

    def test_manipulative_content(self):
        """Test detection of manipulative language"""
        text = "Experts say this shocking new discovery will change everything! Sources claim it's the biggest breakthrough ever, and everyone knows it's true!"
        
        result = self.analyzer.analyze(text)
        
        self.assertIsNotNone(result)
        self.assertGreater(result['manipulation_score'], 20)
        self.assertGreater(len(result['flagged_phrases']), 0)
        self.logger.info(f"Manipulative content result: {result}")