test fixes

This commit is contained in:
Will McGugan 2025-10-09 09:35:09 +01:00
parent 27c2d2df75
commit 655b5210cb
5 changed files with 29 additions and 13 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Python3.14 compatibility
- Python3.14 compatibility https://github.com/Textualize/rich/pull/3861
## [14.1.0] - 2025-06-25

View File

@ -1,6 +1,7 @@
import sys
from functools import lru_cache
from marshal import dumps, loads
from operator import attrgetter
from pickle import dumps, loads
from random import randint
from typing import Any, Dict, Iterable, List, Optional, Type, Union, cast
@ -9,6 +10,10 @@ from .color import Color, ColorParseError, ColorSystem, blend_rgb
from .repr import Result, rich_repr
from .terminal_theme import DEFAULT_TERMINAL_THEME, TerminalTheme
_hash_getter = attrgetter(
"_color", "_bgcolor", "_attributes", "_set_attributes", "_link", "_meta"
)
# Style instances and style definitions are often interchangeable
StyleType = Union[str, "Style"]
@ -432,16 +437,7 @@ class Style:
def __hash__(self) -> int:
if self._hash is not None:
return self._hash
self._hash = hash(
(
self._color,
self._bgcolor,
self._attributes,
self._set_attributes,
self._link,
self._meta,
)
)
self._hash = hash(_hash_getter(self))
return self._hash
@property

View File

@ -43,6 +43,12 @@ skip_py313 = pytest.mark.skipif(
reason="rendered differently on py3.13",
)
skip_py314 = pytest.mark.skipif(
sys.version_info.minor == 14 and sys.version_info.major == 3,
reason="rendered differently on py3.14",
)
skip_pypy3 = pytest.mark.skipif(
hasattr(sys, "pypy_version_info"),
reason="rendered differently on pypy3",
@ -139,6 +145,7 @@ def test_inspect_empty_dict():
assert render({}).startswith(expected)
@skip_py314
@skip_py313
@skip_py312
@skip_py311
@ -219,6 +226,7 @@ def test_inspect_integer_with_value():
@skip_py311
@skip_py312
@skip_py313
@skip_py314
def test_inspect_integer_with_methods_python38_and_python39():
expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n"
@ -257,6 +265,7 @@ def test_inspect_integer_with_methods_python38_and_python39():
@skip_py311
@skip_py312
@skip_py313
@skip_py314
def test_inspect_integer_with_methods_python310only():
expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n"
@ -299,6 +308,7 @@ def test_inspect_integer_with_methods_python310only():
@skip_py310
@skip_py312
@skip_py313
@skip_py314
def test_inspect_integer_with_methods_python311():
# to_bytes and from_bytes methods on int had minor signature change -
# they now, as of 3.11, have default values for all of their parameters

View File

@ -38,6 +38,10 @@ skip_py313 = pytest.mark.skipif(
sys.version_info.minor == 13 and sys.version_info.major == 3,
reason="rendered differently on py3.13",
)
skip_py314 = pytest.mark.skipif(
sys.version_info.minor == 14 and sys.version_info.major == 3,
reason="rendered differently on py3.14",
)
def test_install() -> None:
@ -639,6 +643,7 @@ def test_attrs_empty() -> None:
@skip_py311
@skip_py312
@skip_py313
@skip_py314
def test_attrs_broken() -> None:
@attr.define
class Foo:

View File

@ -843,7 +843,12 @@ def test_assemble():
def test_assemble_meta():
text = Text.assemble("foo", ("bar", "bold"), meta={"foo": "bar"})
assert str(text) == "foobar"
assert text._spans == [Span(3, 6, "bold"), Span(0, 6, Style(meta={"foo": "bar"}))]
spans = text._spans
expected = [Span(3, 6, "bold"), Span(0, 6, Style(meta={"foo": "bar"}))]
assert spans == expected
console = Console()
assert text.get_style_at_offset(console, 0).meta == {"foo": "bar"}