2022-04-29 09:26:55 -04:00
|
|
|
"""Test that a plugin can be loaded by filename.
|
|
|
|
|
|
|
|
This file is copied to a location with the name "file.py",
|
|
|
|
and is then loaded from within the `test_cli.py` code.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os.path
|
2024-12-28 01:01:05 -05:00
|
|
|
from typing import Any
|
2022-04-29 09:26:55 -04:00
|
|
|
|
2022-04-30 21:46:09 -04:00
|
|
|
import dotbot
|
|
|
|
|
2022-04-29 09:26:55 -04:00
|
|
|
|
|
|
|
class File(dotbot.Plugin):
|
2024-12-28 01:01:05 -05:00
|
|
|
def can_handle(self, directive: str) -> bool:
|
2022-04-29 09:26:55 -04:00
|
|
|
return directive == "plugin_file"
|
|
|
|
|
2024-12-28 01:01:05 -05:00
|
|
|
def handle(self, directive: str, _data: Any) -> bool:
|
|
|
|
if directive != "plugin_file":
|
|
|
|
msg = f"File cannot handle directive {directive}"
|
|
|
|
raise ValueError(msg)
|
2022-04-29 09:26:55 -04:00
|
|
|
self._log.debug("Attempting to get options from Context")
|
|
|
|
options = self._context.options()
|
|
|
|
if len(options.plugins) != 1:
|
2024-12-28 01:01:05 -05:00
|
|
|
self._log.debug(f"Context.options.plugins length is {len(options.plugins)}, expected 1")
|
2022-04-29 09:26:55 -04:00
|
|
|
return False
|
|
|
|
if not options.plugins[0].endswith("file.py"):
|
2024-12-28 01:01:05 -05:00
|
|
|
self._log.debug(f"Context.options.plugins[0] is {options.plugins[0]}, expected end with file.py")
|
2022-04-29 09:26:55 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
with open(os.path.abspath(os.path.expanduser("~/flag")), "w") as file:
|
|
|
|
file.write("file plugin loading works")
|
|
|
|
return True
|