39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
"""Offscreen smoke tests for the command bar's image attachment."""
|
|
import os
|
|
|
|
import pytest
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
pytest.importorskip("PySide6")
|
|
|
|
from PySide6.QtCore import QThreadPool # noqa: E402
|
|
from PySide6.QtWidgets import QApplication # noqa: E402
|
|
|
|
from woodshop.gui.command_bar import CommandBar # noqa: E402
|
|
from woodshop.gui.controller import Controller # noqa: E402
|
|
|
|
_app = QApplication.instance() or QApplication([])
|
|
|
|
|
|
def test_attach_sets_pending_and_chip(tmp_path):
|
|
c = Controller(str(tmp_path / "s.json"))
|
|
bar = CommandBar(c, QThreadPool.globalInstance())
|
|
img = tmp_path / "chair.png"
|
|
img.write_bytes(b"\x89PNG")
|
|
bar._set_image(str(img))
|
|
assert bar._pending_image == str(img)
|
|
assert "chair.png" in bar.image_chip.text()
|
|
bar._set_image(None)
|
|
assert bar._pending_image is None and bar.image_chip.text() == ""
|
|
|
|
|
|
def test_send_with_only_image_uses_default_text(tmp_path, monkeypatch):
|
|
c = Controller(str(tmp_path / "s.json"))
|
|
bar = CommandBar(c, QThreadPool.globalInstance())
|
|
calls = {}
|
|
monkeypatch.setattr(bar, "_run", lambda text: calls.setdefault("text", text))
|
|
bar._set_image(str(tmp_path / "x.png"))
|
|
bar.input.clear()
|
|
bar._send()
|
|
assert calls["text"] == "build something like this"
|