Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
testing and cleanup
Browse files Browse the repository at this point in the history
* cleaning up the import of monkey patched tarfile
* adding a test for vanilla tarfile (whether it still fails)
* fixing the 'assert' formatting

Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
  • Loading branch information
vbatts committed Jun 24, 2014
1 parent c1a8ca9 commit 09e9e20
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
7 changes: 3 additions & 4 deletions docker_registry/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from .lib import checksums
from .lib import layers
from .lib import mirroring
from .lib import xtarfile


tarfile = xtarfile.tarfile
# this is our monkey patched snippet from python v2.7.6 'tarfile'
# with xattr support
from .lib.xtarfile import tarfile


store = storage.load()
Expand Down
8 changes: 3 additions & 5 deletions docker_registry/lib/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
from .. import storage
from . import cache
from . import rqueue
# this is our monkey patched 'tarfile' from python v2.7.6, with xattr support
from . import xtarfile


tarfile = xtarfile.tarfile
# this is our monkey patched snippet from python v2.7.6 'tarfile'
# with xattr support
from .xtarfile import tarfile


store = storage.load()
Expand Down
5 changes: 0 additions & 5 deletions docker_registry/lib/xtarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
import re
import tarfile

tarfile.PAX_FIELDS = tarfile.PAX_FIELDS + ("SCHILY.xattr.",)
tarfile.PAX_NUMBER_FIELDS["SCHILY.xattr."] = dict

# class XattrTarInfo(tarfile.TarInfo):


def _proc_pax(self, filetar):
"""Process an extended or global header as described in
Expand Down
58 changes: 31 additions & 27 deletions tests/test_tarfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# -*- coding: utf-8 -*-

import imp
import os

from nose import tools

import base
from docker_registry.lib import checksums
from docker_registry.lib import xtarfile


# setting like this in test, due to flake8 H302
tarfile = xtarfile.tarfile

# To test whether the UnicodeDecodeError still exists
# (it's still present in python 3.4.0)
# ((loading this way, since we've monkey patched currently loaded tarfile))
tarfile_vanilla = imp.load_module('test_failing', *imp.find_module('tarfile'))


class TestTarfile(base.TestCase):
@tools.raises(UnicodeDecodeError)
def test_vanilla_tarfile(self):
layer_fh = open(os.path.join(base.data_dir, "xattr/layer.tar"))
tar = tarfile_vanilla.open(mode='r|*', fileobj=layer_fh)
assert tar

def test_headers(self):
expected = {
"46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar": { # noqa
Expand Down Expand Up @@ -70,31 +86,21 @@ def test_headers(self):
for member in tar:
member_count += 1
# check that we know the file names
assert(
(len(
filter(
lambda x: member.path in x, expected[file].keys()
)
) > 0), "in %s, did not find file %s" % (
file,
member.path))
msg = "in %s, did not find file %s" % (file, member.path)
l = len(filter(lambda x: member.path in x,
expected[file].keys()))
assert (l > 0), msg
e = expected[file][member.path]
for attr in e["headers"].keys():
assert(e["headers"][attr] == getattr(member, attr),
"in %s:%s, expected %s of %s, but got %s" % (
file,
member.path,
attr,
e["headers"][attr],
getattr(member, attr)))
msg = "in %s:%s, expected %s of %s, but got %s" % (
file, member.path, attr, e["headers"][attr],
getattr(member, attr))
assert e["headers"][attr] == getattr(member, attr), msg
for attr in e["pax"].keys():
assert(e["pax"][attr] == member.pax_headers[attr],
b"in %s:%s, expected %s of %s, but got %s".format(
file,
member.path,
attr,
e["pax"][attr],
member.pax_headers[attr]))
msg = b"in %s:%s, expected %s of %s, but got %s".format(
file, member.path, attr, e["pax"][attr],
member.pax_headers[attr])
assert e["pax"][attr] == member.pax_headers[attr], msg

assert member_count == len(expected[file])
layer_fh.close()
Expand All @@ -114,11 +120,9 @@ def test_tarsum(self):
for member in tar:
tarsum.append(member, tar)
sum = tarsum.compute()
assert(expected[layer] == sum,
"layer %s, expected [%s] but got [%s]" % (
layer,
expected[layer],
sum))
msg = "layer %s, expected [%s] but got [%s]" % (
layer, expected[layer], sum)
assert expected[layer] == sum, msg

layer_fh.close()
json_fh.close()

0 comments on commit 09e9e20

Please sign in to comment.