Skip to content

Commit

Permalink
Make test_contrasts.py ignore token.Whitespace (#1938)
Browse files Browse the repository at this point in the history
With the VisibleWhitespaceFilter Pygments can be configured to replace
whitespace characters like spaces, tabs and newlines with Unicode
characters like ·, » and ¶ respectively.

The min_contrast metric is meant to represent the readability of a
style. Increasing it should mean that the style becomes more readable.

This commit therefore excludes the token.Whitespace contrast from the
min_contrast calculation, since giving whitespace characters a high
contrast would make them so intrusive that they would actually hinder
the readability of the source code.
  • Loading branch information
not-my-profile committed Nov 2, 2021
1 parent b489656 commit 4f676c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/contrast/min_contrasts.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"default": 1.8,
"emacs": 1.8,
"friendly": 1.7,
"colorful": 1.9,
"autumn": 1.9,
"default": 2.6,
"emacs": 2.4,
"friendly": 2.2,
"colorful": 2.2,
"autumn": 2.2,
"murphy": 1.4,
"manni": 1.4,
"material": 1.6,
"monokai": 1.4,
"perldoc": 1.6,
"pastie": 1.9,
"borland": 1.9,
"trac": 1.9,
"native": 2.8,
"perldoc": 2.7,
"pastie": 2.5,
"borland": 2.3,
"trac": 2.3,
"native": 3.0,
"fruity": 1.6,
"bw": 21.0,
"vim": 1.3,
"vs": 3.6,
"tango": 1.0,
"tango": 2.4,
"rrt": 1.0,
"xcode": 5.1,
"igor": 3.6,
"paraiso-light": 1.3,
"paraiso-dark": 1.3,
"lovelace": 3.1,
"lovelace": 3.5,
"algol": 3.5,
"algol_nu": 3.5,
"arduino": 2.6,
"rainbow_dash": 1.6,
"rainbow_dash": 2.1,
"abap": 2.5,
"solarized-dark": 1.5,
"solarized-light": 1.0,
"sas": 1.9,
"stata": 1.9,
"stata-light": 1.9,
"sas": 4.2,
"stata": 2.4,
"stata-light": 2.4,
"stata-dark": 1.4,
"inkpot": 1.0,
"zenburn": 1.6,
Expand Down
2 changes: 2 additions & 0 deletions tests/contrast/test_contrasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys

import pygments.styles
import pygments.token
import wcag_contrast_ratio

JSON_FILENAME = os.path.join(os.path.dirname(__file__), "min_contrasts.json")
Expand Down Expand Up @@ -42,6 +43,7 @@ def get_style_contrasts(style_cls):
ttype,
)
for ttype, style in style_cls.list_styles()
if ttype != pygments.token.Whitespace
]


Expand Down

0 comments on commit 4f676c7

Please sign in to comment.