Coverage for tsfpga/test/test_svn_utils.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-07 11:31 +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 

9# Standard libraries 

10from unittest import mock 

11 

12# First party libraries 

13from tsfpga.svn_utils import find_svn_files, svn_local_changes_are_present 

14from tsfpga.system_utils import create_file 

15 

16# SVN is pretty much impossible to work with. Most of the functions are untested. 

17 

18 

19@mock.patch("tsfpga.svn_utils.run_command", autospec=True) 

20def test_svn_local_changes_are_present(run_command): 

21 run_command.return_value.stdout = """ 

22? .vscode 

23? build 

24""" 

25 assert not svn_local_changes_are_present() 

26 

27 run_command.return_value.stdout = """ 

28? .vscode 

29M build.py 

30? build 

31""" 

32 assert svn_local_changes_are_present() 

33 

34 run_command.return_value.stdout = """ 

35? .vscode 

36! build.py 

37? build 

38""" 

39 assert svn_local_changes_are_present() 

40 

41 

42@mock.patch("tsfpga.svn_utils.run_command", autospec=True) 

43def test_find_svn_files(run_command, tmp_path): 

44 apa_txt = create_file(tmp_path / "apa.txt") 

45 hest_txt = create_file(tmp_path / "stuff" / "hest.txt") 

46 zebra_vhd = create_file(tmp_path / "stuff" / "zebra.vhd") 

47 zebra_pdf = create_file(tmp_path / "things" / "zebra.pdf") 

48 

49 run_command.return_value.stdout = """ 

50 104134 104134 lukas.vik . 

51? .pytest_cache 

52? .vscode 

53? build 

54 104134 104134 lukas.vik apa.txt 

55 

56Performing status on external item at 'stuff': 

57 104134 103740 lukas.vik stuff 

58M 104134 103740 lukas.vik stuff/hest.txt 

59 104134 103740 lukas.vik stuff/zebra.vhd 

60 

61Performing status on external item at 'things': 

62 104134 103740 lukas.vik things 

63M X 104134 103740 lukas.vik things/zebra.pdf 

64""" 

65 assert set(find_svn_files(tmp_path)) == {apa_txt, hest_txt, zebra_pdf, zebra_vhd} 

66 

67 # Filter file endings include 

68 assert set(find_svn_files(tmp_path, file_endings_include="txt")) == {apa_txt, hest_txt} 

69 assert set(find_svn_files(tmp_path, file_endings_include=("txt", "vhd"))) == { 

70 apa_txt, 

71 hest_txt, 

72 zebra_vhd, 

73 } 

74 

75 # Filter file endings avoid 

76 assert set(find_svn_files(tmp_path, file_endings_avoid="txt")) == {zebra_vhd, zebra_pdf} 

77 assert set(find_svn_files(tmp_path, file_endings_avoid=("txt", "vhd"))) == {zebra_pdf} 

78 

79 # Filter exclude 

80 assert set(find_svn_files(tmp_path, excludes=[zebra_vhd.parent])) == {apa_txt, zebra_pdf} 

81 assert set(find_svn_files(tmp_path, excludes=[zebra_vhd.parent, zebra_pdf.parent])) == {apa_txt}