Merge branch 'kurtmckee/prevent-source-deletio...'
[dotbot.git] / tests / dotbot_plugin_directory.py
blob76d1356c281325c012622f6faf8c5ffc91f8d314
1 """Test that a plugin can be loaded by directory.
3 This file is copied to a location with the name "directory.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 Directory(dotbot.Plugin):
14 def can_handle(self, directive: str) -> bool:
15 return directive == "plugin_directory"
17 def handle(self, directive: str, _data: Any) -> bool:
18 if directive != "plugin_directory":
19 msg = f"Directory 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.plugin_dirs) != 1:
24 self._log.debug("Context.options.plugins length is %i, expected 1" % len(options.plugins))
25 return False
27 with open(os.path.abspath(os.path.expanduser("~/flag")), "w") as file:
28 file.write("directory plugin loading works")
29 return True