Create a minimal plugin with optional artificial delay in on_load.
(plugin_dir: Path, name: str, delay: float = 0.0)
| 19 | |
| 20 | |
| 21 | def create_plugin_files(plugin_dir: Path, name: str, delay: float = 0.0): |
| 22 | """Create a minimal plugin with optional artificial delay in on_load.""" |
| 23 | plugin_dir.mkdir(exist_ok=True) |
| 24 | |
| 25 | (plugin_dir / "pyproject.toml").write_text( |
| 26 | f""" |
| 27 | [project] |
| 28 | name = "{name}" |
| 29 | version = "1.0.0" |
| 30 | description = "" |
| 31 | |
| 32 | [tool.lichtfeld] |
| 33 | auto_start = false |
| 34 | hot_reload = true |
| 35 | plugin_api = ">=1,<2" |
| 36 | lichtfeld_version = ">=0.4.2" |
| 37 | required_features = [] |
| 38 | """ |
| 39 | ) |
| 40 | |
| 41 | delay_code = f"import time; time.sleep({delay})" if delay > 0 else "" |
| 42 | (plugin_dir / "__init__.py").write_text( |
| 43 | f""" |
| 44 | LOAD_COUNT = 0 |
| 45 | UNLOAD_COUNT = 0 |
| 46 | |
| 47 | def on_load(): |
| 48 | global LOAD_COUNT |
| 49 | {delay_code} |
| 50 | LOAD_COUNT += 1 |
| 51 | |
| 52 | def on_unload(): |
| 53 | global UNLOAD_COUNT |
| 54 | UNLOAD_COUNT += 1 |
| 55 | """ |
| 56 | ) |
| 57 | |
| 58 | |
| 59 | @pytest.fixture |
no outgoing calls
no test coverage detected