Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from unittest import mock 

10 

11from tsfpga.svn_utils import find_svn_files, svn_local_changes_are_present 

12from tsfpga.system_utils import create_file 

13 

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

15 

16 

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

18def test_svn_local_changes_are_present(check_output): 

19 check_output.return_value = """ 

20? .vscode 

21? build 

22""" 

23 assert not svn_local_changes_are_present() 

24 

25 check_output.return_value = """ 

26? .vscode 

27M build.py 

28? build 

29""" 

30 assert svn_local_changes_are_present() 

31 

32 check_output.return_value = """ 

33? .vscode 

34! build.py 

35? build 

36""" 

37 assert svn_local_changes_are_present() 

38 

39 

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

41def test_find_svn_files(check_output, 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") 

46 

47 check_output.return_value = """\ 

48 104134 104134 lukas.vik . 

49? .pytest_cache 

50? .vscode 

51? build 

52 104134 104134 lukas.vik apa.txt 

53 

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 

58 

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} 

64 

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 } 

72 

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} 

76 

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}