Test file drag-and-drop handling

This commit is contained in:
Isaiah Odhner 2023-09-14 01:50:37 -04:00
parent 070e253394
commit faa9c76ba8
5 changed files with 56 additions and 4 deletions

View File

@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
asyncio_mode = "auto"

View File

@ -13,5 +13,6 @@ watchdog==3.0.0 # for development; optional (only used when --restart-on-changes
types-Pillow==10.0.0.1 # for development
types-psutil==5.9.5.15 # for development
pytest==7.4.1 # for development
pytest-asyncio==0.21.1 # for development
pytest-textual-snapshot==0.4.0 # for development
pyfakefs==5.2.4 # for development

41
tests/test_behavior.py Normal file
View File

@ -0,0 +1,41 @@
"""General behavioral/functional tests.
Run with `pytest tests/test_behavior.py`, or `pytest` to run all tests.
"""
from pyfakefs.fake_filesystem import FakeFilesystem
from textual.events import Paste
from textual_paint.char_input import CharInput
from textual_paint.paint import PaintApp
async def test_char_input_paste():
app = PaintApp()
async with app.run_test() as pilot: # type: ignore
char_input = app.query_one(CharInput)
char_input.post_message(Paste("Hello, world!"))
await pilot.pause()
assert char_input.value == "!"
async def test_file_drag_and_drop(my_fs: FakeFilesystem):
# File drag and drop is treated as a paste in the terminal.
# CharInput often has focus, and needs to propagate the event to the app.
my_fs.create_file("/test_file_to_load.txt", contents="Hello, world!")
app = PaintApp()
async with app.run_test() as pilot: # type: ignore
char_input = app.query_one(CharInput)
char_input.post_message(Paste("/test_file_to_load.txt"))
await pilot.pause()
# TODO: fix double handling of Paste event
# It should ONLY load the file in this case, not also paste the filename into the char input.
# assert char_input.value == " " # default, may become full block (█) in the future
assert app.query_one("Canvas").render_line(0).text == "Hello, world!"
# TODO: bring palette state into the app class,
# and remove this KLUDGE of resetting the palette.
# Without this, the palette becomes black and white when loading a txt file,
# and it affects all snapshot tests! Pretty stupid.
import textual_paint.paint
from textual_paint.palette_data import DEFAULT_PALETTE
textual_paint.paint.palette = DEFAULT_PALETTE

View File

@ -1,4 +1,7 @@
"""Test that files are encoded correctly."""
"""Test that files are encoded correctly.
Run with `pytest tests/test_encoding.py`, or `pytest` to run all tests.
"""
from pathlib import Path
import pytest

View File

@ -1,9 +1,13 @@
"""Visual regression tests, using pytest-textual-snapshot. Run with `pytest`."""
"""Visual regression tests, using pytest-textual-snapshot.
Run with `pytest tests/test_snapshots.py`, or `pytest` to run all tests.
"""
from pathlib import Path, PurePath
from typing import TYPE_CHECKING, Awaitable, Callable, Iterable, Protocol
import pytest
from pyfakefs.fake_filesystem import FakeFilesystem
from textual.geometry import Offset
from textual.pilot import Pilot
from textual.widgets import Input
@ -53,10 +57,10 @@ def test_paint_flip_rotate_dialog(snap_compare: SnapCompareType, each_theme: Non
def test_paint_image_attributes_dialog(snap_compare: SnapCompareType, each_theme: None):
assert snap_compare(PAINT, press=["ctrl+e"])
def test_paint_open_dialog(snap_compare: SnapCompareType, each_theme: None, my_fs: None):
def test_paint_open_dialog(snap_compare: SnapCompareType, each_theme: None, my_fs: FakeFilesystem):
assert snap_compare(PAINT, press=["ctrl+o"], terminal_size=LARGER)
def test_paint_save_dialog(snap_compare: SnapCompareType, each_theme: None, my_fs: None):
def test_paint_save_dialog(snap_compare: SnapCompareType, each_theme: None, my_fs: FakeFilesystem):
assert snap_compare(PAINT, press=["ctrl+s"], terminal_size=LARGER)
def test_paint_help_dialog(snap_compare: SnapCompareType, each_theme: None):