Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mocking from tests #4287

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 14 additions & 18 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,8 @@ def test_false_positive_symlink_output_issue_3384(self) -> None:
# running from CLI, but fails when running the tests because cwd is different
project_root = Path(THIS_DIR / "data" / "nested_gitignore_tests")
working_directory = project_root / "root"
target_abspath = working_directory / "child"
target_contents = list(target_abspath.iterdir())

def mock_n_calls(responses: List[bool]) -> Callable[[], bool]:
def _mocked_calls() -> bool:
if responses:
return responses.pop(0)
return False

return _mocked_calls

with patch("pathlib.Path.iterdir", return_value=target_contents), patch(
"pathlib.Path.resolve", return_value=target_abspath
), patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])):
with change_directory(working_directory):
# Note that the root folder (project_root) isn't the folder
# named "root" (aka working_directory)
report = MagicMock(verbose=True)
Expand Down Expand Up @@ -2692,11 +2680,19 @@ def test_get_sources_symlink_and_force_exclude(self) -> None:
def test_get_sources_with_stdin_symlink_outside_root(
self,
) -> None:
path = THIS_DIR / "data" / "include_exclude_tests"
stdin_filename = str(path / "b/exclude/a.py")
outside_root_symlink = Path("/target_directory/a.py")
root = Path("target_dir/").resolve().absolute()
with patch("pathlib.Path.resolve", return_value=outside_root_symlink):
with TemporaryDirectory() as tempdir:
tmp = Path(tempdir).resolve()

root = tmp / "root"
root.mkdir()
(root / "pyproject.toml").write_text("[tool.black]", encoding="utf-8")

target = tmp / "outside_root" / "a.py"
target.parent.mkdir()
target.write_text("print('hello')", encoding="utf-8")
(root / "a.py").symlink_to(target)

stdin_filename = str(root / "a.py")
assert_collected_sources(
root=root,
src=["-"],
Expand Down