()
| 332 | |
| 333 | # This function holds the source code that will be run under RustPython |
| 334 | def compare(): |
| 335 | import inspect |
| 336 | import io |
| 337 | import json |
| 338 | import os |
| 339 | import platform |
| 340 | import re |
| 341 | import sys |
| 342 | import warnings |
| 343 | from contextlib import redirect_stdout |
| 344 | |
| 345 | def method_incompatibility_reason(typ, method_name, real_method_value): |
| 346 | has_method = hasattr(typ, method_name) |
| 347 | if not has_method: |
| 348 | return "" |
| 349 | |
| 350 | is_inherited = not attr_is_not_inherited(typ, method_name) |
| 351 | if is_inherited: |
| 352 | return "(inherited)" |
| 353 | |
| 354 | value = extra_info(getattr(typ, method_name)) |
| 355 | if value != real_method_value: |
| 356 | return f"{value} != {real_method_value}" |
| 357 | |
| 358 | return None |
| 359 | |
| 360 | not_implementeds = {} |
| 361 | for name, (typ, real_value, methods) in expected_methods.items(): |
| 362 | missing_methods = {} |
| 363 | for method, real_method_value in methods: |
| 364 | reason = method_incompatibility_reason(typ, method, real_method_value) |
| 365 | if reason is not None: |
| 366 | missing_methods[method] = reason |
| 367 | if missing_methods: |
| 368 | not_implementeds[name] = missing_methods |
| 369 | |
| 370 | if platform.python_implementation() == "CPython": |
| 371 | if not_implementeds: |
| 372 | sys.exit( |
| 373 | f"ERROR: CPython should have all the methods but missing: {not_implementeds}" |
| 374 | ) |
| 375 | |
| 376 | mod_names = [ |
| 377 | name.decode() |
| 378 | for name, ext in map(os.path.splitext, os.listdir(libdir)) |
| 379 | if ext == b".py" or os.path.isdir(os.path.join(libdir, name)) |
| 380 | ] |
| 381 | mod_names += list(sys.builtin_module_names) |
| 382 | # Remove easter egg modules |
| 383 | mod_names = sorted(set(mod_names) - {"this", "antigravity"}) |
| 384 | |
| 385 | rustpymods = {mod: dir_of_mod_or_error(mod) for mod in mod_names} |
| 386 | |
| 387 | result = { |
| 388 | "cpython_modules": {}, |
| 389 | "implemented": {}, |
| 390 | "not_implemented": {}, |
| 391 | "failed_to_import": {}, |
nothing calls this directly
no test coverage detected