Skip to content

Commit 341635c

Browse files
stanislavlevinneersighted
authored andcommitted
tests: Mock Git for gitignore tests
Upstream run its tests on cloned git repo, but downstreams may or may not run tests in local git tree. Gitignore tests already use mocked results of Git and the corresponding git object may also be mocked. Fixes: python-poetry/poetry#4481 Signed-off-by: Stanislav Levin <[email protected]>
1 parent e72d3e4 commit 341635c

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

tests/masonry/builders/test_sdist.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -423,23 +423,27 @@ def test_with_src_module_dir() -> None:
423423

424424

425425
def test_default_with_excluded_data(mocker: MockerFixture) -> None:
426-
# Patch git module to return specific excluded files
427-
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
428-
p.return_value = [
429-
(
430-
(
431-
Path(__file__).parent
432-
/ "fixtures"
433-
/ "default_with_excluded_data"
434-
/ "my_package"
435-
/ "data"
436-
/ "sub_data"
437-
/ "data2.txt"
438-
)
439-
.relative_to(project("default_with_excluded_data"))
440-
.as_posix()
441-
)
442-
]
426+
class MockGit:
427+
def get_ignored_files(self, folder: Path | None = None) -> list[str]:
428+
# Patch git module to return specific excluded files
429+
return [
430+
(
431+
(
432+
Path(__file__).parent
433+
/ "fixtures"
434+
/ "default_with_excluded_data"
435+
/ "my_package"
436+
/ "data"
437+
/ "sub_data"
438+
/ "data2.txt"
439+
)
440+
.relative_to(project("default_with_excluded_data"))
441+
.as_posix()
442+
)
443+
]
444+
445+
p = mocker.patch("poetry.core.vcs.get_vcs")
446+
p.return_value = MockGit()
443447
poetry = Factory().create_poetry(project("default_with_excluded_data"))
444448

445449
builder = SdistBuilder(poetry)

tests/masonry/builders/test_wheel.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,28 @@ def test_wheel_with_file_with_comma() -> None:
284284

285285

286286
def test_default_src_with_excluded_data(mocker: MockerFixture) -> None:
287-
# Patch git module to return specific excluded files
288-
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
289-
p.return_value = [
290-
(
291-
(
292-
Path(__file__).parent
293-
/ "fixtures"
294-
/ "default_src_with_excluded_data"
295-
/ "src"
296-
/ "my_package"
297-
/ "data"
298-
/ "sub_data"
299-
/ "data2.txt"
300-
)
301-
.relative_to(project("default_src_with_excluded_data"))
302-
.as_posix()
303-
)
304-
]
287+
class MockGit:
288+
def get_ignored_files(self, folder: Path | None = None) -> list[str]:
289+
# Patch git module to return specific excluded files
290+
return [
291+
(
292+
(
293+
Path(__file__).parent
294+
/ "fixtures"
295+
/ "default_src_with_excluded_data"
296+
/ "src"
297+
/ "my_package"
298+
/ "data"
299+
/ "sub_data"
300+
/ "data2.txt"
301+
)
302+
.relative_to(project("default_src_with_excluded_data"))
303+
.as_posix()
304+
)
305+
]
306+
307+
p = mocker.patch("poetry.core.vcs.get_vcs")
308+
p.return_value = MockGit()
305309
poetry = Factory().create_poetry(project("default_src_with_excluded_data"))
306310

307311
builder = WheelBuilder(poetry)

0 commit comments

Comments
 (0)