import os import pytest from naramotion import Image, Format, Context, Rect def test_image_creation(): img = Image(400, 300, Format.PRGB32) assert img.width == 400 assert img.height == 300 assert img.size == (400, 300) assert img.format == Format.PRGB32 assert not img.is_empty() def test_image_file_io(tmp_path): filepath = str(tmp_path / "test_io.png") img = Image(200, 200, Format.PRGB32) with Context(img) as ctx: ctx.fill_all("white") ctx.fill_circle(100, 100, 50, "red") img.write_to_file(filepath) assert os.path.exists(filepath) assert os.path.getsize(filepath) > 0 loaded = Image.from_file(filepath) assert loaded.width == 200 assert loaded.height == 200 assert loaded.format == Format.PRGB32 def test_image_memory_bytes(): img = Image(100, 100, Format.PRGB32) with Context(img) as ctx: ctx.fill_all(0xFF00FF00) # Green data = img.to_data() assert isinstance(data, bytes) assert len(data) > 0 loaded = Image.from_data(data) assert loaded.width == 100 assert loaded.height == 100 def test_image_convert(): img = Image(100, 100, Format.PRGB32) assert img.format == Format.PRGB32 img.convert(Format.XRGB32) assert img.format == Format.XRGB32