import os from PIL import Image as PILImage from spectra.display import InkyDisplay class TestProcessImage: def setup_method(self): self.d = InkyDisplay(simulate=True, width=800, height=480) def test_aspect_crop_wide_image(self): img = PILImage.new("RGB", (1600, 600), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_aspect_crop_tall_image(self): img = PILImage.new("RGB", (400, 900), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_exact_aspect_no_crop(self): img = PILImage.new("RGB", (800, 480), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_square_input_to_landscape(self): img = PILImage.new("RGB", (1000, 1000), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_tiny_input(self): img = PILImage.new("RGB", (10, 10), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_panorama_very_wide(self): img = PILImage.new("RGB", (4000, 800), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) def test_very_narrow(self): img = PILImage.new("RGB", (100, 2000), color=(128, 64, 200)) r = self.d.process_image(img) assert r.size == (800, 480) class TestProcessImageWithRotation: def test_90_rotation_swaps_crop(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=90) img = PILImage.new("RGB", (1200, 1600), color=(128, 64, 200)) r = d.process_image(img) assert r.size == (800, 480) def test_270_rotation(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=270) img = PILImage.new("RGB", (1600, 1200), color=(128, 64, 200)) r = d.process_image(img) assert r.size == (800, 480) def test_180_rotation(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=180) img = PILImage.new("RGB", (1600, 1200), color=(128, 64, 200)) r = d.process_image(img) assert r.size == (800, 480) class TestShow: def test_show_writes_file(self): d = InkyDisplay(simulate=True, width=800, height=480) d.show(PILImage.new("RGB", (200, 200))) assert os.path.exists("/tmp/spectra_last.png") os.unlink("/tmp/spectra_last.png") def test_show_with_rotation_writes_same_size(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=90) d.show(PILImage.new("RGB", (200, 200))) saved = PILImage.open("/tmp/spectra_last.png") assert saved.size == (800, 480) os.unlink("/tmp/spectra_last.png") class TestShowFile: def test_show_file(self, tmp_path): src = tmp_path / "input.png" img = PILImage.new("RGB", (200, 200)) img.save(str(src)) d = InkyDisplay(simulate=True, width=800, height=480) d.show_file(str(src)) assert os.path.exists("/tmp/spectra_last.png") os.unlink("/tmp/spectra_last.png") def test_show_file_nonexistent(self): d = InkyDisplay(simulate=True, width=800, height=480) try: d.show_file("/nonexistent/image.png") assert False, "Expected exception" except FileNotFoundError: pass class TestClear: def test_clear_simulation(self): d = InkyDisplay(simulate=True, width=800, height=480) d.clear() def test_clear_simulation_with_orientation(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=90) d.clear() class TestEdgeCases: def test_display_initialization_defaults(self): d = InkyDisplay() assert d.width == 1600 assert d.height == 1200 assert d.orientation == 0 assert d.simulate is False def test_display_initialization_custom(self): d = InkyDisplay(simulate=True, width=800, height=480, orientation=90) assert d.effective_width == 480 assert d.effective_height == 800 def test_process_image_with_rgba(self): d = InkyDisplay(simulate=True, width=800, height=480) img = PILImage.new("RGBA", (1600, 1200), color=(128, 64, 200, 255)) r = d.process_image(img) assert r.size == (800, 480) def test_process_image_with_grayscale(self): d = InkyDisplay(simulate=True, width=800, height=480) img = PILImage.new("L", (1600, 1200), color=128) r = d.process_image(img) assert r.size == (800, 480)