|
1 | 1 | import os
|
| 2 | +import pytest |
2 | 3 |
|
3 | 4 | # Check it is importable from tools
|
4 | 5 | from conan.tools.files import rm, chdir
|
@@ -63,3 +64,46 @@ def test_remove_files_by_mask_non_recursively():
|
63 | 64 |
|
64 | 65 | assert os.path.exists(os.path.join(tmpdir, "1.txt"))
|
65 | 66 | assert os.path.exists(os.path.join(tmpdir, "subdir", "2.txt"))
|
| 67 | + |
| 68 | + |
| 69 | +@pytest.mark.parametrize("recursive", [False, True]) |
| 70 | +@pytest.mark.parametrize("results", [ |
| 71 | + ["*.dll", ("foo.dll",)], |
| 72 | + [("*.dll",), ("foo.dll",)], |
| 73 | + [["*.dll"], ("foo.dll",)], |
| 74 | + [("*.dll", "*.lib"), ("foo.dll", "foo.dll.lib")], |
| 75 | +]) |
| 76 | +def test_exclude_pattern_from_remove_list(recursive, results): |
| 77 | + """ conan.tools.files.rm should not remove files that match the pattern but are excluded |
| 78 | + by the excludes parameter. |
| 79 | + It should obey the recursive parameter, only excluding the files in the root folder in case |
| 80 | + it is False. |
| 81 | + """ |
| 82 | + excludes, expected_files = results |
| 83 | + temporary_folder = temp_folder() |
| 84 | + with chdir(None, temporary_folder): |
| 85 | + os.makedirs("subdir") |
| 86 | + |
| 87 | + save_files(temporary_folder, { |
| 88 | + "1.txt": "", |
| 89 | + "1.pdb": "", |
| 90 | + "1.pdb1": "", |
| 91 | + "foo.dll": "", |
| 92 | + "foo.dll.lib": "", |
| 93 | + os.path.join("subdir", "2.txt"): "", |
| 94 | + os.path.join("subdir", "2.pdb"): "", |
| 95 | + os.path.join("subdir", "foo.dll"): "", |
| 96 | + os.path.join("subdir", "foo.dll.lib"): "", |
| 97 | + os.path.join("subdir", "2.pdb1"): ""}) |
| 98 | + |
| 99 | + rm(None, "*", temporary_folder, excludes=excludes, recursive=recursive) |
| 100 | + |
| 101 | + for it in expected_files: |
| 102 | + assert os.path.exists(os.path.join(temporary_folder, it)) |
| 103 | + assert not os.path.exists(os.path.join(temporary_folder, "1.pdb")) |
| 104 | + |
| 105 | + # Check the recursive parameter and subfolder |
| 106 | + condition = (lambda x: not x) if recursive else (lambda x: x) |
| 107 | + assert condition(os.path.exists(os.path.join(temporary_folder, "subdir", "2.pdb"))) |
| 108 | + for it in expected_files: |
| 109 | + assert os.path.exists(os.path.join(temporary_folder, "subdir", it)) |
0 commit comments