def test_fix(self): self.fh = open(self.test_file, 'rb') self.tarfixer.fh = self.fh self.tarfixer.fix() self.assertEqual( self.reference_hash, self.hash_buffer(encode_bytes(self.out.getvalue(), "utf8")))
def test_encode_header(self): mode = 123 chunk = { 'mode': mode, 'name': 'hello', } result = self.tarfixer.encode_header(chunk, ['mode', 'name']) expected_result = ["%07o\x00" % mode, "hello"] expected_result = list(map(lambda x: encode_bytes(x, "utf8"), expected_result)) self.assertEqual(expected_result, result)
def create_extended_header(self): # pax extended header records have the format "%u %s=%s\n". %u contains # the size of the whole string (including the %u), the first %s is the # keyword, the second one is the value. # # Since the git ref is always 40 characters we can # pre-compute the length to put in the extended header comment = "52 comment=%s\n" % self.gitref data_out = struct.pack("=52s460x", encode_bytes(comment, "ascii")) self.write(data_out) self.total_length += len(data_out)
def test_encode_header(self): mode = 123 chunk = { 'mode': mode, 'name': 'hello', } result = self.tarfixer.encode_header(chunk, ['mode', 'name']) expected_result = ["%07o\x00" % mode, "hello"] expected_result = list( map(lambda x: encode_bytes(x, "utf8"), expected_result)) self.assertEqual(expected_result, result)
def test_fix(self): self.fh = open(self.test_file, 'rb') self.tarfixer.fh = self.fh self.tarfixer.fix() self.assertEqual(self.reference_hash, self.hash_buffer(encode_bytes(self.out.getvalue(), "utf8")))