|
| 1 | +import contextlib |
| 2 | +import os.path |
| 3 | +from textwrap import dedent |
| 4 | + |
1 | 5 | import pytest |
2 | 6 |
|
3 | | -from rapids_dependency_file_generator._cli import generate_matrix, validate_args |
| 7 | +from rapids_dependency_file_generator._cli import generate_matrix, main, validate_args |
| 8 | +from rapids_dependency_file_generator._rapids_dependency_file_validator import UnusedDependencySetWarning |
4 | 9 |
|
5 | 10 |
|
6 | 11 | def test_generate_matrix(): |
@@ -181,3 +186,52 @@ def test_validate_args(): |
181 | 186 |
|
182 | 187 | args = validate_args(["--version"]) |
183 | 188 | assert args.version |
| 189 | + |
| 190 | + |
| 191 | +@pytest.mark.parametrize( |
| 192 | + ["extra_args", "context"], |
| 193 | + [ |
| 194 | + ( |
| 195 | + [], |
| 196 | + contextlib.nullcontext(), |
| 197 | + ), |
| 198 | + ( |
| 199 | + ["--strict"], |
| 200 | + contextlib.nullcontext(), |
| 201 | + ), |
| 202 | + ( |
| 203 | + ["--warn-unused-dependencies"], |
| 204 | + pytest.warns(UnusedDependencySetWarning), |
| 205 | + ), |
| 206 | + ( |
| 207 | + ["--warn-unused-dependencies", "--strict"], |
| 208 | + pytest.raises(UnusedDependencySetWarning), |
| 209 | + ), |
| 210 | + ( |
| 211 | + ["--warn-all"], |
| 212 | + pytest.warns(UnusedDependencySetWarning), |
| 213 | + ), |
| 214 | + ( |
| 215 | + ["--warn-all", "--strict"], |
| 216 | + pytest.raises(UnusedDependencySetWarning), |
| 217 | + ), |
| 218 | + ], |
| 219 | +) |
| 220 | +def test_warnings(tmp_path, extra_args, context): |
| 221 | + config_file = os.path.join(tmp_path, "dependencies.yaml") |
| 222 | + with open(config_file, "w") as f: |
| 223 | + f.write(dedent(""" |
| 224 | + files: |
| 225 | + all: |
| 226 | + output: conda |
| 227 | + includes: [a] |
| 228 | + channels: [] |
| 229 | + dependencies: |
| 230 | + a: |
| 231 | + common: [] |
| 232 | + b: |
| 233 | + common: [] |
| 234 | + """)) |
| 235 | + |
| 236 | + with context: |
| 237 | + main(["--config", config_file, *extra_args]) |
0 commit comments