From db7c83f1ac6bde1a0bca32d9980f22f03ce02665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Terje=20R=C3=B8sten?= Date: Thu, 14 May 2026 14:27:11 +0200 Subject: [PATCH] Adapt test suite to pygments 2.20 --- changelog.md | 1 + test/pytests/test_naive_completion.py | 10 ++++++- ...est_smart_completion_public_schema_only.py | 28 +++++++++++++++++-- test/utils.py | 8 ++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 35fa9292..087be421 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Bug Fixes --------- * Update `sqlglot` to v30.7.0 to fix has_bit_strings error. +* Adapt test suite to pygments 2.20.0 1.72.0 (2026/05/08) diff --git a/test/pytests/test_naive_completion.py b/test/pytests/test_naive_completion.py index fd4be76b..46d46cde 100644 --- a/test/pytests/test_naive_completion.py +++ b/test/pytests/test_naive_completion.py @@ -4,6 +4,8 @@ from prompt_toolkit.document import Document import pytest +from test.utils import pygments_at_least + @pytest.fixture def completer(): @@ -37,7 +39,7 @@ def test_function_name_completion(completer, complete_event): text = "SELECT MA" position = len("SELECT MA") result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) - assert sorted(x.text for x in result) == [ + expected = [ 'MAKEDATE', 'MAKETIME', 'MAKE_SET', @@ -80,6 +82,12 @@ def test_function_name_completion(completer, complete_event): 'MAX_USER_CONNECTIONS', ] + if pygments_at_least("2.20"): + expected.extend([ + 'MANUAL', + ]) + assert sorted(x.text for x in result) == sorted(expected) + def test_column_name_completion(completer, complete_event): text = "SELECT FROM users" diff --git a/test/pytests/test_smart_completion_public_schema_only.py b/test/pytests/test_smart_completion_public_schema_only.py index 72b64b87..09a20856 100644 --- a/test/pytests/test_smart_completion_public_schema_only.py +++ b/test/pytests/test_smart_completion_public_schema_only.py @@ -8,6 +8,7 @@ import pytest import mycli.packages.special.main as special +from test.utils import pygments_at_least metadata = { "users": ["id", "email", "first_name", "last_name"], @@ -848,7 +849,7 @@ def test_backticked_column_completion_two_character(completer, complete_event): text = 'select `f' position = len(text) result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) - assert result == [ + expected = [ # todo it would be nicer if the column name "first_name" sorted to the top Completion(text='`for`', start_position=-2), Completion(text='`from`', start_position=-2), @@ -912,12 +913,24 @@ def test_backticked_column_completion_two_character(completer, complete_event): Completion(text='`references`', start_position=-2), ] + if pygments_at_least("2.20"): + expected.extend([ + Completion(text='`file_format`', start_position=-2), + Completion(text='`file_name`', start_position=-2), + Completion(text='`file_pattern`', start_position=-2), + Completion(text='`file_prefix`', start_position=-2), + Completion(text='`files`', start_position=-2), + Completion(text='`from_vector`', start_position=-2), + ]) + + assert sorted((x.text, x.start_position) for x in result) == sorted((x.text, x.start_position) for x in expected) + def test_backticked_column_completion_three_character(completer, complete_event): text = 'select `fi' position = len(text) result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) - assert result == [ + expected = [ # todo it would be nicer if the column name "first_name" sorted to the top Completion(text='`file`', start_position=-3), Completion(text='`field`', start_position=-3), @@ -942,6 +955,17 @@ def test_backticked_column_completion_three_character(completer, complete_event) Completion(text='`foreign key`', start_position=-3), ] + if pygments_at_least("2.20"): + expected.extend([ + Completion(text='`file_format`', start_position=-3), + Completion(text='`file_name`', start_position=-3), + Completion(text='`file_pattern`', start_position=-3), + Completion(text='`file_prefix`', start_position=-3), + Completion(text='`files`', start_position=-3), + ]) + + assert sorted((x.text, x.start_position) for x in result) == sorted((x.text, x.start_position) for x in expected) + def test_backticked_column_completion_four_character(completer, complete_event): text = 'select `fir' diff --git a/test/utils.py b/test/utils.py index 66b44e67..6d74be96 100644 --- a/test/utils.py +++ b/test/utils.py @@ -9,6 +9,8 @@ from types import SimpleNamespace from typing import Any, Callable, Literal, cast +from packaging.version import Version +import pygments import pymysql import pytest @@ -34,6 +36,12 @@ SSH_PORT = int(os.getenv("PYTEST_SSH_PORT", "22")) TEMPFILE_PREFIX = 'mycli_test_suite_' +PYGMENTS_VERSION = Version(pygments.__version__) + + +def pygments_at_least(version: str) -> bool: + return PYGMENTS_VERSION >= Version(version) + class DummyLogger: def __init__(self) -> None: