Coverage for tsfpga/test/test_git_simulation_subset.py: 98%
41 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-08-29 20:51 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-08-29 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9from unittest.mock import MagicMock, Mock, patch
11from vunit.ui import VUnit
13from tsfpga.git_simulation_subset import GitSimulationSubset
14from tsfpga.module import get_modules
15from tsfpga.system_utils import create_file
18def test_find_subset(tmp_path):
19 """
20 Set up a scenario with a few files that have diffs and a few files that do not.
21 """
22 module_paths = tmp_path / "modules"
24 vhd_with_diff = create_file(module_paths / "foo" / "file_with_diff.vhdl")
25 verilog_with_diff = create_file(module_paths / "foo" / "file_with_diff.v")
26 create_file(module_paths / "foo" / "file_with_no_diff.vhd")
27 tb_vhd_with_diff = create_file(module_paths / "foo" / "tb_file_with_diff.vhd")
28 create_file(module_paths / "foo" / "file1_with_no_diff_tb.vhdl")
29 create_file(module_paths / "foo" / "file2_with_no_diff_tb.vhdl")
30 create_file(module_paths / "foo" / "file3_with_no_diff_tb.vhdl")
31 regs_toml_with_diff = create_file(module_paths / "bar" / "regs_bar.toml")
32 regs_pkg_vhd_untracked = create_file(module_paths / "bar" / "regs_src" / "bar_regs_pkg.vhd")
34 modules = get_modules(modules_folder=module_paths)
36 git_simulation_subset = GitSimulationSubset(
37 repo_root=tmp_path, reference_branch="origin/master", modules=modules
38 )
40 with patch("tsfpga.git_simulation_subset.Repo", autospec=True) as mocked_repo:
41 repo = mocked_repo.return_value
42 head_commit = repo.head.commit
44 reference_commit = repo.commit.return_value
46 def diff_commit(arg):
47 """
48 Return the files that have diffs. One or the other depending on what the argument
49 (reference commit, or None=local tree) is.
50 """
51 if arg is None:
52 diff = MagicMock()
53 diff.b_path = tb_vhd_with_diff
54 return [diff]
56 if arg is reference_commit:
57 diff1 = MagicMock()
58 diff1.b_path = vhd_with_diff
60 diff2 = MagicMock()
61 diff2.b_path = verilog_with_diff
63 diff3 = MagicMock()
64 diff3.b_path = regs_toml_with_diff
66 return [diff1, diff2, diff3]
68 raise AssertionError
70 head_commit.diff.side_effect = diff_commit
72 vunit_proj = Mock(spec=VUnit)
74 git_simulation_subset.update_test_pattern(vunit_proj=vunit_proj)
76 repo.commit.assert_called_once_with("origin/master")
78 vunit_proj.update_test_pattern.assert_called_once_with(
79 include_dependent_on={
80 vhd_with_diff,
81 tb_vhd_with_diff,
82 verilog_with_diff,
83 regs_pkg_vhd_untracked,
84 }
85 )