mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-05-20 12:05:56 +08:00

* chore(deps): make Qt backend optional TODO: - [ ] Add relevant entry in CHANGELOG - [ ] Update install documentation - [ ] Make sure `manim-slides convert` can run without any Qt backend - [ ] Make sure test suite works (partially) without any Qt backend - [ ] Make sure we can import `manim_slides` without any Qt backend * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(deps): some fixes but wip * chore(docs): update * chore(deps): support PyQt6 * chore(deps): make Qt backend optional TODO: - [ ] Add relevant entry in CHANGELOG - [ ] Update install documentation - [ ] Make sure `manim-slides convert` can run without any Qt backend - [ ] Make sure test suite works (partially) without any Qt backend - [ ] Make sure we can import `manim_slides` without any Qt backend * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(deps): some fixes but wip * chore(docs): update * chore(deps): support PyQt6 * fix(deps): ci and docs * fix(lib): missing package * chore(ci): does it work? * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(test): skip failing * chore(docs): update * chore(docs): update * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix(docs): typo * fix(test): quit instead of shutdown --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
183 lines
5.0 KiB
Python
183 lines
5.0 KiB
Python
from pathlib import Path
|
|
|
|
from click.testing import CliRunner
|
|
from pytest import MonkeyPatch
|
|
from pytestqt.qtbot import QtBot
|
|
from qtpy.QtCore import Qt
|
|
from qtpy.QtWidgets import (
|
|
QApplication,
|
|
QMessageBox,
|
|
)
|
|
|
|
from manim_slides.config import Config, Key
|
|
from manim_slides.defaults import CONFIG_PATH
|
|
from manim_slides.wizard import init, wizard
|
|
from manim_slides.wizard.wizard import KeyInput, Wizard
|
|
|
|
|
|
class TestKeyInput:
|
|
def test_default_is_none(self, qtbot: QtBot) -> None:
|
|
widget = KeyInput()
|
|
widget.show()
|
|
qtbot.addWidget(widget)
|
|
assert widget.key is None
|
|
|
|
def test_send_key(self, qtbot: QtBot) -> None:
|
|
widget = KeyInput()
|
|
widget.show()
|
|
qtbot.addWidget(widget)
|
|
qtbot.keyPress(widget, Qt.Key_Q)
|
|
assert widget.key is Qt.Key_Q.value
|
|
|
|
|
|
class TestWizard:
|
|
def test_close_without_saving(self, qtbot: QtBot) -> None:
|
|
wizard = Wizard(Config())
|
|
wizard.show()
|
|
qtbot.addWidget(wizard)
|
|
wizard.button_box.rejected.emit()
|
|
assert wizard.closed_without_saving
|
|
|
|
def test_save_valid_config(self, qtbot: QtBot) -> None:
|
|
widget = Wizard(Config())
|
|
widget.show()
|
|
qtbot.addWidget(widget)
|
|
widget.button_box.accepted.emit()
|
|
assert not widget.closed_without_saving
|
|
|
|
def test_save_invalid_config(self, qtbot: QtBot, monkeypatch: MonkeyPatch) -> None:
|
|
wizard = Wizard(Config())
|
|
wizard.show()
|
|
qtbot.addWidget(wizard)
|
|
|
|
def open_dialog(button_number: int, key: Key) -> None:
|
|
button = wizard.buttons[button_number]
|
|
dialog = KeyInput()
|
|
qtbot.addWidget(dialog)
|
|
qtbot.keyPress(dialog, Qt.Key_Q)
|
|
assert dialog.key is not None
|
|
key.set_ids(dialog.key)
|
|
button.setText("Q")
|
|
assert button.text() == "Q"
|
|
dialog.close()
|
|
|
|
message_boxes = []
|
|
|
|
def exec_patched(self: QMessageBox) -> None:
|
|
self.show()
|
|
message_boxes.append(self)
|
|
|
|
monkeypatch.setattr(QMessageBox, "exec", exec_patched)
|
|
|
|
for i, (key, _) in enumerate(wizard.config.keys.dict().items()):
|
|
open_dialog(i, getattr(wizard.config.keys, key))
|
|
|
|
wizard.button_box.accepted.emit()
|
|
message_box = message_boxes.pop()
|
|
qtbot.addWidget(message_box)
|
|
assert message_box.isVisible()
|
|
|
|
|
|
def test_init() -> None:
|
|
runner = CliRunner()
|
|
|
|
with runner.isolated_filesystem():
|
|
assert not CONFIG_PATH.exists()
|
|
results = runner.invoke(
|
|
init,
|
|
)
|
|
|
|
assert results.exit_code == 0
|
|
assert CONFIG_PATH.exists()
|
|
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
|
|
|
|
|
|
def test_init_custom_path() -> None:
|
|
runner = CliRunner()
|
|
custom_path = Path("config.toml")
|
|
|
|
with runner.isolated_filesystem():
|
|
assert not custom_path.exists()
|
|
results = runner.invoke(
|
|
init,
|
|
["--config", str(custom_path)],
|
|
)
|
|
|
|
assert results.exit_code == 0
|
|
assert not CONFIG_PATH.exists()
|
|
assert custom_path.exists()
|
|
assert Config().dict() == Config.from_file(custom_path).dict()
|
|
|
|
|
|
def test_init_path_exists() -> None:
|
|
runner = CliRunner()
|
|
|
|
with runner.isolated_filesystem():
|
|
assert not CONFIG_PATH.exists()
|
|
results = runner.invoke(
|
|
init,
|
|
)
|
|
|
|
assert results.exit_code == 0
|
|
assert CONFIG_PATH.exists()
|
|
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
|
|
|
|
results = runner.invoke(init, input="o")
|
|
|
|
assert results.exit_code == 0
|
|
|
|
results = runner.invoke(init, input="m")
|
|
|
|
assert results.exit_code == 0
|
|
|
|
results = runner.invoke(init, input="q")
|
|
|
|
assert results.exit_code == 0
|
|
|
|
|
|
def test_wizard(monkeypatch: MonkeyPatch) -> None:
|
|
runner = CliRunner()
|
|
|
|
with runner.isolated_filesystem():
|
|
assert not CONFIG_PATH.exists()
|
|
|
|
def show(self: Wizard) -> None:
|
|
self.button_box.accepted.emit()
|
|
|
|
def exec_patched(self: QApplication) -> None:
|
|
pass
|
|
|
|
monkeypatch.setattr(Wizard, "show", show)
|
|
monkeypatch.setattr(QApplication, "exec", exec_patched)
|
|
|
|
results = runner.invoke(
|
|
wizard,
|
|
)
|
|
|
|
assert results.exit_code == 0
|
|
assert CONFIG_PATH.exists()
|
|
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
|
|
|
|
|
|
def test_wizard_closed_without_saving(monkeypatch: MonkeyPatch) -> None:
|
|
runner = CliRunner()
|
|
|
|
with runner.isolated_filesystem():
|
|
assert not CONFIG_PATH.exists()
|
|
|
|
def show(self: Wizard) -> None:
|
|
self.button_box.rejected.emit()
|
|
|
|
def exec_patched(self: QApplication) -> None:
|
|
pass
|
|
|
|
monkeypatch.setattr(Wizard, "show", show)
|
|
monkeypatch.setattr(QApplication, "exec", exec_patched)
|
|
|
|
results = runner.invoke(
|
|
wizard,
|
|
)
|
|
|
|
assert results.exit_code == 0
|
|
assert not CONFIG_PATH.exists()
|