-
Notifications
You must be signed in to change notification settings - Fork 0
Add testing support for Pyodide and MicroPython environments #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
f3705ef
a710851
107f9b5
bef22f8
6abe6e9
02689e3
736b0dc
21a19d4
e819cb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import sys | ||
|
|
||
| def modify_core(filepath): | ||
| with open(filepath, 'r') as f: | ||
| content = f.read() | ||
|
|
||
| # We will just use replace_with_git_merge_diff below. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import sys | ||
| import os | ||
|
|
||
| # Ensure src is in the path | ||
| sys.path.append(os.getcwd() + '/src') | ||
| sys.path.append(os.getcwd() + '/test') | ||
|
|
||
| import test_micropython_core | ||
| test_micropython_core.run_all_tests() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,39 @@ | ||
| from numbers import Number | ||
| from types import FunctionType | ||
| try: | ||
| from numbers import Number | ||
| except ImportError: # MicroPython compatibility fallback for missing numbers | ||
| Number = (int, float, complex) # type: ignore[assignment,misc] | ||
|
|
||
| try: | ||
| import inspect | ||
| except ImportError: # MicroPython compatibility fallback for missing inspect | ||
| inspect = None # type: ignore[assignment] | ||
|
|
||
| try: | ||
| from typing import Any | ||
| except ImportError: # MicroPython compatibility fallback for missing typing | ||
| Any = object # type: ignore[assignment,misc] | ||
|
|
||
| try: | ||
| from types import FunctionType | ||
| except ImportError: # MicroPython compatibility fallback for missing types | ||
| FunctionType = type(lambda: None) # type: ignore[assignment,misc] | ||
|
|
||
|
|
||
| if inspect is not None: | ||
|
||
|
|
||
| def is_zero_arg(value: Any) -> bool: | ||
| if not callable(value): | ||
| return False | ||
| return len(inspect.signature(value).parameters) == 0 | ||
| else: | ||
|
|
||
| def is_zero_arg(value: Any) -> bool: | ||
| if not callable(value): | ||
| return False | ||
| try: | ||
| return value.__code__.co_argcount == 0 | ||
| except AttributeError: | ||
| return True | ||
|
|
||
|
|
||
| class ClosureCollectorException(AttributeError): | ||
|
|
@@ -19,7 +53,11 @@ def is_rule(func): | |
|
|
||
| if getattr(func, "__closure__", False): ## TODO replace with inspect_getclosurevars, probably inspect only nonlocals | ||
| for cell in func.__closure__: | ||
| if not isinstance(cell.cell_contents, (str, Number, bytes, tuple, frozenset)): | ||
| try: | ||
| contents = cell.cell_contents | ||
| except AttributeError: | ||
| contents = cell | ||
| if not isinstance(contents, (str, Number, bytes, tuple, frozenset)): | ||
| return True | ||
| try: | ||
| if set(func.__globals__).intersection(func.__code__.co_names): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this handling for different python interpreters? If so split it out into a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! This logic is required because MicroPython's function objects lack an
__code__attribute natively. I have extracted this logic into anis_zero_argfunction withinclosure_collector/util.py(which is defined conditionally based on the availability ofinspect). This cleans upmake_callableand removes the need for repeated exception handling inline.