Spaces:
Configuration error
Configuration error
Download tests/test_model.py from world44/humanize-e: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/world44/humanize-e/resolve/main/tests/test_model.py
- Command line
-
hf download hf://spaces/world44/humanize-e/tests/test_model.py
-
curl -L -o test_model.py https://huggingface.co/spaces/world44/humanize-e/resolve/main/tests/test_model.py
2.05 kB
| """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() |