Coverage for rust2rpm/tests/test_inspect.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-26 13:52 +0100

1from importlib import resources 

2from pathlib import Path 

3 

4import pytest 

5 

6from rust2rpm.conf.toml import FileInEx, Package, TomlConf 

7from rust2rpm.inspect import files_from_crate 

8 

9 

10@pytest.mark.parametrize( 

11 ("crate_name", "crate_version", "conf", "license_files", "doc_files"), 

12 [ 

13 # empty configuration 

14 ("a-lib", "0.1.0", TomlConf(), ["LICENSE"], ["README.md"]), 

15 # override lists 

16 ( 

17 "a-lib", 

18 "0.1.0", 

19 TomlConf(package=Package(license_files=["Cargo.toml"], doc_files=["Cargo.*"])), 

20 ["Cargo.toml"], 

21 ["Cargo.toml", "Cargo.toml.orig"], 

22 ), 

23 # includes / excludes 

24 ( 

25 "a-lib", 

26 "0.1.0", 

27 TomlConf( 

28 package=Package( 

29 license_files=FileInEx(include=["Cargo.toml"]), 

30 doc_files=FileInEx(include=["Cargo.*"]), 

31 ), 

32 ), 

33 ["Cargo.toml", "LICENSE"], 

34 ["Cargo.toml", "Cargo.toml.orig", "README.md"], 

35 ), 

36 ( 

37 "a-lib", 

38 "0.1.0", 

39 TomlConf( 

40 package=Package( 

41 license_files=FileInEx(include=["Cargo.toml"], exclude=["LICENSE*"]), 

42 doc_files=FileInEx(include=["Cargo.*"], exclude=["README.md"]), 

43 ), 

44 ), 

45 ["Cargo.toml"], 

46 ["Cargo.toml", "Cargo.toml.orig"], 

47 ), 

48 ], 

49 ids=repr, 

50) 

51def test_files_from_crate( 

52 crate_name: str, 

53 crate_version: str, 

54 conf: TomlConf, 

55 license_files: list[str], 

56 doc_files: list[str], 

57): 

58 filename = f"{crate_name}-{crate_version}.crate" 

59 crate_path = Path(str(resources.files("rust2rpm.tests.data.fixtures").joinpath(filename))) 

60 

61 with files_from_crate(crate_path, crate_name, crate_version, conf) as (_, lf, df): 

62 assert lf == license_files 

63 assert df == doc_files 

64 

65 

66@pytest.mark.parametrize( 

67 ("crate_name", "crate_version", "conf", "message"), 

68 [ 

69 # override lists 

70 ( 

71 "a-lib", 

72 "0.1.0", 

73 TomlConf(package=Package(license_files=["LICENSE-*"])), 

74 "No matches for specified %license file glob: 'LICENSE-*'", 

75 ), 

76 # includes / excludes 

77 ( 

78 "a-lib", 

79 "0.1.0", 

80 TomlConf(package=Package(license_files=FileInEx(exclude=["LICENSE-*"]))), 

81 "No matches for specified %license file glob: 'LICENSE-*'", 

82 ), 

83 ( 

84 "a-lib", 

85 "0.1.0", 

86 TomlConf(package=Package(doc_files=FileInEx(include=["README.md"]))), 

87 "Manually included %doc file already detected: 'README.md'", 

88 ), 

89 ( 

90 "a-lib", 

91 "0.1.0", 

92 TomlConf(package=Package(doc_files=FileInEx(include=["does-not-exist-*"]))), 

93 "No matches for specified %doc file glob: 'does-not-exist-*'", 

94 ), 

95 ( 

96 "a-lib", 

97 "0.1.0", 

98 TomlConf(package=Package(doc_files=FileInEx(exclude=["does-not-exist"]))), 

99 "Manually excluded %doc file not detected: 'does-not-exist'", 

100 ), 

101 ], 

102 ids=repr, 

103) 

104def test_files_from_crate_messages( 

105 capsys: pytest.CaptureFixture[str], 

106 crate_name: str, 

107 crate_version: str, 

108 conf: TomlConf, 

109 message: str, 

110): 

111 filename = f"{crate_name}-{crate_version}.crate" 

112 crate_path = Path(str(resources.files("rust2rpm.tests.data.fixtures").joinpath(filename))) 

113 

114 with files_from_crate(crate_path, crate_name, crate_version, conf) as (_, lf, df): 

115 pass 

116 

117 assert message in capsys.readouterr().err