Tests for encode_image_directly method.
| 80 | |
| 81 | |
| 82 | class TestBaseAPIEncodeImage: |
| 83 | """Tests for encode_image_directly method.""" |
| 84 | |
| 85 | def test_encode_image_from_pil(self, api, real_image): |
| 86 | """Test encoding PIL Image.""" |
| 87 | result = api.encode_image_directly(real_image) |
| 88 | assert isinstance(result, str) |
| 89 | # Should be base64 encoded |
| 90 | assert len(result) > 0 |
| 91 | |
| 92 | def test_encode_image_from_bytes(self, api, real_image): |
| 93 | """Test encoding from bytes.""" |
| 94 | # Convert PIL image to bytes |
| 95 | buffer = io.BytesIO() |
| 96 | real_image.save(buffer, format="PNG") |
| 97 | img_bytes = buffer.getvalue() |
| 98 | |
| 99 | result = api.encode_image_directly(io.BytesIO(img_bytes)) |
| 100 | assert isinstance(result, str) |
| 101 | |
| 102 | def test_encode_image_from_base64_string(self, api, real_image): |
| 103 | """Test encoding already base64 encoded string.""" |
| 104 | # Create base64 string with data URI prefix |
| 105 | buffer = io.BytesIO() |
| 106 | real_image.save(buffer, format="PNG") |
| 107 | b64_str = base64.b64encode(buffer.getvalue()).decode() |
| 108 | data_uri = f"data:image/png;base64,{b64_str}" |
| 109 | |
| 110 | result = api.encode_image_directly(data_uri) |
| 111 | # Should return as-is since it's already encoded |
| 112 | assert result == data_uri |
| 113 | |
| 114 | |
| 115 | class TestBaseAPICheckContent: |
nothing calls this directly
no outgoing calls
no test coverage detected