summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-01 15:27:45 +0100
committerGitHub <noreply@github.com>2021-11-01 15:27:45 +0100
commit8cfc6823a7a74d20d0f32000f3b967de770d1a9f (patch)
treee9b74c0a90e398a60873adaa0c9fbbee5c3ca1c9 /scripts
parent631e8511fa47a5f99468eabfcd418d3cd6cecc25 (diff)
downloadpygments-git-8cfc6823a7a74d20d0f32000f3b967de770d1a9f.tar.gz
Prohibit contrast degradation for styles via test (#1919)
Web accessibility is important. Unfortunately currently many pygments styles have rules with poor contrasts. This commit introduces a test case that fails if the minimum contrast of a style gets worse, e.g: E AssertionError: contrast degradation for style 'borland' E The following rules have a contrast lower than the required 2.9: E E * 1.90 Token.Text.Whitespace E * 2.80 Token.Generic.Heading E * 2.30 Token.Generic.Subheading E E assert not 1.9 < 2.9 This is accomplished by storing the current minimum contrasts in ./tests/contrast/min_contrasts.json. When you improve a minimum contrast the test fails with: E AssertionError: congrats, you improved a contrast! please run ./scripts/update_contrasts.py E assert not 1.9 > 0.9 Running the script as instructed updates the JSON file, making the test pass. New styles are required to meet the WCAG AA contrast minimum of 4.5. First commit to address #1718.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/update_contrasts.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/update_contrasts.py b/scripts/update_contrasts.py
new file mode 100755
index 00000000..156bc5cb
--- /dev/null
+++ b/scripts/update_contrasts.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+"""
+ Updates tests/contrast/min_contrasts.json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Whenever you have improved the minimum contrast of a style you should run
+ this script, so that the test_contrasts.py test prevents future degredations.
+"""
+
+import os
+import sys
+
+# always prefer Pygments from source if exists
+srcpath = os.path.join(os.path.dirname(__file__), "..")
+if os.path.isdir(os.path.join(srcpath, "pygments")):
+ sys.path.insert(0, srcpath)
+
+import tests.contrast.test_contrasts
+
+tests.contrast.test_contrasts.test_contrasts(fail_if_improved=False)
+tests.contrast.test_contrasts.update_json()