Coverage for tsfpga/test/test_svn_utils.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-21 20:51 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-21 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 import mock
11from tsfpga.svn_utils import find_svn_files, svn_local_changes_are_present
12from tsfpga.system_utils import create_file
14# SVN is pretty much impossible to work with. Most of the functions are untested.
17@mock.patch("tsfpga.svn_utils.run_command", autospec=True)
18def test_svn_local_changes_are_present(run_command):
19 run_command.return_value.stdout = """
20? .vscode
21? build
22"""
23 assert not svn_local_changes_are_present()
25 run_command.return_value.stdout = """
26? .vscode
27M build.py
28? build
29"""
30 assert svn_local_changes_are_present()
32 run_command.return_value.stdout = """
33? .vscode
34! build.py
35? build
36"""
37 assert svn_local_changes_are_present()
40@mock.patch("tsfpga.svn_utils.run_command", autospec=True)
41def test_find_svn_files(run_command, tmp_path):
42 apa_txt = create_file(tmp_path / "apa.txt")
43 hest_txt = create_file(tmp_path / "stuff" / "hest.txt")
44 zebra_vhd = create_file(tmp_path / "stuff" / "zebra.vhd")
45 zebra_pdf = create_file(tmp_path / "things" / "zebra.pdf")
47 run_command.return_value.stdout = """
48 104134 104134 lukas.vik .
49? .pytest_cache
50? .vscode
51? build
52 104134 104134 lukas.vik apa.txt
54Performing status on external item at 'stuff':
55 104134 103740 lukas.vik stuff
56M 104134 103740 lukas.vik stuff/hest.txt
57 104134 103740 lukas.vik stuff/zebra.vhd
59Performing status on external item at 'things':
60 104134 103740 lukas.vik things
61M X 104134 103740 lukas.vik things/zebra.pdf
62"""
63 assert set(find_svn_files(tmp_path)) == {apa_txt, hest_txt, zebra_pdf, zebra_vhd}
65 # Filter file endings include
66 assert set(find_svn_files(tmp_path, file_endings_include="txt")) == {apa_txt, hest_txt}
67 assert set(find_svn_files(tmp_path, file_endings_include=("txt", "vhd"))) == {
68 apa_txt,
69 hest_txt,
70 zebra_vhd,
71 }
73 # Filter file endings avoid
74 assert set(find_svn_files(tmp_path, file_endings_avoid="txt")) == {zebra_vhd, zebra_pdf}
75 assert set(find_svn_files(tmp_path, file_endings_avoid=("txt", "vhd"))) == {zebra_pdf}
77 # Filter exclude
78 assert set(find_svn_files(tmp_path, excludes=[zebra_vhd.parent])) == {apa_txt, zebra_pdf}
79 assert set(find_svn_files(tmp_path, excludes=[zebra_vhd.parent, zebra_pdf.parent])) == {apa_txt}