MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / test_api_functions

Function test_api_functions

test_gitbase_e2e.py:231–273  ·  view source on GitHub ↗

Test module-level API functions.

()

Source from the content-addressed store, hash-verified

229
230
231def test_api_functions():
232 """Test module-level API functions."""
233 print("=" * 60)
234 print("TESTING API FUNCTIONS")
235 print("=" * 60)
236
237 test_images = create_test_images()
238 sample_image = list(test_images.values())[0]
239
240 # Test get_gitbase_captioner caching
241 print("\n--- Testing Cached Captioner ---")
242 captioner1 = get_gitbase_captioner(dtype=torch.float16)
243 captioner2 = get_gitbase_captioner(dtype=torch.float16)
244
245 print(f"Same instance returned: {captioner1 is captioner2}")
246 assert captioner1 is captioner2, "Caching not working properly"
247
248 # Test caption_image_bytes
249 print("\n--- Testing Bytes API ---")
250 from io import BytesIO
251
252 # Convert image to bytes
253 buffer = BytesIO()
254 sample_image.save(buffer, format="JPEG")
255 image_bytes = buffer.getvalue()
256
257 # Test fast mode
258 start_time = time.time()
259 caption_fast = caption_image_bytes(image_bytes, fast_mode=True)
260 fast_time = time.time() - start_time
261
262 # Test quality mode
263 start_time = time.time()
264 caption_quality = caption_image_bytes(image_bytes, fast_mode=False)
265 quality_time = time.time() - start_time
266
267 print(f"Fast caption: {caption_fast} (time: {fast_time:.3f}s)")
268 print(f"Quality caption: {caption_quality} (time: {quality_time:.3f}s)")
269
270 assert isinstance(caption_fast, str)
271 assert isinstance(caption_quality, str)
272 assert len(caption_fast) > 0
273 assert len(caption_quality) > 0
274
275
276def test_comprehensive_image_types():

Callers 1

mainFunction · 0.85

Calls 5

get_gitbase_captionerFunction · 0.90
caption_image_bytesFunction · 0.90
create_test_imagesFunction · 0.85
printFunction · 0.50
saveMethod · 0.45

Tested by

no test coverage detected