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

32 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-27 15:21 +0100

1from importlib import resources 

2 

3import pytest 

4 

5from rust2rpm.conf import IniConf, TomlConf, to_list, conf_comments_to_spec_comments 

6 

7 

8@pytest.mark.parametrize( 

9 "string,expected", 

10 [ 

11 ("1\n2", ["1", "2"]), 

12 ("1\n\n 2", ["1", "2"]), 

13 (" 2 ", ["2"]), 

14 ("\n\n", []), 

15 ], 

16 ids=repr, 

17) 

18def test_to_list(string: str, expected: list[str]): 

19 assert to_list(string) == expected 

20 

21 

22@pytest.mark.parametrize( 

23 "filename,features,expected", 

24 [ 

25 ( 

26 "askalono-cli-0.4.6.rust2rpm.conf", 

27 {"diagnostics"}, 

28 IniConf(enabled_features=["diagnostics"], conf_file=True), 

29 ), 

30 ( 

31 "chrono-0.4.23.rust2rpm.conf", 

32 {"__doctest"}, 

33 IniConf(all_features=True, unwanted_features=["__doctest"], conf_file=True), 

34 ), 

35 ( 

36 "glib-sys-0.17.2.rust2rpm.conf", 

37 {"v2_58", "v2_60", "v2_62", "v2_64", "v2_66", "v2_68", "v2_70", "v2_72", "v2_74", "v2_76"}, 

38 IniConf( 

39 unwanted_features=["v2_76"], 

40 buildrequires=["pkgconfig(glib-2.0) >= 2.56"], 

41 lib_requires={ 

42 None: ["pkgconfig(glib-2.0) >= 2.56"], 

43 "v2_58": ["pkgconfig(glib-2.0) >= 2.58"], 

44 "v2_60": ["pkgconfig(glib-2.0) >= 2.60"], 

45 "v2_62": ["pkgconfig(glib-2.0) >= 2.62"], 

46 "v2_64": ["pkgconfig(glib-2.0) >= 2.64"], 

47 "v2_66": ["pkgconfig(glib-2.0) >= 2.66"], 

48 "v2_68": ["pkgconfig(glib-2.0) >= 2.68"], 

49 "v2_70": ["pkgconfig(glib-2.0) >= 2.70"], 

50 "v2_72": ["pkgconfig(glib-2.0) >= 2.72"], 

51 "v2_74": ["pkgconfig(glib-2.0) >= 2.74"], 

52 }, 

53 conf_file=True, 

54 ), 

55 ), 

56 ( 

57 "libsqlite3-sys-0.25.2.rust2rpm.conf", 

58 {"sqlcipher"}, 

59 IniConf( 

60 buildrequires=["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"], 

61 lib_requires={None: ["pkgconfig(sqlite3) >= 3.7.16"], "sqlcipher": ["pkgconfig(sqlcipher)"]}, 

62 conf_file=True, 

63 ), 

64 ), 

65 ], 

66) 

67def test_ini_conf_load( 

68 filename: str, 

69 features: set[str], 

70 expected: IniConf, 

71): 

72 path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) 

73 conf = IniConf.load([path], "fedora", features) 

74 assert conf == expected 

75 

76 

77@pytest.mark.parametrize( 

78 "filename,features,expected", 

79 [ 

80 ( 

81 "askalono-cli-0.4.6.rust2rpm.toml", 

82 {"diagnostics"}, 

83 TomlConf( 

84 { 

85 "features": { 

86 "enable": [ 

87 "diagnostics", 

88 ], 

89 }, 

90 }, 

91 ), 

92 ), 

93 ( 

94 "chrono-0.4.23.rust2rpm.toml", 

95 {"__doctest"}, 

96 TomlConf( 

97 { 

98 "features": { 

99 "enable-all": True, 

100 "hide": [ 

101 "__doctest", 

102 ], 

103 }, 

104 }, 

105 ), 

106 ), 

107 ( 

108 "dotenvy-0.15.7.rust2rpm.toml", 

109 set(), 

110 TomlConf( 

111 { 

112 "tests": { 

113 "run": [ 

114 "lib", 

115 "tests", 

116 ], 

117 "comments": [ 

118 "files required by doctests are not included in published crates", 

119 ], 

120 }, 

121 }, 

122 ), 

123 ), 

124 ( 

125 "glib-sys-0.17.2.rust2rpm.toml", 

126 {"v2_58", "v2_60", "v2_62", "v2_64", "v2_66", "v2_68", "v2_70", "v2_72", "v2_74", "v2_76"}, 

127 TomlConf( 

128 { 

129 "tests": { 

130 "run": ["none"], 

131 "comments": [ 

132 "tests are known to be broken upstream: https://github.com/gtk-rs/gtk-rs-core/issues/64" 

133 ], 

134 }, 

135 "features": { 

136 "hide": ["v2_76"], 

137 }, 

138 "requires": { 

139 "build": [ 

140 "pkgconfig(glib-2.0) >= 2.56", 

141 ], 

142 "lib": [ 

143 "pkgconfig(glib-2.0) >= 2.56", 

144 ], 

145 "features": { 

146 "v2_58": ["pkgconfig(glib-2.0) >= 2.58"], 

147 "v2_60": ["pkgconfig(glib-2.0) >= 2.60"], 

148 "v2_62": ["pkgconfig(glib-2.0) >= 2.62"], 

149 "v2_64": ["pkgconfig(glib-2.0) >= 2.64"], 

150 "v2_66": ["pkgconfig(glib-2.0) >= 2.66"], 

151 "v2_68": ["pkgconfig(glib-2.0) >= 2.68"], 

152 "v2_70": ["pkgconfig(glib-2.0) >= 2.70"], 

153 "v2_72": ["pkgconfig(glib-2.0) >= 2.72"], 

154 "v2_74": ["pkgconfig(glib-2.0) >= 2.74"], 

155 }, 

156 }, 

157 }, 

158 ), 

159 ), 

160 ( 

161 "libsqlite3-sys-0.25.2.rust2rpm.toml", 

162 {"sqlcipher"}, 

163 TomlConf( 

164 { 

165 "requires": { 

166 "build": [ 

167 "pkgconfig(sqlcipher)", 

168 "pkgconfig(sqlite3) >= 3.7.16", 

169 ], 

170 "lib": [ 

171 "pkgconfig(sqlite3) >= 3.7.16", 

172 ], 

173 "features": { 

174 "sqlcipher": [ 

175 "pkgconfig(sqlcipher)", 

176 ], 

177 }, 

178 } 

179 }, 

180 ), 

181 ), 

182 ( 

183 "nix-0.24.1.rust2rpm.toml", 

184 set(), 

185 TomlConf( 

186 { 

187 "tests": { 

188 "run": ["none"], 

189 "comments": ["tests are not reliable in containerized environments"], 

190 }, 

191 }, 

192 ), 

193 ), 

194 ( 

195 "reqwest-0.11.20.rust2rpm.toml", 

196 set(), 

197 TomlConf( 

198 { 

199 "tests": { 

200 "skip": [ 

201 "test_allowed_methods", 

202 "test_badssl_modern", 

203 "test_badssl_self_signed", 

204 ], 

205 "skip-exact": True, 

206 "comments": [ 

207 "skip tests which require internet access", 

208 ], 

209 }, 

210 }, 

211 ), 

212 ), 

213 ], 

214) 

215def test_toml_conf_load( 

216 filename: str, 

217 features: set[str], 

218 expected: TomlConf, 

219): 

220 path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) 

221 conf = TomlConf.load(path, features) 

222 assert conf == expected 

223 

224 

225@pytest.mark.parametrize( 

226 "filename,features,expected", 

227 [ 

228 ( 

229 "askalono-cli-0.4.6.rust2rpm.conf", 

230 {"diagnostics"}, 

231 TomlConf( 

232 { 

233 "features": { 

234 "enable": [ 

235 "diagnostics", 

236 ], 

237 }, 

238 }, 

239 ), 

240 ), 

241 ( 

242 "chrono-0.4.23.rust2rpm.conf", 

243 {"__doctest"}, 

244 TomlConf( 

245 { 

246 "features": { 

247 "enable-all": True, 

248 "hide": [ 

249 "__doctest", 

250 ], 

251 }, 

252 }, 

253 ), 

254 ), 

255 ( 

256 "glib-sys-0.17.2.rust2rpm.conf", 

257 {"v2_58", "v2_60", "v2_62", "v2_64", "v2_66", "v2_68", "v2_70", "v2_72", "v2_74", "v2_76"}, 

258 TomlConf( 

259 { 

260 "features": { 

261 "hide": ["v2_76"], 

262 }, 

263 "requires": { 

264 "build": [ 

265 "pkgconfig(glib-2.0) >= 2.56", 

266 ], 

267 "lib": [ 

268 "pkgconfig(glib-2.0) >= 2.56", 

269 ], 

270 "features": { 

271 "v2_58": ["pkgconfig(glib-2.0) >= 2.58"], 

272 "v2_60": ["pkgconfig(glib-2.0) >= 2.60"], 

273 "v2_62": ["pkgconfig(glib-2.0) >= 2.62"], 

274 "v2_64": ["pkgconfig(glib-2.0) >= 2.64"], 

275 "v2_66": ["pkgconfig(glib-2.0) >= 2.66"], 

276 "v2_68": ["pkgconfig(glib-2.0) >= 2.68"], 

277 "v2_70": ["pkgconfig(glib-2.0) >= 2.70"], 

278 "v2_72": ["pkgconfig(glib-2.0) >= 2.72"], 

279 "v2_74": ["pkgconfig(glib-2.0) >= 2.74"], 

280 }, 

281 }, 

282 }, 

283 ), 

284 ), 

285 ( 

286 "libsqlite3-sys-0.25.2.rust2rpm.conf", 

287 {"sqlcipher"}, 

288 TomlConf( 

289 { 

290 "requires": { 

291 "build": [ 

292 "pkgconfig(sqlcipher)", 

293 "pkgconfig(sqlite3) >= 3.7.16", 

294 ], 

295 "lib": [ 

296 "pkgconfig(sqlite3) >= 3.7.16", 

297 ], 

298 "features": { 

299 "sqlcipher": [ 

300 "pkgconfig(sqlcipher)", 

301 ], 

302 }, 

303 } 

304 }, 

305 ), 

306 ), 

307 ], 

308) 

309def test_conf_toml_from_ini( 

310 filename: str, 

311 features: set[str], 

312 expected: TomlConf, 

313): 

314 path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) 

315 conf = IniConf.load([path], "fedora", features) 

316 toml = TomlConf.from_conf(conf) 

317 assert toml == expected 

318 

319 

320@pytest.mark.parametrize( 

321 "filename,features,expected", 

322 [ 

323 ( 

324 "dotenvy-0.15.7.rust2rpm.toml", 

325 set(), 

326 ["# * files required by doctests are not included in published crates"], 

327 ), 

328 ( 

329 "reqwest-0.11.20.rust2rpm.toml", 

330 set(), 

331 ["# * skip tests which require internet access"], 

332 ), 

333 ], 

334 ids=repr, 

335) 

336def test_conf_to_test_comments(filename, features: set[str], expected: str): 

337 path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) 

338 conf = TomlConf.load(path, features) 

339 assert conf_comments_to_spec_comments(conf.tests_comments) == expected 

340 

341 

342@pytest.mark.parametrize( 

343 "filename,features,expected", 

344 [ 

345 ( 

346 "dotenvy-0.15.7.rust2rpm.toml", 

347 set(), 

348 [" -- --lib", " -- --tests"], 

349 ), 

350 ( 

351 "reqwest-0.11.20.rust2rpm.toml", 

352 set(), 

353 [" -- -- --exact --skip test_allowed_methods --skip test_badssl_modern --skip test_badssl_self_signed"], 

354 ), 

355 ], 

356 ids=repr, 

357) 

358def test_conf_to_cargo_test_args(filename, features: set[str], expected: str): 

359 path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) 

360 conf = TomlConf.load(path, features) 

361 assert conf.to_cargo_test_args() == expected