changeset 123:4d96ace53ba1

Make it work on Python2 too with all tests by explicitely declaring some strings to be Unicode strings. No tests need to be skipped on Python2 now.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 06 May 2026 15:53:24 +0200
parents e39ca08b0609
children f916251d5647
files pygments_lexer_pseudocode2/algpseudocode.py tests/test_algpseudo.py
diffstat 2 files changed, 43 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/algpseudocode.py	Wed May 06 15:40:16 2026 +0200
+++ b/pygments_lexer_pseudocode2/algpseudocode.py	Wed May 06 15:53:24 2026 +0200
@@ -109,14 +109,14 @@
         "LOOP": "END LOOP",
     }
     DEFAULT_END_PREFIX = "END OF "
-    SYMBOL_REMARK = "▷"            # U+25B7: Unicode 1.0 (Geometric Shapes)
-    # SYMBOL_REMARK = "▻"          # U+25BB: Unicode 1.0 (Geometric Shapes)
-    # SYMBOL_REMARK = "⍝"          # U+235D: Unicode 1.1 (Misc. Technical, APL)
-    SYMBOL_BLOCK = "◆"             # U+25C6: Unicode 1.0 (Geometric Shapes)
-    # SYMBOL_BLOCK = "┃"           # U+2503: Unicode 1.0 (Bow Drawing)
-    # SYMBOL_BLOCK = "●"           # U+25CF: Unicode 1.0 (Geometric Shapes)
-    SYMBOL_TEXTSTATEMENT = "▪"     # U+25AA: Unicode 1.0 (Geometric Shapes)
-    # SYMBOL_TEXTSTATEMENT = "■"   # U+25A0: Unicode 1.0 (Geometric Shapes)
+    SYMBOL_REMARK = u"▷"           # U+25B7: Unicode 1.0 (Geometric Shapes)
+    # SYMBOL_REMARK = u"▻"         # U+25BB: Unicode 1.0 (Geometric Shapes)
+    # SYMBOL_REMARK = u"⍝"         # U+235D: Unicode 1.1 (Misc. Technical, APL)
+    SYMBOL_BLOCK = u"◆"            # U+25C6: Unicode 1.0 (Geometric Shapes)
+    # SYMBOL_BLOCK = u"┃"          # U+2503: Unicode 1.0 (Bow Drawing)
+    # SYMBOL_BLOCK = u"●"          # U+25CF: Unicode 1.0 (Geometric Shapes)
+    SYMBOL_TEXTSTATEMENT = u"▪"    # U+25AA: Unicode 1.0 (Geometric Shapes)
+    # SYMBOL_TEXTSTATEMENT = u"■"  # U+25A0: Unicode 1.0 (Geometric Shapes)
     SYMBOLS = {
         # Group REMARK
         "REMARK": SYMBOL_REMARK,
@@ -132,23 +132,23 @@
         "TSTATE": SYMBOL_TEXTSTATEMENT,
         "TEXTBLOCK": SYMBOL_TEXTSTATEMENT,
         "TBLOCK": SYMBOL_TEXTSTATEMENT,
-        "<-": "⟵",          # U+27F5: Unicode 3.2 (Supplemental Arrows-A)
-        "->": "⟶",          # U+27F6: Unicode 3.2 (Supplemental Arrows-A)
-        "<->": "⟷",         # U+27F7: Unicode 3.2 (Supplemental Arrows-A)
-        # "=>": "⟹",       # U+27F9: Unicode 3.2 (Supplemental Arrows-A)
-        # "<=>": "⟺",      # U+27FA: Unicode 3.2 (Supplemental Arrows-A)
-        # "<-": "←",        # U+2190: Unicode 1.0 (Arrows)
-        # "->": "→",        # U+2192: Unicode 1.0 (Arrows)
-        # "<->": "↔",       # U+2194: Unicode 1.0 (Arrows)
-        "=>": "⇒",          # U+21D2: Unicode 1.0 (Arrows)
-        "<=>": "⇔",         # U+21D4: Unicode 1.0 (Arrows)
-        "<=": "≤",          # U+2264: Unicode 1.0 (Mathematical Operators)
-        ">=": "≥",          # U+2265: Unicode 1.0 (Mathematical Operators)
-        "<>": "≠",          # U+2260: Unicode 1.0 (Mathematical Operators)
-        "!=": "≠",          # U+2260: Unicode 1.0 (Mathematical Operators)
-        ":=": "∶=",    # "≔" U+2254  not recognizable in my (small) mono font
-        "=:": "=∶",    # "≕" U+2255  not recognizable in my (small) mono font
-        "?=": "≟",          # U+225F: Unicode 1.0 (Mathematical Operators)
+        "<-": u"⟵",          # U+27F5: Unicode 3.2 (Supplemental Arrows-A)
+        "->": u"⟶",          # U+27F6: Unicode 3.2 (Supplemental Arrows-A)
+        "<->": u"⟷",         # U+27F7: Unicode 3.2 (Supplemental Arrows-A)
+        # "=>": u"⟹",       # U+27F9: Unicode 3.2 (Supplemental Arrows-A)
+        # "<=>": u"⟺",      # U+27FA: Unicode 3.2 (Supplemental Arrows-A)
+        # "<-": u"←",        # U+2190: Unicode 1.0 (Arrows)
+        # "->": u"→",        # U+2192: Unicode 1.0 (Arrows)
+        # "<->": u"↔",       # U+2194: Unicode 1.0 (Arrows)
+        "=>": u"⇒",          # U+21D2: Unicode 1.0 (Arrows)
+        "<=>": u"⇔",         # U+21D4: Unicode 1.0 (Arrows)
+        "<=": u"≤",          # U+2264: Unicode 1.0 (Mathematical Operators)
+        ">=": u"≥",          # U+2265: Unicode 1.0 (Mathematical Operators)
+        "<>": u"≠",          # U+2260: Unicode 1.0 (Mathematical Operators)
+        "!=": u"≠",          # U+2260: Unicode 1.0 (Mathematical Operators)
+        ":=": u"∶=",    # "≔" U+2254  not recognizable in my (small) mono font
+        "=:": u"=∶",    # "≕" U+2255  not recognizable in my (small) mono font
+        "?=": u"≟",          # U+225F: Unicode 1.0 (Mathematical Operators)
     }
 
     def op_translate(toktype):
--- a/tests/test_algpseudo.py	Wed May 06 15:40:16 2026 +0200
+++ b/tests/test_algpseudo.py	Wed May 06 15:53:24 2026 +0200
@@ -6,7 +6,6 @@
 
 from _tsetup import ALGLEXERFILENAME, ALGLEXERCLASS
 
-import sys
 import unittest
 
 import pygments
@@ -321,7 +320,7 @@
 
     def test_remark_1(self):
         self.assertTokenStreamEqualComplete(
-            [("Comment.Single", "▷"),
+            [("Comment.Single", u"▷"),
              ("Comment.Single", "  the remark"),
              ("Text.Whitespace", "\n"),
              ],
@@ -329,10 +328,10 @@
 
     def test_remark_2(self):
         self.assertTokenStreamEqualComplete(
-            [("Comment.Single", "▷"),
+            [("Comment.Single", u"▷"),
              ("Comment.Single", "  the remark 1"),
              ("Text.Whitespace", "\n"),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", "  the remark 2"),
              ("Text.Whitespace", "\n"),
              ],
@@ -346,16 +345,16 @@
         lexer = pygments.lexers.load_lexer_from_file(
             ALGLEXERFILENAME, ALGLEXERCLASS, remark=u"⍝")
         self.assertTokenStreamEqualComplete(
-            [("Comment.Single", "⍝"),  # U+235D ⍝ APL FUNC. SYMBOL UP SHOE JOT
+            [("Comment.Single", u"⍝"),  # U+235D ⍝ APL FUNC. SYMBOL UP SHOE JOT
              ("Comment.Single", "  another remark"),
              ("Text.Whitespace", "\n"),
              ],
-            pygments.lex("\\REMARK  another remark\n", lexer))
+            pygments.lex(u"\\REMARK  another remark\n", lexer))
 
     def test_remark_in_text(self):
         self.assertTokenStreamEqualComplete(
             [("Text", "the text  "),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", " the remark"),
              ("Text.Whitespace", "\n"),
              ("Text", "the next text line"),
@@ -445,7 +444,7 @@
 
     def test_block_empty(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "◆"),
+            [("Text", u"◆"),
              ("Text.Whitespace", " "),
              ("Text.Whitespace", "\n"),
              ],
@@ -453,7 +452,7 @@
 
     def test_block_with_text(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "◆"),
+            [("Text", u"◆"),
              ("Text.Whitespace", " "),
              ("Text", "a b c"),
              ("Text.Whitespace", "\n"),
@@ -462,7 +461,7 @@
 
     def test_block_with_escaped_text(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "◆"),
+            [("Text", u"◆"),
              ("Text.Whitespace", " "),
              ("Text", "\\"),
              ("Name.Entity", "text"),
@@ -479,7 +478,7 @@
 
     def test_block(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "◆"),
+            [("Text", u"◆"),
              ("Text.Whitespace", " "),
              ("Name.Entity", "a"),
              ("Text", " "),
@@ -500,7 +499,7 @@
 
     def test_tstate_empty(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "▪"),
+            [("Text", u"▪"),
              ("Text.Whitespace", " "),
              ("Text.Whitespace", "\n"),
              ],
@@ -508,7 +507,7 @@
 
     def test_tstate_with_expr(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "▪"),
+            [("Text", u"▪"),
              ("Text.Whitespace", " "),
              ("Text", "a 1.2 "),
              ("Name.Entity", "x"),
@@ -524,7 +523,7 @@
 
     def test_tstate_with_escaped_expr(self):
         self.assertTokenStreamEqualComplete(
-            [("Text", "▪"),
+            [("Text", u"▪"),
              ("Text.Whitespace", " "),
              ("Text", "a 1.2 "),
              ("Text", "\\"),
@@ -628,7 +627,7 @@
         self.assertTokenStreamEqualComplete(
             [("Operator", u"∈ ∌"),
              ("Text", "    "),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", u" ∈ ∌ as (ordinary) operators"),
              ("Text.Whitespace", "\n"),
              ],
@@ -640,7 +639,7 @@
         self.assertTokenStreamEqualComplete(
             [("Operator", "new_operator"),
              ("Text", "  "),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", " a (synthesized) operator"),
              ("Text.Whitespace", "\n"),
              ],
@@ -673,7 +672,7 @@
              ("Name.Entity", "p2"),
              ("Punctuation", ")"),
              ("Text", "   "),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", " (Python) decorator"),
              ("Text.Whitespace", "\n"),
              ],
@@ -691,7 +690,7 @@
              ("Name.Entity", "p2"),
              ("Punctuation", ")"),
              ("Text", "   "),
-             ("Comment.Single", "▷"),
+             ("Comment.Single", u"▷"),
              ("Comment.Single", " (Python) annotation"),
              ("Text.Whitespace", "\n"),
              ],
@@ -757,7 +756,6 @@
              ],
             pygments.lex("=!&< >+-*/%|~", self.lexer))
 
-    @unittest.skipIf(sys.version_info[0] <= 2, "Unicode issues on Python 2")
     def test_ascii_math_operator_with_replacements(self):
         self.assertTokenStreamEqualComplete(
             [("Operator", u"⇔"),
@@ -890,7 +888,7 @@
         self.assertTokenStreamEqualComplete(
             [("Name.Entity", "a"),
              ("Text", " "),
-             ("Operator", "⟵"),     # U+27F5 (Supplemental Arrows-A)
+             ("Operator", u"⟵"),     # U+27F5 (Supplemental Arrows-A)
              ("Text", " "),
              ("Number.Integer", "2"),
              ("Text.Whitespace", "\n"),