Merge branch 'kurtmckee/prevent-source-deletio...'
[dotbot.git] / tests / dotbot_plugin_file.py
blob1b7887b1cabf6ee7838bb2ef8355f178379f0876
1 """Test that a plugin can be loaded by filename.
3 This file is copied to a location with the name "file.py",
4 and is then loaded from within the `test_cli.py` code.
5 """
7 import os.path
8 from typing import Any
10 import dotbot
13 class File(dotbot.Plugin):
14 def can_handle(self, directive: str) -> bool:
15 return directive == "plugin_file"
17 def handle(self, directive: str, _data: Any) -> bool:
18 if directive != "plugin_file":
19 msg = f"File cannot handle directive {directive}"
20 raise ValueError(msg)
21 self._log.debug("Attempting to get options from Context")
22 options = self._context.options()
23 if len(options.plugins) != 1:
24 self._log.debug(f"Context.options.plugins length is {len(options.plugins)}, expected 1")
25 return False
26 if not options.plugins[0].endswith("file.py"):
27 self._log.debug(f"Context.options.plugins[0] is {options.plugins[0]}, expected end with file.py")
28 return False
30 with open(os.path.abspath(os.path.expanduser("~/flag")), "w") as file:
31 file.write("file plugin loading works")
32 return True