Skip to content

Commit

Permalink
Add test to check Cpython compatibility
Browse files Browse the repository at this point in the history
- add a constant with the version of CPython that we got the
builtins attributes available.

- add a test that will skip in case of using an older CPython
version in runtime, or pass in case of the same, or newer version with
same attributes.

Signed-off-by: Alexandra Pereira <alesilva241@gmail.com>
  • Loading branch information
alexandrasp committed Mar 6, 2024
1 parent c56dbc0 commit 211e204
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cython/Compiler/Symtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

# Builtins python 3.12.2

KNOWN_PYTHON_BUILTINS_VERSION = (3, 12, 2, 'final', 0)
KNOWN_PYTHON_BUILTINS = frozenset([
'ArithmeticError',
'AssertionError',
Expand Down
13 changes: 13 additions & 0 deletions Cython/Compiler/Tests/TestBuiltin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
builtin_scope,
)

from ..Symtab import (
KNOWN_PYTHON_BUILTINS_VERSION, KNOWN_PYTHON_BUILTINS,
)

class TestBuiltinReturnTypes(unittest.TestCase):
def test_find_return_type_of_builtin_method(self):
Expand All @@ -30,3 +33,13 @@ def test_find_return_type_of_builtin_method(self):
self.assertTrue(hasattr(py_type, method_name), f"{type_name}.{method_name}")
else:
self.assertEqual(return_type.empty_declaration_code(pyrex=True), return_type_name)

class TestBuiltinCompatibility(unittest.TestCase):
def test_python_builtin_compatibility(self):
runtime_builtin_version = frozenset(dir(__builtins__))
if sys.version_info < KNOWN_PYTHON_BUILTINS_VERSION:
missing_builtins = KNOWN_PYTHON_BUILTINS-runtime_builtin_version
if len(missing_builtins) == 0:
self.skipTest('skipping test, older Python release found.')
self.skipTest(f'skipping test, older Python release found. Missing builtins: {", ".join(missing_builtins)}')
self.assertEqual(runtime_builtin_version, KNOWN_PYTHON_BUILTINS)

0 comments on commit 211e204

Please sign in to comment.