Remove mocking from tests (#4287) · psf/black@c9d2635 (original) (raw)

`@@ -474,20 +474,8 @@ def test_false_positive_symlink_output_issue_3384(self) -> None:

`

474

474

`# running from CLI, but fails when running the tests because cwd is different

`

475

475

`project_root = Path(THIS_DIR / "data" / "nested_gitignore_tests")

`

476

476

`working_directory = project_root / "root"

`

477

``

`-

target_abspath = working_directory / "child"

`

478

``

`-

target_contents = list(target_abspath.iterdir())

`

479

477

``

480

``

`-

def mock_n_calls(responses: List[bool]) -> Callable[[], bool]:

`

481

``

`-

def _mocked_calls() -> bool:

`

482

``

`-

if responses:

`

483

``

`-

return responses.pop(0)

`

484

``

`-

return False

`

485

``

-

486

``

`-

return _mocked_calls

`

487

``

-

488

``

`-

with patch("pathlib.Path.iterdir", return_value=target_contents), patch(

`

489

``

`-

"pathlib.Path.resolve", return_value=target_abspath

`

490

``

`-

), patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])):

`

``

478

`+

with change_directory(working_directory):

`

491

479

`# Note that the root folder (project_root) isn't the folder

`

492

480

`# named "root" (aka working_directory)

`

493

481

`report = MagicMock(verbose=True)

`

`@@ -2692,11 +2680,19 @@ def test_get_sources_symlink_and_force_exclude(self) -> None:

`

2692

2680

`def test_get_sources_with_stdin_symlink_outside_root(

`

2693

2681

`self,

`

2694

2682

` ) -> None:

`

2695

``

`-

path = THIS_DIR / "data" / "include_exclude_tests"

`

2696

``

`-

stdin_filename = str(path / "b/exclude/a.py")

`

2697

``

`-

outside_root_symlink = Path("/target_directory/a.py")

`

2698

``

`-

root = Path("target_dir/").resolve().absolute()

`

2699

``

`-

with patch("pathlib.Path.resolve", return_value=outside_root_symlink):

`

``

2683

`+

with TemporaryDirectory() as tempdir:

`

``

2684

`+

tmp = Path(tempdir).resolve()

`

``

2685

+

``

2686

`+

root = tmp / "root"

`

``

2687

`+

root.mkdir()

`

``

2688

`+

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

`

``

2689

+

``

2690

`+

target = tmp / "outside_root" / "a.py"

`

``

2691

`+

target.parent.mkdir()

`

``

2692

`+

target.write_text("print('hello')", encoding="utf-8")

`

``

2693

`+

(root / "a.py").symlink_to(target)

`

``

2694

+

``

2695

`+

stdin_filename = str(root / "a.py")

`

2700

2696

`assert_collected_sources(

`

2701

2697

`root=root,

`

2702

2698

`src=["-"],

`