(self)
| 143 | self.assertTarFileContent(self.tempfile, content) |
| 144 | |
| 145 | def test_adding_tree(self): |
| 146 | content = [ |
| 147 | { |
| 148 | "name": "./a", |
| 149 | "mode": 0o750 |
| 150 | }, |
| 151 | { |
| 152 | "name": "./a/b", |
| 153 | "data": b"ab", |
| 154 | "mode": 0o640 |
| 155 | }, |
| 156 | { |
| 157 | "name": "./a/c", |
| 158 | "mode": 0o750 |
| 159 | }, |
| 160 | { |
| 161 | "name": "./a/c/d", |
| 162 | "data": b"acd", |
| 163 | "mode": 0o640 |
| 164 | }, |
| 165 | ] |
| 166 | tempdir = os.path.join(os.environ["TEST_TMPDIR"], "test_dir") |
| 167 | # Iterate over the `content` array to create the directory |
| 168 | # structure it describes. |
| 169 | for c in content: |
| 170 | if "data" in c: |
| 171 | p = os.path.join(tempdir, c["name"]) |
| 172 | os.makedirs(os.path.dirname(p)) |
| 173 | with open(p, "wb") as f: |
| 174 | f.write(c["data"]) |
| 175 | with mini_tar.TarFileWriter(self.tempfile) as f: |
| 176 | f.add_file_at_dest(in_path=tempdir, dest_path=".", mode=0o640) |
| 177 | self.assertTarFileContent(self.tempfile, content) |
| 178 | |
| 179 | # Try it again, but re-rooted |
| 180 | with mini_tar.TarFileWriter(self.tempfile, root_directory="foo") as f: |
| 181 | f.add_file_at_dest(in_path=tempdir, dest_path="x", mode=0o640) |
| 182 | n_content = [ |
| 183 | { |
| 184 | "name": "foo", |
| 185 | "mode": 0o755 |
| 186 | }, |
| 187 | { |
| 188 | "name": "foo/x", |
| 189 | "mode": 0o750 |
| 190 | }, |
| 191 | ] |
| 192 | for c in content: |
| 193 | nc = copy.copy(c) |
| 194 | nc["name"] = "foo/x/" + c["name"][2:] |
| 195 | n_content.append(nc) |
| 196 | self.assertTarFileContent(self.tempfile, n_content) |
| 197 | |
| 198 | |
| 199 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected