textual/tests/test_slug.py
Darren Burns dc1c734c7f Update snapshots (#4788)
* Update snapshots

* Update to use textual-snapshot v1.0.0

* Dont use xdist on CI

* Update pytest-cov to fix warnings

* Remove xdist thing from pythonpackage.yml GitHub workflow
2024-08-02 00:54:20 +02:00

64 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pytest
from textual._slug import TrackedSlugs, slug
@pytest.mark.xdist_group("group1")
@pytest.mark.parametrize(
"text, expected",
[
("test", "test"),
("Test", "test"),
(" Test ", "test"),
("-test-", "-test-"),
("!test!", "test"),
("test!!test", "testtest"),
("test! !test", "test-test"),
("test test", "test-test"),
("test test", "test--test"),
("test test", "test----------test"),
("--test", "--test"),
("test--", "test--"),
("--test--test--", "--test--test--"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test"),
("tëst", "t%C3%ABst"),
("test🙂test", "testtest"),
("test🤷test", "testtest"),
("test🤷🏻test", "testtest"),
],
)
def test_simple_slug(text: str, expected: str) -> None:
"""The simple slug function should produce the expected slug."""
assert slug(text) == expected
@pytest.fixture(scope="module")
def tracker() -> TrackedSlugs:
return TrackedSlugs()
@pytest.mark.xdist_group("group2")
@pytest.mark.parametrize(
"text, expected",
[
("test", "test"),
("test", "test-1"),
("test", "test-2"),
("-test-", "-test-"),
("-test-", "-test--1"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test"),
("test!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~test", "test-_test-1"),
("tëst", "t%C3%ABst"),
("tëst", "t%C3%ABst-1"),
("tëst", "t%C3%ABst-2"),
("test🙂test", "testtest"),
("test🤷test", "testtest-1"),
("test🤷🏻test", "testtest-2"),
("test", "test-3"),
("test", "test-4"),
(" test ", "test-5"),
],
)
def test_tracked_slugs(tracker: TrackedSlugs, text: str, expected: str) -> None:
"""The tracked slugging class should produce the expected slugs."""
assert tracker.slug(text) == expected