update_payload: Fix most of lint styling issues.
This patch fixes a lot of pylint issues in the update_engine scripts. Majority
of this changes are based on recommendation found in:
https://www.chromium.org/chromium-os/python-style-guidelines
It is a good idea to do these changes now, because if there are many pylint
errors when performing 'repo upload', serious problems can be overshadowed by a
lot of noise and eventually cause problems.
These fixes include:
- Fixing executable shebangs to /usr/bin/python2.
- Fixing import-error problems by disabiling them.
- Removing pylint disables that are not valid anymore.
- Changing all imports to proper absolute import format.
- Change the import of PayloadError from update_payload.PayloadError for
simplicity.
- Add pydoc strings for functions and classes that were missing.
The remaining unchanged pylint problmes include:
- The header files of these scripts are in CrOS copyright format, but the
the cros lint hook is configured to AoSP copyright format.
- The test* functions in unittests are not compatible with CamelCase format.
BUG=chromium:796338
TEST=unittests pass
TEST=start_devserver
TEST=cros flash
TEST=scripts/paycheck.py
Change-Id: I7eed4d1625eb7c510c7949fada120de5a6a26c7b
Reviewed-on: https://chromium-review.googlesource.com/834875
Commit-Ready: Amin Hassani <[email protected]>
Tested-by: Amin Hassani <[email protected]>
Reviewed-by: Ben Chan <[email protected]>
Reviewed-by: Sen Jiang <[email protected]>
diff --git a/scripts/blockdiff.py b/scripts/blockdiff.py
index feb5bd9..1dc60a6 100755
--- a/scripts/blockdiff.py
+++ b/scripts/blockdiff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
#
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -6,6 +6,8 @@
"""Block diff utility."""
+from __future__ import print_function
+
import optparse
import sys
@@ -92,7 +94,7 @@
diff_list = BlockDiff(opts.block_size, file1, file2, name1, name2,
opts.max_length)
except BlockDiffError as e:
- print >> sys.stderr, 'Error:', e
+ print('Error: ' % e, file=sys.stderr)
return 2
# Print the diff, if such was found.
@@ -103,7 +105,7 @@
print('%d->%d (%d)' %
(extent_start, extent_start + extent_length, extent_length))
- print 'total diff: %d blocks' % total_diff_blocks
+ print('total diff: %d blocks' % total_diff_blocks)
return 1
return 0
diff --git a/scripts/paycheck.py b/scripts/paycheck.py
index c87c202..8df1bf0 100755
--- a/scripts/paycheck.py
+++ b/scripts/paycheck.py
@@ -12,7 +12,6 @@
import os
import sys
-# pylint: disable=F0401
lib_dir = os.path.join(os.path.dirname(__file__), 'lib')
if os.path.exists(lib_dir) and os.path.isdir(lib_dir):
sys.path.insert(1, lib_dir)
diff --git a/scripts/update_payload/__init__.py b/scripts/update_payload/__init__.py
index 1906a16..e4a5588 100644
--- a/scripts/update_payload/__init__.py
+++ b/scripts/update_payload/__init__.py
@@ -5,7 +5,6 @@
"""Library for processing, verifying and applying Chrome OS update payloads."""
# Just raise the interface classes to the root namespace.
-# pylint: disable=W0401
-from checker import CHECKS_TO_DISABLE
-from error import PayloadError
-from payload import Payload
+from update_payload.checker import CHECKS_TO_DISABLE
+from update_payload.error import PayloadError
+from update_payload.payload import Payload
diff --git a/scripts/update_payload/applier.py b/scripts/update_payload/applier.py
index 3cb9741..e470ac4 100644
--- a/scripts/update_payload/applier.py
+++ b/scripts/update_payload/applier.py
@@ -24,8 +24,8 @@
import sys
import tempfile
-import common
-from error import PayloadError
+from update_payload import common
+from update_payload.error import PayloadError
#
@@ -44,7 +44,6 @@
PayloadError if computed hash doesn't match expected one, or if fails to
read the specified length of data.
"""
- # pylint: disable=E1101
hasher = hashlib.sha256()
block_length = 1024 * 1024
max_length = length if length >= 0 else sys.maxint
@@ -316,6 +315,7 @@
base_name = '%s.dst_extents' % op_name
# Iterate over the extents and write zero.
+ # pylint: disable=unused-variable
for ex, ex_name in common.ExtentIter(op.dst_extents, base_name):
# Only do actual writing if this is not a pseudo-extent.
if ex.start_block != common.PSEUDO_EXTENT_MARKER:
@@ -361,6 +361,7 @@
"""
length = 0
+ # pylint: disable=unused-variable
for ex, ex_name in common.ExtentIter(extents, base_name):
length += ex.num_blocks * self.block_size
return length
diff --git a/scripts/update_payload/block_tracer.py b/scripts/update_payload/block_tracer.py
index f222b21..5caf7e3 100644
--- a/scripts/update_payload/block_tracer.py
+++ b/scripts/update_payload/block_tracer.py
@@ -16,7 +16,7 @@
from __future__ import print_function
-import common
+from update_payload import common
#
diff --git a/scripts/update_payload/checker.py b/scripts/update_payload/checker.py
index c710c47..e4cb845 100644
--- a/scripts/update_payload/checker.py
+++ b/scripts/update_payload/checker.py
@@ -21,11 +21,11 @@
import os
import subprocess
-import common
-import error
-import format_utils
-import histogram
-import update_metadata_pb2
+from update_payload import common
+from update_payload import error
+from update_payload import format_utils
+from update_payload import histogram
+from update_payload import update_metadata_pb2
#
@@ -970,8 +970,6 @@
op_name)
# Check: Hash verifies correctly.
- # pylint cannot find the method in hashlib, for some reason.
- # pylint: disable=E1101
actual_hash = hashlib.sha256(self.payload.ReadDataBlob(data_offset,
data_length))
if op.data_sha256_hash != actual_hash.digest():
@@ -1168,8 +1166,6 @@
report.AddSection('signatures')
# Check: At least one signature present.
- # pylint cannot see through the protobuf object, it seems.
- # pylint: disable=E1101
if not sigs.signatures:
raise error.PayloadError('Signature block is empty.')
diff --git a/scripts/update_payload/checker_unittest.py b/scripts/update_payload/checker_unittest.py
index 245da55..974519d 100755
--- a/scripts/update_payload/checker_unittest.py
+++ b/scripts/update_payload/checker_unittest.py
@@ -20,14 +20,16 @@
# pylint: disable=F0401
import mox
-import checker
-import common
-import payload as update_payload # Avoid name conflicts later.
-import test_utils
-import update_metadata_pb2
+from update_payload import checker
+from update_payload import common
+from update_payload import test_utils
+from update_payload import update_metadata_pb2
+from update_payload.error import PayloadError
+from update_payload.payload import Payload # Avoid name conflicts later.
def _OpTypeByName(op_name):
+ """Returns the type of an operation from itsname."""
op_name_to_type = {
'REPLACE': common.OpType.REPLACE,
'REPLACE_BZ': common.OpType.REPLACE_BZ,
@@ -55,7 +57,7 @@
payload_file = cStringIO.StringIO()
payload_gen_write_to_file_func(payload_file, **payload_gen_dargs)
payload_file.seek(0)
- payload = update_payload.Payload(payload_file)
+ payload = Payload(payload_file)
payload.Init()
return checker.PayloadChecker(payload, **checker_init_dargs)
@@ -65,7 +67,7 @@
payload_file = cStringIO.StringIO()
payload_gen.WriteToFile(payload_file)
payload_file.seek(0)
- payload = update_payload.Payload(payload_file)
+ payload = Payload(payload_file)
payload.Init()
return checker.PayloadChecker(payload)
@@ -91,7 +93,7 @@
def MockPayload(self):
"""Create a mock payload object, complete with a mock manifest."""
- payload = self.mox.CreateMock(update_payload.Payload)
+ payload = self.mox.CreateMock(Payload)
payload.is_init = True
payload.manifest = self.mox.CreateMock(
update_metadata_pb2.DeltaArchiveManifest)
@@ -195,7 +197,7 @@
args = (msg, name, report, is_mandatory, is_submsg)
kwargs = {'convert': convert, 'linebreak': linebreak, 'indent': indent}
if is_mandatory and not is_present:
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckElem, *args, **kwargs)
else:
ret_val, ret_subreport = checker.PayloadChecker._CheckElem(*args,
@@ -229,8 +231,7 @@
# Test the method call.
if is_mandatory and not is_present:
- self.assertRaises(update_payload.PayloadError, tested_func, *args,
- **kwargs)
+ self.assertRaises(PayloadError, tested_func, *args, **kwargs)
else:
ret_val = tested_func(*args, **kwargs)
self.assertEquals(val if is_present else None, ret_val)
@@ -254,7 +255,7 @@
# Test the method call.
if is_mandatory and not is_present:
- self.assertRaises(update_payload.PayloadError, tested_func, *args)
+ self.assertRaises(PayloadError, tested_func, *args)
else:
ret_val, ret_subreport = tested_func(*args)
self.assertEquals(val if is_present else None, ret_val)
@@ -266,11 +267,9 @@
None, None, 'foo', 'bar', 'baz'))
self.assertIsNone(checker.PayloadChecker._CheckPresentIff(
'a', 'b', 'foo', 'bar', 'baz'))
- self.assertRaises(update_payload.PayloadError,
- checker.PayloadChecker._CheckPresentIff,
+ self.assertRaises(PayloadError, checker.PayloadChecker._CheckPresentIff,
'a', None, 'foo', 'bar', 'baz')
- self.assertRaises(update_payload.PayloadError,
- checker.PayloadChecker._CheckPresentIff,
+ self.assertRaises(PayloadError, checker.PayloadChecker._CheckPresentIff,
None, 'b', 'foo', 'bar', 'baz')
def DoCheckSha256SignatureTest(self, expect_pass, expect_subprocess_call,
@@ -299,7 +298,7 @@
self.assertIsNone(checker.PayloadChecker._CheckSha256Signature(
sig_data, 'foo', expected_signed_hash, 'bar'))
else:
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckSha256Signature,
sig_data, 'foo', expected_signed_hash, 'bar')
finally:
@@ -359,31 +358,31 @@
def testCheckBlocksFitLength_TooManyBlocks(self):
"""Tests _CheckBlocksFitLength(); fails due to excess blocks."""
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
64, 5, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
60, 5, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
49, 5, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
48, 4, 16, 'foo')
def testCheckBlocksFitLength_TooFewBlocks(self):
"""Tests _CheckBlocksFitLength(); fails due to insufficient blocks."""
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
64, 3, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
60, 3, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
49, 3, 16, 'foo')
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
checker.PayloadChecker._CheckBlocksFitLength,
48, 2, 16, 'foo')
@@ -476,8 +475,7 @@
fail_old_rootfs_fs_size or fail_new_kernel_fs_size or
fail_new_rootfs_fs_size)
if should_fail:
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckManifest, report,
+ self.assertRaises(PayloadError, payload_checker._CheckManifest, report,
rootfs_part_size, kernel_part_size)
else:
self.assertIsNone(payload_checker._CheckManifest(report,
@@ -493,12 +491,10 @@
self.assertIsNone(payload_checker._CheckLength(
int(3.5 * block_size), 4, 'foo', 'bar'))
# Fails, too few blocks.
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckLength,
+ self.assertRaises(PayloadError, payload_checker._CheckLength,
int(3.5 * block_size), 3, 'foo', 'bar')
# Fails, too many blocks.
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckLength,
+ self.assertRaises(PayloadError, payload_checker._CheckLength,
int(3.5 * block_size), 5, 'foo', 'bar')
def testCheckExtents(self):
@@ -533,30 +529,26 @@
# Fails, extent missing a start block.
extents = self.NewExtentList((-1, 4), (8, 3), (1024, 16))
self.assertRaises(
- update_payload.PayloadError, payload_checker._CheckExtents,
- extents, (1024 + 16) * block_size, collections.defaultdict(int),
- 'foo')
+ PayloadError, payload_checker._CheckExtents, extents,
+ (1024 + 16) * block_size, collections.defaultdict(int), 'foo')
# Fails, extent missing block count.
extents = self.NewExtentList((0, -1), (8, 3), (1024, 16))
self.assertRaises(
- update_payload.PayloadError, payload_checker._CheckExtents,
- extents, (1024 + 16) * block_size, collections.defaultdict(int),
- 'foo')
+ PayloadError, payload_checker._CheckExtents, extents,
+ (1024 + 16) * block_size, collections.defaultdict(int), 'foo')
# Fails, extent has zero blocks.
extents = self.NewExtentList((0, 4), (8, 3), (1024, 0))
self.assertRaises(
- update_payload.PayloadError, payload_checker._CheckExtents,
- extents, (1024 + 16) * block_size, collections.defaultdict(int),
- 'foo')
+ PayloadError, payload_checker._CheckExtents, extents,
+ (1024 + 16) * block_size, collections.defaultdict(int), 'foo')
# Fails, extent exceeds partition boundaries.
extents = self.NewExtentList((0, 4), (8, 3), (1024, 16))
self.assertRaises(
- update_payload.PayloadError, payload_checker._CheckExtents,
- extents, (1024 + 15) * block_size, collections.defaultdict(int),
- 'foo')
+ PayloadError, payload_checker._CheckExtents, extents,
+ (1024 + 15) * block_size, collections.defaultdict(int), 'foo')
def testCheckReplaceOperation(self):
"""Tests _CheckReplaceOperation() where op.type == REPLACE."""
@@ -578,22 +570,19 @@
# Fail, src extents founds.
op.src_extents = ['bar']
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, data_length, (data_length + block_size - 1) / block_size, 'foo')
# Fail, missing data.
op.src_extents = []
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, None, (data_length + block_size - 1) / block_size, 'foo')
# Fail, length / block number mismatch.
op.src_extents = ['bar']
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, data_length, (data_length + block_size - 1) / block_size + 1, 'foo')
def testCheckReplaceBzOperation(self):
@@ -616,22 +605,19 @@
# Fail, src extents founds.
op.src_extents = ['bar']
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, data_length, (data_length + block_size - 1) / block_size + 5, 'foo')
# Fail, missing data.
op.src_extents = []
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, None, (data_length + block_size - 1) / block_size, 'foo')
# Fail, too few blocks to justify BZ.
op.src_extents = []
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckReplaceOperation,
+ PayloadError, payload_checker._CheckReplaceOperation,
op, data_length, (data_length + block_size - 1) / block_size, 'foo')
def testCheckMoveOperation_Pass(self):
@@ -658,8 +644,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, 1024, 134, 134, 'foo')
def testCheckMoveOperation_FailInsufficientSrcBlocks(self):
@@ -673,8 +658,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckMoveOperation_FailInsufficientDstBlocks(self):
@@ -688,8 +672,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 5)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckMoveOperation_FailExcessSrcBlocks(self):
@@ -703,16 +686,14 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 5)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
self.AddToMessage(op.src_extents,
self.NewExtentList((1, 4), (12, 2), (1024, 129)))
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckMoveOperation_FailExcessDstBlocks(self):
@@ -726,8 +707,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((16, 128), (512, 7)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckMoveOperation_FailStagnantBlocks(self):
@@ -741,8 +721,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((8, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckMoveOperation_FailZeroStartBlock(self):
@@ -756,8 +735,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((8, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
self.AddToMessage(op.src_extents,
@@ -765,8 +743,7 @@
self.AddToMessage(op.dst_extents,
self.NewExtentList((0, 128), (512, 6)))
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckMoveOperation,
+ PayloadError, payload_checker._CheckMoveOperation,
op, None, 134, 134, 'foo')
def testCheckAnyDiff(self):
@@ -780,14 +757,12 @@
# Fail, missing data blob.
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckAnyDiffOperation,
+ PayloadError, payload_checker._CheckAnyDiffOperation,
op, None, 3, 'foo')
# Fail, too big of a diff blob (unjustified).
self.assertRaises(
- update_payload.PayloadError,
- payload_checker._CheckAnyDiffOperation,
+ PayloadError, payload_checker._CheckAnyDiffOperation,
op, 10000, 2, 'foo')
def testCheckSourceCopyOperation_Pass(self):
@@ -799,15 +774,13 @@
def testCheckSourceCopyOperation_FailContainsData(self):
"""Tests _CheckSourceCopyOperation(); message contains data."""
payload_checker = checker.PayloadChecker(self.MockPayload())
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckSourceCopyOperation,
+ self.assertRaises(PayloadError, payload_checker._CheckSourceCopyOperation,
134, 0, 0, 'foo')
def testCheckSourceCopyOperation_FailBlockCountsMismatch(self):
"""Tests _CheckSourceCopyOperation(); src and dst block totals not equal."""
payload_checker = checker.PayloadChecker(self.MockPayload())
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckSourceCopyOperation,
+ self.assertRaises(PayloadError, payload_checker._CheckSourceCopyOperation,
None, 0, 1, 'foo')
def DoCheckOperationTest(self, op_type_name, is_last, allow_signature,
@@ -942,8 +915,7 @@
old_part_size, new_part_size, prev_data_offset, allow_signature,
blob_hash_counts)
if should_fail:
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckOperation, *args)
+ self.assertRaises(PayloadError, payload_checker._CheckOperation, *args)
else:
self.assertEqual(op.data_length if op.HasField('data_length') else 0,
payload_checker._CheckOperation(*args))
@@ -965,6 +937,7 @@
self.assertEqual(17, len(result))
def DoCheckOperationsTest(self, fail_nonexhaustive_full_update):
+ """Tests _CheckOperations()."""
# Generate a test payload. For this test, we only care about one
# (arbitrary) set of operations, so we'll only be generating kernel and
# test with them.
@@ -996,8 +969,7 @@
args = (payload_checker.payload.manifest.install_operations, report, 'foo',
0, rootfs_part_size, rootfs_part_size, rootfs_part_size, 0, False)
if fail_nonexhaustive_full_update:
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckOperations, *args)
+ self.assertRaises(PayloadError, payload_checker._CheckOperations, *args)
else:
self.assertEqual(rootfs_data_length,
payload_checker._CheckOperations(*args))
@@ -1005,6 +977,7 @@
def DoCheckSignaturesTest(self, fail_empty_sigs_blob, fail_missing_pseudo_op,
fail_mismatched_pseudo_op, fail_sig_missing_fields,
fail_unknown_sig_version, fail_incorrect_sig):
+ """Tests _CheckSignatures()."""
# Generate a test payload. For this test, we only care about the signature
# block and how it relates to the payload hash. Therefore, we're generating
# a random (otherwise useless) payload for this purpose.
@@ -1069,8 +1042,7 @@
fail_unknown_sig_version or fail_incorrect_sig)
args = (report, test_utils._PUBKEY_FILE_NAME)
if should_fail:
- self.assertRaises(update_payload.PayloadError,
- payload_checker._CheckSignatures, *args)
+ self.assertRaises(PayloadError, payload_checker._CheckSignatures, *args)
else:
self.assertIsNone(payload_checker._CheckSignatures(*args))
@@ -1099,7 +1071,7 @@
if should_succeed:
self.assertIsNone(payload_checker._CheckManifestMinorVersion(*args))
else:
- self.assertRaises(update_payload.PayloadError,
+ self.assertRaises(PayloadError,
payload_checker._CheckManifestMinorVersion, *args)
def DoRunTest(self, rootfs_part_size_provided, kernel_part_size_provided,
@@ -1107,6 +1079,7 @@
fail_mismatched_block_size, fail_excess_data,
fail_rootfs_part_size_exceeded,
fail_kernel_part_size_exceeded):
+ """Tests Run()."""
# Generate a test payload. For this test, we generate a full update that
# has sample kernel and rootfs operations. Since most testing is done with
# internal PayloadChecker methods that are tested elsewhere, here we only
@@ -1164,7 +1137,7 @@
'assert_type': 'delta' if fail_wrong_payload_type else 'full',
'block_size': use_block_size}}
if fail_invalid_block_size:
- self.assertRaises(update_payload.PayloadError, _GetPayloadChecker,
+ self.assertRaises(PayloadError, _GetPayloadChecker,
payload_gen.WriteToFileWithData, **kwargs)
else:
payload_checker = _GetPayloadChecker(payload_gen.WriteToFileWithData,
@@ -1178,8 +1151,7 @@
fail_rootfs_part_size_exceeded or
fail_kernel_part_size_exceeded)
if should_fail:
- self.assertRaises(update_payload.PayloadError, payload_checker.Run,
- **kwargs)
+ self.assertRaises(PayloadError, payload_checker.Run, **kwargs)
else:
self.assertIsNone(payload_checker.Run(**kwargs))
diff --git a/scripts/update_payload/common.py b/scripts/update_payload/common.py
index eaf0611..231c504 100644
--- a/scripts/update_payload/common.py
+++ b/scripts/update_payload/common.py
@@ -6,8 +6,8 @@
from __future__ import print_function
-from error import PayloadError
-import update_metadata_pb2
+from update_payload import update_metadata_pb2
+from update_payload.error import PayloadError
#
@@ -35,7 +35,6 @@
class OpType(object):
"""Container for operation type constants."""
_CLASS = update_metadata_pb2.InstallOperation
- # pylint: disable=E1101
REPLACE = _CLASS.REPLACE
REPLACE_BZ = _CLASS.REPLACE_BZ
MOVE = _CLASS.MOVE
diff --git a/scripts/update_payload/format_utils_unittest.py b/scripts/update_payload/format_utils_unittest.py
index 8c5ba8e..7153f9e 100755
--- a/scripts/update_payload/format_utils_unittest.py
+++ b/scripts/update_payload/format_utils_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
#
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -8,10 +8,11 @@
import unittest
-import format_utils
+from update_payload import format_utils
class NumToPercentTest(unittest.TestCase):
+ """ Tests number conversion to percentage format."""
def testHundredPercent(self):
self.assertEqual(format_utils.NumToPercent(1, 1), '100%')
@@ -43,6 +44,7 @@
class BytesToHumanReadableTest(unittest.TestCase):
+ """ Tests number conversion to human readable format."""
def testBaseTwo(self):
self.assertEqual(format_utils.BytesToHumanReadable(0x1000), '4 KiB')
self.assertEqual(format_utils.BytesToHumanReadable(0x400000), '4 MiB')
diff --git a/scripts/update_payload/histogram.py b/scripts/update_payload/histogram.py
index 9916329..f72db61 100644
--- a/scripts/update_payload/histogram.py
+++ b/scripts/update_payload/histogram.py
@@ -6,7 +6,7 @@
from collections import defaultdict
-import format_utils
+from update_payload import format_utils
class Histogram(object):
diff --git a/scripts/update_payload/histogram_unittest.py b/scripts/update_payload/histogram_unittest.py
index 421ff20..643bb32 100755
--- a/scripts/update_payload/histogram_unittest.py
+++ b/scripts/update_payload/histogram_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
#
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -8,11 +8,12 @@
import unittest
-import format_utils
-import histogram
+from update_payload import format_utils
+from update_payload import histogram
class HistogramTest(unittest.TestCase):
+ """ Tests histogram"""
@staticmethod
def AddHumanReadableSize(size):
diff --git a/scripts/update_payload/payload.py b/scripts/update_payload/payload.py
index 9450d02..8e50c1f 100644
--- a/scripts/update_payload/payload.py
+++ b/scripts/update_payload/payload.py
@@ -13,8 +13,8 @@
from update_payload import block_tracer
from update_payload import checker
from update_payload import common
-from update_payload.error import PayloadError
from update_payload import update_metadata_pb2
+from update_payload.error import PayloadError
#
@@ -189,8 +189,6 @@
if self.is_init:
raise PayloadError('payload object already initialized')
- # Initialize hash context.
- # pylint: disable=E1101
self.manifest_hasher = hashlib.sha256()
# Read the file header.
@@ -232,11 +230,9 @@
_DisplayIndentedValue('Build version', image_info.build_version)
if self.manifest.HasField('old_image_info'):
- # pylint: disable=E1101
_DescribeImageInfo('Old Image', self.manifest.old_image_info)
if self.manifest.HasField('new_image_info'):
- # pylint: disable=E1101
_DescribeImageInfo('New Image', self.manifest.new_image_info)
def _AssertInit(self):
diff --git a/scripts/update_payload/test_utils.py b/scripts/update_payload/test_utils.py
index 61a91f5..38712fb 100644
--- a/scripts/update_payload/test_utils.py
+++ b/scripts/update_payload/test_utils.py
@@ -12,9 +12,9 @@
import struct
import subprocess
-import common
-import payload
-import update_metadata_pb2
+from update_payload import common
+from update_payload import payload
+from update_payload import update_metadata_pb2
class TestError(Exception):
@@ -84,7 +84,6 @@
Raises:
TestError if something goes wrong.
"""
- # pylint: disable=E1101
data_sha256_hash = common.SIG_ASN1_HEADER + hashlib.sha256(data).digest()
sign_cmd = ['openssl', 'rsautl', '-sign', '-inkey', privkey_file_name]
try:
@@ -110,8 +109,6 @@
version: signature version (None means do not assign)
data: signature binary data (None means do not assign)
"""
- # Pylint fails to identify a member of the Signatures message.
- # pylint: disable=E1101
sig = self.sigs.signatures.add()
if version is not None:
sig.version = version
@@ -174,11 +171,9 @@
part_hash: the partition hash
"""
if is_kernel:
- # pylint: disable=E1101
part_info = (self.manifest.new_kernel_info if is_new
else self.manifest.old_kernel_info)
else:
- # pylint: disable=E1101
part_info = (self.manifest.new_rootfs_info if is_new
else self.manifest.old_rootfs_info)
_SetMsgField(part_info, 'size', part_size)
@@ -188,7 +183,6 @@
data_length=None, src_extents=None, src_length=None,
dst_extents=None, dst_length=None, data_sha256_hash=None):
"""Adds an InstallOperation entry."""
- # pylint: disable=E1101
operations = (self.manifest.kernel_install_operations if is_kernel
else self.manifest.install_operations)
@@ -293,7 +287,6 @@
data_offset = data_length = data_sha256_hash = None
if data_blob is not None:
if do_hash_data_blob:
- # pylint: disable=E1101
data_sha256_hash = hashlib.sha256(data_blob).digest()
data_length, data_offset = self.AddData(data_blob)