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

25 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 20:01 +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://gitlab.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("subprocess.check_output", autospec=True) 

20def test_svn_local_changes_are_present(check_output): 

21 check_output.return_value = """ 

22? .vscode 

23? build 

24""" 

25 assert not svn_local_changes_are_present() 

26 

27 check_output.return_value = """ 

28? .vscode 

29M build.py 

30? build 

31""" 

32 assert svn_local_changes_are_present() 

33 

34 check_output.return_value = """ 

35? .vscode 

36! build.py 

37? build 

38""" 

39 assert svn_local_changes_are_present() 

40 

41 

42@mock.patch("subprocess.check_output", autospec=True) 

43def test_find_svn_files(check_output, 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 check_output.return_value = """\ 

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}