File size: 2,053 Bytes
6595ce6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Unit tests for model.py"""
import os
import sys
import unittest
from unittest.mock import patch, MagicMock

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from model import HumanizeModel, quick_humanize_fallback


class TestHumanizeModel(unittest.TestCase):
    def test_init_without_adapter(self):
        """Model should load in fallback mode when adapter not found."""
        with patch('model.HumanizeModel._adapter_exists', return_value=False):
            model = HumanizeModel()
            self.assertFalse(model._loaded)
            self.assertIsNone(model.model)
            self.assertIsNone(model.tokenizer)

    def test_fallback_humanize(self):
        """Rule-based fallback should return human-like text."""
        input_text = "In order to provide you with the most comprehensive solution, it is important to note that we have conducted extensive research."
        result = quick_humanize_fallback(input_text)
        
        self.assertIsInstance(result, str)
        self.assertIn("To", result)
        self.assertNotIn("In order to", result)
        self.assertNotIn("it is important to note that", result.lower())

    def test_fallback_preserves_meaning(self):
        """Fallback should keep core content."""
        input_text = "The model cannot process the data."
        result = quick_humanize_fallback(input_text)
        
        self.assertIn("Can't", result)
        self.assertIn("model", result.lower())
        self.assertIn("data", result.lower())

    def test_fallback_empty_string(self):
        """Fallback should handle empty strings."""
        result = quick_humanize_fallback("")
        self.assertEqual(result, "")

    def test_build_prompt_requires_tokenizer(self):
        """build_prompt requires loaded tokenizer."""
        model = HumanizeModel()
        model._loaded = False
        # Should not raise when tokenizer is None, but build_prompt is not called in fallback
        self.assertFalse(model._loaded)


if __name__ == '__main__':
    unittest.main()