MCPcopy Index your code
hub / github.com/bazelbuild/bazel / assertTarFileContent

Method assertTarFileContent

tools/mini_tar/mini_tar_test.py:28–59  ·  view source on GitHub ↗

Assert that tarfile contains exactly the entry described by `content`. Args: tar: the path to the TAR file to test. content: an array describing the expected content of the TAR file. Each entry in that list should be a dictionary where each field is a f

(self, tar, content)

Source from the content-addressed store, hash-verified

26 """Testing for TarFileWriter class."""
27
28 def assertTarFileContent(self, tar, content):
29 """Assert that tarfile contains exactly the entry described by `content`.
30
31 Args:
32 tar: the path to the TAR file to test.
33 content: an array describing the expected content of the TAR file. Each
34 entry in that list should be a dictionary where each field is a
35 field to test in the corresponding TarInfo. For testing the
36 presence of a file "x", then the entry could simply be
37 `{"name": "x"}`, the missing field will be ignored. To match the
38 content of a file entry, use the key "data".
39 """
40 with tarfile.open(tar, "r:") as f:
41 i = 0
42 for current in f:
43 error_msg = "Extraneous file at end of archive %s: %s" % (tar,
44 current.name)
45 self.assertLess(i, len(content), error_msg)
46 for k, v in content[i].items():
47 if k == "data":
48 value = f.extractfile(current).read()
49 else:
50 value = getattr(current, k)
51 error_msg = " ".join([
52 "Value `%s` for key `%s` of file" % (value, k),
53 "%s in archive %s does" % (current.name, tar),
54 "not match expected value `%s`" % v
55 ])
56 self.assertEqual(value, v, error_msg)
57 i += 1
58 if i < len(content):
59 self.fail("Missing file %s in archive %s" % (content[i], tar))
60
61 def setUp(self):
62 super(TarFileWriterTest, self).setUp()

Callers 4

test_empty_tar_fileMethod · 0.95
test_files_with_dotsMethod · 0.95
test_add_parentsMethod · 0.95
test_adding_treeMethod · 0.95

Calls 4

itemsMethod · 0.80
readMethod · 0.65
joinMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected