-
-
Notifications
You must be signed in to change notification settings - Fork 6
ci: run the plugins' own tests, and repair the ones that could not pass #265
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,71 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Simple syntax checker for the basketball plugin. | ||
| Tests that the plugin can be imported without errors. | ||
| """Smoke test: the entry point imports and declares the class the manifest names. | ||
|
|
||
| Cheap, but it catches the two failures that stop a plugin loading at all -- | ||
| a syntax error, and a manifest whose ``class_name`` no longer matches the code. | ||
| The second is not hypothetical: this file used to import a hardcoded | ||
| ``BasketballPluginManager``, a name the plugin had long since stopped using, so | ||
| it failed on every run for a reason that had nothing to do with the plugin. It | ||
| now reads the name from the manifest, which is the thing the loader actually | ||
| uses, so a rename is either reflected in both places or caught here. | ||
|
|
||
| Needs the core on the path for ``src.plugin_system.base_plugin``; run via | ||
| scripts/run_plugin_tests.py, which supplies it. | ||
|
|
||
| Exit codes: 0 pass, 2 skip (no core), 1 fail. | ||
| """ | ||
|
|
||
| import sys | ||
| import json | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Set emulator mode before any imports | ||
| os.environ['EMULATOR'] = 'true' | ||
| PLUGIN_DIR = Path(__file__).resolve().parent | ||
| sys.path.insert(0, str(PLUGIN_DIR)) | ||
|
|
||
| # Add LEDMatrix to path | ||
| sys.path.insert(0, '/home/chuck/Github/LEDMatrix') | ||
| # Emulator mode must be set before the plugin imports anything from the core. | ||
| os.environ.setdefault("EMULATOR", "true") | ||
|
|
||
| core = os.environ.get("LEDMATRIX_CORE") | ||
| if core: | ||
| sys.path.insert(0, core) | ||
|
|
||
| try: | ||
| import src.plugin_system.base_plugin # noqa: F401 | ||
| except ModuleNotFoundError as exc: | ||
| # Skip only when the core itself is absent. A ModuleNotFoundError raised | ||
| # from *inside* the core -- a missing dependency, a broken import in | ||
| # base_plugin -- is a real failure, and reporting it as "no core here" | ||
| # would hide it behind a skip nobody reads. | ||
| if exc.name not in ("src", "src.plugin_system", "src.plugin_system.base_plugin"): | ||
| raise | ||
| print(f"SKIP: needs a LEDMatrix core on the path ({exc}); " | ||
| f"set LEDMATRIX_CORE or run via scripts/run_plugin_tests.py --core") | ||
| sys.exit(2) | ||
|
|
||
| manifest = json.loads((PLUGIN_DIR / "manifest.json").read_text(encoding="utf-8")) | ||
| class_name = manifest["class_name"] | ||
| entry_point = manifest.get("entry_point", "manager.py") | ||
| module_name = entry_point[:-3] if entry_point.endswith(".py") else entry_point | ||
|
|
||
| try: | ||
| # Try to import the plugin | ||
| from manager import BasketballPluginManager | ||
| print("✓ Plugin imported successfully") | ||
| print(f"✓ Class name: {BasketballPluginManager.__name__}") | ||
| print(f"✓ Base classes: {BasketballPluginManager.__bases__}") | ||
| print("\nPlugin structure is valid!") | ||
| sys.exit(0) | ||
|
|
||
| module = __import__(module_name) | ||
| except SyntaxError as e: | ||
| print(f"✗ Syntax error: {e}") | ||
| print(f"FAIL: syntax error in {entry_point}: {e}") | ||
| sys.exit(1) | ||
| except ImportError as e: | ||
| print(f"✗ Import error: {e}") | ||
| print(f"FAIL: {entry_point} could not be imported: {e}") | ||
| sys.exit(1) | ||
| except Exception as e: | ||
| print(f"✗ Error: {e}") | ||
| import traceback | ||
| traceback.print_exc() | ||
|
|
||
| cls = getattr(module, class_name, None) | ||
| if cls is None: | ||
| available = sorted( | ||
| n for n, v in vars(module).items() if isinstance(v, type) | ||
| and v.__module__ == module.__name__) | ||
| print(f"FAIL: manifest class_name is {class_name!r}, but {entry_point} " | ||
| f"defines no such class. It defines: {', '.join(available) or '(none)'}") | ||
| sys.exit(1) | ||
|
|
||
| print(f"PASS: {entry_point} imports and defines {class_name}") | ||
| print(f" base classes: {', '.join(b.__name__ for b in cls.__bases__)}") | ||
| sys.exit(0) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.