MCPcopy
hub / github.com/bazelbuild/bazel / test_adding_tree

Method test_adding_tree

tools/mini_tar/mini_tar_test.py:145–196  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
199if __name__ == "__main__":

Callers

nothing calls this directly

Calls 6

assertTarFileContentMethod · 0.95
add_file_at_destMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
copyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected