Skip to content

Commit 8b8bbf0

Browse files
committed
Snapshot tests
1 parent c7f859e commit 8b8bbf0

File tree

8 files changed

+431
-156
lines changed

8 files changed

+431
-156
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.sample_data/
1+
tests/.sample_data/
22

33

44
# Byte-compiled / optimized / DLL files

poetry.lock

Lines changed: 107 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "rich-pixels"
33
version = "1.0.0"
4-
description = "A Rich-compatible library for writing pixels and other colourful grids to the terminal."
4+
description = "A Rich-compatible library for writing pixel images and ASCII art to the terminal."
55
authors = ["Darren Burns <darrenb900@gmail.com>"]
66
readme = "README.md"
77
packages = [{ include = "rich_pixels" }]
@@ -16,9 +16,9 @@ pillow = "^9.0.0"
1616
image = ["Pillow"]
1717

1818
[tool.poetry.group.dev.dependencies]
19-
ward = "^0.67.0b0"
2019
black = "^22.10.0"
2120
mypy = "^0.990"
21+
syrupy = "^3.0.5"
2222

2323
[build-system]
2424
requires = ["poetry-core"]

rich_pixels/_pixel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __rich_console__(
127127
if __name__ == '__main__':
128128
console = Console()
129129
images_path = Path(__file__).parent / "../.sample_data/images"
130-
pixels = Pixels.from_image_path(images_path / "1.png")
130+
pixels = Pixels.from_image_path(images_path / "bulbasaur.png")
131131
console.print(pixels)
132132

133133
grid = """\

tests/__init__.py

Whitespace-only changes.

tests/__snapshots__/test_pixel/test_ascii_text.svg

Lines changed: 90 additions & 0 deletions
Loading

tests/__snapshots__/test_pixel/test_png_image_path.svg

Lines changed: 186 additions & 0 deletions
Loading

tests/test_pixel.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from rich.align import Align
5+
from rich.console import Console
6+
from rich.segment import Segment
7+
from rich.style import Style
8+
from syrupy.extensions.image import SVGImageSnapshotExtension
9+
10+
from rich_pixels import Pixels
11+
12+
SAMPLE_DATA_DIR = Path(__file__).parent / ".sample_data/"
13+
14+
15+
@pytest.fixture
16+
def svg_snapshot(snapshot):
17+
return snapshot.use_extension(SVGImageSnapshotExtension)
18+
19+
20+
def get_console():
21+
console = Console(record=True)
22+
return console
23+
24+
25+
def test_png_image_path(svg_snapshot):
26+
console = get_console()
27+
pixels = Pixels.from_image_path(SAMPLE_DATA_DIR / "images/bulbasaur.png")
28+
console.print(pixels)
29+
svg = console.export_svg()
30+
assert svg == svg_snapshot
31+
32+
33+
def test_ascii_text(svg_snapshot):
34+
console = get_console()
35+
ascii = (SAMPLE_DATA_DIR / "ascii/rich_pixels.txt").read_text(encoding="utf-8")
36+
mapping = {"#": Segment(" ", Style.parse("on #50b332")),
37+
"=": Segment(" ", Style.parse("on #10ada3"))}
38+
pixels = Pixels.from_ascii(
39+
ascii,
40+
mapping=mapping,
41+
)
42+
console.print(Align.center(pixels))
43+
svg = console.export_svg(title="pixels in the terminal")
44+
assert svg == svg_snapshot

0 commit comments

Comments
 (0)