|
5 | 5 |
|
6 | 6 | import os |
7 | 7 | from contextlib import contextmanager |
8 | | -from scratchrelaxtv import cli, StubMaker, VarExtractor, EXIT_OKAY |
| 8 | +from scratchrelaxtv import cli, StubMaker, VarExtractor, EXIT_OKAY, \ |
| 9 | + remove_files |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @contextmanager |
@@ -89,3 +90,33 @@ def test_same_content_maker(): |
89 | 90 | second_list = file_handle.read().splitlines() |
90 | 91 | assert first_list == second_list |
91 | 92 | os.remove(filename) |
| 93 | + |
| 94 | + |
| 95 | +def test_removal(): |
| 96 | + """Test removing files.""" |
| 97 | + with change_dir("tests"): |
| 98 | + tmpdir = "tmpdir" |
| 99 | + os.mkdir(tmpdir) |
| 100 | + |
| 101 | + with open(os.path.join(tmpdir, "modstub.tf"), "w") as file_handle: |
| 102 | + file_handle.write("hello") |
| 103 | + |
| 104 | + with open(os.path.join(tmpdir, "variables.5.tf"), "w") as file_handle: |
| 105 | + file_handle.write("hello") |
| 106 | + |
| 107 | + with open(os.path.join(tmpdir, "modstub.2.tf"), "w") as file_handle: |
| 108 | + file_handle.write("hello") |
| 109 | + |
| 110 | + with open(os.path.join(tmpdir, "dont_delete.tf"), "w") as file_handle: |
| 111 | + file_handle.write("hello") |
| 112 | + |
| 113 | + with change_dir(tmpdir): |
| 114 | + remove_files() |
| 115 | + |
| 116 | + assert not os.path.isfile(os.path.join(tmpdir, "modstub.tf")) |
| 117 | + assert not os.path.isfile(os.path.join(tmpdir, "variables.5.tf")) |
| 118 | + assert not os.path.isfile(os.path.join(tmpdir, "modstub.2.tf")) |
| 119 | + assert os.path.isfile(os.path.join(tmpdir, "dont_delete.tf")) |
| 120 | + |
| 121 | + os.remove(os.path.join(tmpdir, "dont_delete.tf")) |
| 122 | + os.rmdir(tmpdir) |
0 commit comments