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 ### Changed
- Python3.14 compatibility - Python3.14 compatibility https://github.com/Textualize/rich/pull/3861
## [14.1.0] - 2025-06-25 ## [14.1.0] - 2025-06-25

View file

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

View file

@ -43,6 +43,12 @@ skip_py313 = pytest.mark.skipif(
reason="rendered differently on py3.13", 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( skip_pypy3 = pytest.mark.skipif(
hasattr(sys, "pypy_version_info"), hasattr(sys, "pypy_version_info"),
reason="rendered differently on pypy3", reason="rendered differently on pypy3",
@ -139,6 +145,7 @@ def test_inspect_empty_dict():
assert render({}).startswith(expected) assert render({}).startswith(expected)
@skip_py314
@skip_py313 @skip_py313
@skip_py312 @skip_py312
@skip_py311 @skip_py311
@ -219,6 +226,7 @@ def test_inspect_integer_with_value():
@skip_py311 @skip_py311
@skip_py312 @skip_py312
@skip_py313 @skip_py313
@skip_py314
def test_inspect_integer_with_methods_python38_and_python39(): def test_inspect_integer_with_methods_python38_and_python39():
expected = ( expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n" "╭──────────────── <class 'int'> ─────────────────╮\n"
@ -257,6 +265,7 @@ def test_inspect_integer_with_methods_python38_and_python39():
@skip_py311 @skip_py311
@skip_py312 @skip_py312
@skip_py313 @skip_py313
@skip_py314
def test_inspect_integer_with_methods_python310only(): def test_inspect_integer_with_methods_python310only():
expected = ( expected = (
"╭──────────────── <class 'int'> ─────────────────╮\n" "╭──────────────── <class 'int'> ─────────────────╮\n"
@ -299,6 +308,7 @@ def test_inspect_integer_with_methods_python310only():
@skip_py310 @skip_py310
@skip_py312 @skip_py312
@skip_py313 @skip_py313
@skip_py314
def test_inspect_integer_with_methods_python311(): def test_inspect_integer_with_methods_python311():
# to_bytes and from_bytes methods on int had minor signature change - # 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 # 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, sys.version_info.minor == 13 and sys.version_info.major == 3,
reason="rendered differently on py3.13", 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: def test_install() -> None:
@ -639,6 +643,7 @@ def test_attrs_empty() -> None:
@skip_py311 @skip_py311
@skip_py312 @skip_py312
@skip_py313 @skip_py313
@skip_py314
def test_attrs_broken() -> None: def test_attrs_broken() -> None:
@attr.define @attr.define
class Foo: class Foo:

View file

@ -843,7 +843,12 @@ def test_assemble():
def test_assemble_meta(): def test_assemble_meta():
text = Text.assemble("foo", ("bar", "bold"), meta={"foo": "bar"}) text = Text.assemble("foo", ("bar", "bold"), meta={"foo": "bar"})
assert str(text) == "foobar" 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() console = Console()
assert text.get_style_at_offset(console, 0).meta == {"foo": "bar"} assert text.get_style_at_offset(console, 0).meta == {"foo": "bar"}