Skip to content

Commit

Permalink
Merge pull request #13113 from The-Compiler/fix-pygments-whitespace
Browse files Browse the repository at this point in the history
Fix selftests with Pygments >= 2.19.0
  • Loading branch information
The-Compiler authored Jan 8, 2025
2 parents 5d58b1f + ecf0548 commit bdfc3a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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 @@ -3,9 +3,12 @@

from collections.abc import Generator
import dataclasses
import importlib.metadata
import re
import sys

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 @@ -1294,13 +1294,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 @@ -2580,7 +2580,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 @@ -2602,7 +2602,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 @@ -2625,7 +2625,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

0 comments on commit bdfc3a9

Please sign in to comment.