def __init__(self) -> None:
self.default_map: Dict[str, Any] = {}
+ # Dummy root, since most of the tests don't care about it
+ self.obj: Dict[str, Any] = {"root": PROJECT_ROOT}
class FakeParameter(click.Parameter):
src_python.touch()
self.assertEqual(
- black.find_project_root((src_dir, test_dir)), root.resolve()
+ black.find_project_root((src_dir, test_dir)),
+ (root.resolve(), "pyproject.toml"),
+ )
+ self.assertEqual(
+ black.find_project_root((src_dir,)),
+ (src_dir.resolve(), "pyproject.toml"),
+ )
+ self.assertEqual(
+ black.find_project_root((src_python,)),
+ (src_dir.resolve(), "pyproject.toml"),
)
- self.assertEqual(black.find_project_root((src_dir,)), src_dir.resolve())
- self.assertEqual(black.find_project_root((src_python,)), src_dir.resolve())
@patch(
"black.files.find_user_pyproject_toml",
src: Sequence[Union[str, Path]],
expected: Sequence[Union[str, Path]],
*,
+ ctx: Optional[FakeContext] = None,
exclude: Optional[str] = None,
include: Optional[str] = None,
extend_exclude: Optional[str] = None,
)
gs_force_exclude = None if force_exclude is None else compile_pattern(force_exclude)
collected = black.get_sources(
- ctx=FakeContext(),
+ ctx=ctx or FakeContext(),
src=gs_src,
quiet=False,
verbose=False,
base / "b/.definitely_exclude/a.pyi",
]
src = [base / "b/"]
- assert_collected_sources(src, expected, extend_exclude=r"/exclude/")
+ ctx = FakeContext()
+ ctx.obj["root"] = base
+ assert_collected_sources(src, expected, ctx=ctx, extend_exclude=r"/exclude/")
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_exclude_for_issue_1572(self) -> None:
# Exclude shouldn't touch files that were explicitly given to Black through the
# CLI. Exclude is supposed to only apply to the recursive discovery of files.
child.is_symlink.assert_called()
assert child.is_symlink.call_count == 2
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_get_sources_with_stdin(self) -> None:
src = ["-"]
expected = ["-"]
assert_collected_sources(src, expected, include="", exclude=r"/exclude/|a\.py")
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_get_sources_with_stdin_filename(self) -> None:
src = ["-"]
stdin_filename = str(THIS_DIR / "data/collections.py")
stdin_filename=stdin_filename,
)
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_get_sources_with_stdin_filename_and_exclude(self) -> None:
# Exclude shouldn't exclude stdin_filename since it is mimicking the
# file being passed directly. This is the same as
stdin_filename=stdin_filename,
)
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_get_sources_with_stdin_filename_and_extend_exclude(self) -> None:
# Extend exclude shouldn't exclude stdin_filename since it is mimicking the
# file being passed directly. This is the same as
stdin_filename=stdin_filename,
)
- @patch("black.find_project_root", lambda *args: THIS_DIR.resolve())
+ @patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_get_sources_with_stdin_filename_and_force_exclude(self) -> None:
# Force exclude should exclude the file when passing it through
# stdin_filename