def must_equal(self, tar_path, expect, expect_attrs, attrkeys = None):
     if attrkeys is None:
         attrkeys = ["size", "sha1", "mode"]
     m = ManifestTarWalker().build(t_path(tar_path), attrkeys = attrkeys)
     self.assertEqual(m, expect)
     for path, e_attrs in expect_attrs.items():
         self.assertEqual(m.resolve(path).getattrs(), e_attrs)
 def test_files_with_contents(self):
     import os
     s = os.stat(t_path("files_with_contents.tar"))
     expect_uid, expect_gid = s.st_uid, s.st_gid
     m = Manifest_from_walking_unpacked_tar("files_with_contents.tar")
     self.assertEqual(m, {
         "foo": {},
         "bar": {"baz": {}},
         "symlink_to_bar_baz": {}
     })
     self.assertEqual(m.resolve("foo").getattrs(), {
         "size": 12,
         "sha1": "fc6da897c87c7b9c3b67d1d5af32085e561db793",
         "mode": 0o100644,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("bar").getattrs(), {
         "mode": 0o040755,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("bar/baz").getattrs(), {
         "size": 12,
         "sha1": "7508a86c26bcda1d3f298f67de33f7c48a3fe047",
         "mode": 0o100644,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("symlink_to_bar_baz").getattrs(), {
         "mode": 0o120777,
         "uid": expect_uid,
         "gid": expect_gid,
     })
 def test_files_with_contents(self):
     import tarfile
     tf = tarfile.open(t_path("files_with_contents.tar"), errorlevel=1)
     ti = tf.next()
     expect_uid, expect_gid = ti.uid, ti.gid
     tf.close()
     m = ManifestTarWalker().build(t_path("files_with_contents.tar"))
     self.assertEqual(m, {
         "foo": {},
         "bar": {"baz": {}},
         "symlink_to_bar_baz": {}
     })
     self.assertEqual(m.resolve("foo").getattrs(), {
         "size": 12,
         "sha1": "fc6da897c87c7b9c3b67d1d5af32085e561db793",
         "mode": 0o100644,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("bar").getattrs(), {
         "mode": 0o040755,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("bar/baz").getattrs(), {
         "size": 12,
         "sha1": "7508a86c26bcda1d3f298f67de33f7c48a3fe047",
         "mode": 0o100644,
         "uid": expect_uid,
         "gid": expect_gid,
     })
     self.assertEqual(m.resolve("symlink_to_bar_baz").getattrs(), {
         "mode": 0o120777,
         "uid": expect_uid,
         "gid": expect_gid,
     })
 def test_files_at_many_levels_at_subdir(self):
     m = self.mtw.build(t_path("files_at_many_levels.tar"), "./baz/")
     self.assertEqual(m, {
         "foo": {}, "bar": {}, "baz": { "foo": {}, "bar": {}, "baz": {} } })
 def test_file_and_subdir_at_subdir(self):
     m = self.mtw.build(t_path("file_and_subdir.tar"), "./subdir/")
     self.assertEqual(m, {"foo": {}})
 def test_not_a_tar(self):
     self.assertRaises(Exception, self.mtw.build, t_path("not_tar"))
 def test_missing_raises_ValueError(self):
     self.assertRaises(Exception, self.mtw.build, t_path("missing.tar"))
 def must_equal(self, tar_path, expect):
     self.assertEqual(self.mtw.build(t_path(tar_path)), expect)
 def test_not_a_dir(self):
     self.assertRaises(ValueError, self.mdw.build, t_path("plain_file"))
Esempio n. 10
0
 def test_missing_raises_ValueError(self):
     self.assertRaises(ValueError, self.mdw.build, t_path("missing"))