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

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# -------------------------------------------------------------------------------------------------- 

8 

9from unittest.mock import MagicMock, Mock, patch 

10 

11from vunit.ui import VUnit 

12 

13from tsfpga.git_simulation_subset import GitSimulationSubset 

14from tsfpga.module import get_modules 

15from tsfpga.system_utils import create_file 

16 

17 

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" 

23 

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") 

33 

34 modules = get_modules(modules_folder=module_paths) 

35 

36 git_simulation_subset = GitSimulationSubset( 

37 repo_root=tmp_path, reference_branch="origin/master", modules=modules 

38 ) 

39 

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 

43 

44 reference_commit = repo.commit.return_value 

45 

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] 

55 

56 if arg is reference_commit: 

57 diff1 = MagicMock() 

58 diff1.b_path = vhd_with_diff 

59 

60 diff2 = MagicMock() 

61 diff2.b_path = verilog_with_diff 

62 

63 diff3 = MagicMock() 

64 diff3.b_path = regs_toml_with_diff 

65 

66 return [diff1, diff2, diff3] 

67 

68 raise AssertionError 

69 

70 head_commit.diff.side_effect = diff_commit 

71 

72 vunit_proj = Mock(spec=VUnit) 

73 

74 git_simulation_subset.update_test_pattern(vunit_proj=vunit_proj) 

75 

76 repo.commit.assert_called_once_with("origin/master") 

77 

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 )