Skip to content

Commit

Permalink
Add a test for filtering of targets in build().
Browse files Browse the repository at this point in the history
  • Loading branch information
devdanzin committed Oct 12, 2023
1 parent db5cbeb commit 6b359b0
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions test/unit/test_build_unit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib
import sys
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import pytest

Expand Down Expand Up @@ -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"],
),
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 6b359b0

Please sign in to comment.