Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #13113/bdfc3a99 backport][8.3.x] Fix selftests with Pygments >= 2.19.0 #13116

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13112.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed selftest failures in ``test_terminal.py`` with Pygments >= 2.19.0
7 changes: 7 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from __future__ import annotations

import dataclasses
import importlib.metadata
import re
import sys
from typing import Generator

from packaging.version import Version

from _pytest.monkeypatch import MonkeyPatch
from _pytest.pytester import Pytester
import pytest
Expand Down Expand Up @@ -168,6 +171,9 @@ def color_mapping():

Used by tests which check the actual colors output by pytest.
"""
# https://github.com/pygments/pygments/commit/d24e272894a56a98b1b718d9ac5fabc20124882a
pygments_version = Version(importlib.metadata.version("pygments"))
pygments_has_kwspace_hl = pygments_version >= Version("2.19")

class ColorMapping:
COLORS = {
Expand All @@ -180,6 +186,7 @@ class ColorMapping:
"bold": "\x1b[1m",
"reset": "\x1b[0m",
"kw": "\x1b[94m",
"kwspace": "\x1b[90m \x1b[39;49;00m" if pygments_has_kwspace_hl else " ",
"hl-reset": "\x1b[39;49;00m",
"function": "\x1b[92m",
"number": "\x1b[94m",
Expand Down
10 changes: 5 additions & 5 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,13 +1299,13 @@ def test_this():
"=*= FAILURES =*=",
"{red}{bold}_*_ test_this _*_{reset}",
"",
" {reset}{kw}def{hl-reset} {function}test_this{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_this{hl-reset}():{endline}",
"> fail(){endline}",
"",
"{bold}{red}test_color_yes.py{reset}:5: ",
"_ _ * _ _*",
"",
" {reset}{kw}def{hl-reset} {function}fail{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}fail{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
"{bold}{red}E assert 0{reset}",
"",
Expand Down Expand Up @@ -2585,7 +2585,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
"{bold}{red}E assert 1 == 10{reset}",
]
Expand All @@ -2607,7 +2607,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
" {print}print{hl-reset}({str}'''{hl-reset}{str}{hl-reset}",
"> {str} {hl-reset}{str}'''{hl-reset}); {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
"{bold}{red}E assert 0{reset}",
Expand All @@ -2630,7 +2630,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
"{bold}{red}E assert 1 == 10{reset}",
]
Expand Down
Loading