Test that non-string parameters are automatically converted to JSON
(self)
| 42 | self.assertEqual(result, "您好") |
| 43 | |
| 44 | def test_non_string_params(self): |
| 45 | """Test that non-string parameters are automatically converted to JSON""" |
| 46 | params = {"model": "gpt-3.5", "temperature": 0.7} |
| 47 | cache_instance = cache.TranslationCache("test_engine", params) |
| 48 | |
| 49 | # Test that params are converted to JSON string internally |
| 50 | cache_instance.set("hello", "你好") |
| 51 | result = cache_instance.get("hello") |
| 52 | self.assertEqual(result, "你好") |
| 53 | |
| 54 | # Test with different param types |
| 55 | array_params = ["param1", "param2"] |
| 56 | cache_instance2 = cache.TranslationCache("test_engine", array_params) |
| 57 | cache_instance2.set("hello", "你好2") |
| 58 | self.assertEqual(cache_instance2.get("hello"), "你好2") |
| 59 | |
| 60 | # Test with nested structures |
| 61 | nested_params = {"options": {"temp": 0.8, "models": ["a", "b"]}} |
| 62 | cache_instance3 = cache.TranslationCache("test_engine", nested_params) |
| 63 | cache_instance3.set("hello", "你好3") |
| 64 | self.assertEqual(cache_instance3.get("hello"), "你好3") |
| 65 | |
| 66 | def test_engine_distinction(self): |
| 67 | """Test that cache distinguishes between different translation engines""" |