From 6b359b0513f6f159e7c4f87b9a870b0f3f915a7f Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:05:34 -0300 Subject: [PATCH] Add a test for filtering of targets in build(). --- test/unit/test_build_unit.py | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/unit/test_build_unit.py b/test/unit/test_build_unit.py index ddd8fb86..367ba1eb 100644 --- a/test/unit/test_build_unit.py +++ b/test/unit/test_build_unit.py @@ -1,6 +1,7 @@ import os +import pathlib import sys -from unittest.mock import patch +from unittest.mock import MagicMock, patch import pytest @@ -38,7 +39,7 @@ def revisions(self, path, max_revisions): message="None again", tracked_files=["a", "b", "c", "d"], tracked_dirs=["d"], - added_files=["e"], + added_files=["e", "d/h"], modified_files=["f"], deleted_files=["a"], ), @@ -79,6 +80,42 @@ def test_build_simple(config): assert result is None +def test_build_targets(config): + mock_state = MagicMock() + mock_starmap = MagicMock() + mock_pool = MagicMock() + mock_pool.return_value = mock_pool + mock_pool.__enter__.return_value = mock_pool + mock_pool.starmap = mock_starmap + + _test_operators = (MockOperator,) + d_path = pathlib.Path("d/") + h_path = str(d_path / "h") + + assert config.targets == ["."] + with patch("wily.state.resolve_archiver", return_value=MockArchiver), patch( + "wily.commands.build.resolve_operator", return_value=MockOperator + ), patch("wily.commands.build.State", mock_state), patch( + "wily.commands.build.multiprocessing.Pool", mock_pool + ): + build.build(config, MockArchiver, _test_operators) # type: ignore + assert len(mock_starmap.mock_calls) == 6 + assert mock_starmap.mock_calls[0].args[-1][-1][-1] == ["e", h_path, "f"] + assert mock_starmap.mock_calls[3].args[-1][-1][-1] == [] + + config.targets = [str(d_path)] + mock_starmap.reset_mock() + with patch("wily.state.resolve_archiver", return_value=MockArchiver), patch( + "wily.commands.build.resolve_operator", return_value=MockOperator + ), patch("wily.commands.build.State", mock_state), patch( + "wily.commands.build.multiprocessing.Pool", mock_pool + ): + build.build(config, MockArchiver, _test_operators) # type: ignore + assert len(mock_starmap.mock_calls) == 6 + assert mock_starmap.mock_calls[0].args[-1][-1][-1] == [h_path] + assert mock_starmap.mock_calls[3].args[-1][-1][-1] == [] + + def test_run_operator(config): rev = Revision("123", None, None, 1, "message", [], [], [], [], []) name, data = build.run_operator(MockOperator, rev, config, ["test1.py"])