diff --git a/setup.cfg b/setup.cfg index bd8d5ac..05f3dda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,10 +29,10 @@ install_requires = setup_requires = setuptools>=44; setuptools_scm[toml]>=3.4.3 include_package_data = True -tests_require = pytest; typeguard; pygments>=2.16.0; littleutils +tests_require = pytest; typeguard; pygments; littleutils [options.extras_require] -tests = pytest; typeguard; pygments>=2.16.0; littleutils; cython +tests = pytest; typeguard; pygments; littleutils; cython [coverage:run] relative_files = True diff --git a/tests/__init__.py b/tests/__init__.py index aa63d95..e61d09f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,10 @@ import os import pyximport -from typeguard import install_import_hook +try: + from typeguard import install_import_hook +except ImportError: + from typeguard.importhook import install_import_hook pyximport.install(language_level=3) diff --git a/tests/test_serializer.py b/tests/test_serializer.py index 807872d..bc8acca 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -39,4 +39,4 @@ def test_example(): ) - compare_to_file_json(result, "serialize") + compare_to_file_json(result, "serialize", pygmented=True) diff --git a/tests/utils.py b/tests/utils.py index 7ba00e2..1500086 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,9 +1,19 @@ import os +import pygments from littleutils import string_to_file, file_to_string, json_to_file, file_to_json +def parse_version(version: str): + return tuple(int(x) for x in version.split(".")) + + +old_pygments = parse_version(pygments.__version__) < (2, 16, 1) + + def compare_to_file(text, name): + if old_pygments and "pygment" in name: + return filename = os.path.join( os.path.dirname(__file__), 'golden_files', @@ -16,7 +26,9 @@ def compare_to_file(text, name): assert text == expected_output -def compare_to_file_json(data, name): +def compare_to_file_json(data, name, *, pygmented): + if old_pygments and pygmented: + return filename = os.path.join( os.path.dirname(__file__), 'golden_files',