Formatting: Format all python code with black.
This CL is probably not what you're looking for, it's only
automated formatting. Ignore it with
`git blame --ignore-rev <revision>` for this commit.
BUG=b:233893248
TEST=CQ
Change-Id: I66591d7a738d241aed3290138c0f68065ab10a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3879174
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
diff --git a/scripts/autotest_quickmerge_unittest.py b/scripts/autotest_quickmerge_unittest.py
index 5487a89..0e14356 100644
--- a/scripts/autotest_quickmerge_unittest.py
+++ b/scripts/autotest_quickmerge_unittest.py
@@ -50,143 +50,179 @@
cd+++++++++ client/site_tests/power_Thermal/a/b/c/
>f+++++++++ client/site_tests/power_Thermal/a/b/c/d.py"""
-RSYNC_TEST_DESTINATION_PATH = '/foo/bar/'
+RSYNC_TEST_DESTINATION_PATH = "/foo/bar/"
-TEST_PACKAGE_CP = 'a_cute/little_puppy'
-TEST_PACKAGE_CPV = 'a_cute/little_puppy-3.14159'
-TEST_PACKAGE_C = 'a_cute'
-TEST_PACKAGE_PV = 'little_puppy-3.14159'
-TEST_PORTAGE_ROOT = '/bib/bob/'
+TEST_PACKAGE_CP = "a_cute/little_puppy"
+TEST_PACKAGE_CPV = "a_cute/little_puppy-3.14159"
+TEST_PACKAGE_C = "a_cute"
+TEST_PACKAGE_PV = "little_puppy-3.14159"
+TEST_PORTAGE_ROOT = "/bib/bob/"
TEST_PACKAGE_OLDCONTENTS = {
- u'/by/the/prickling/of/my/thumbs': (u'obj', '1234', '4321'),
- u'/something/wicked/this/way/comes': (u'dir',)
+ "/by/the/prickling/of/my/thumbs": ("obj", "1234", "4321"),
+ "/something/wicked/this/way/comes": ("dir",),
}
class ItemizeChangesFromRsyncOutput(cros_test_lib.TestCase):
- """Test autotest_quickmerge.ItemizeChangesFromRsyncOutput."""
+ """Test autotest_quickmerge.ItemizeChangesFromRsyncOutput."""
- def testItemizeChangesFromRsyncOutput(self):
- """Test that rsync output parser returns correct FileMutations."""
- expected_new = set(
- [('>f+++++++++', '/foo/bar/new_file'),
- ('>f+++++++++', '/foo/bar/directory_a/new_file_in_directory'),
- ('cL+++++++++', '/foo/bar/new_symlink')])
+ def testItemizeChangesFromRsyncOutput(self):
+ """Test that rsync output parser returns correct FileMutations."""
+ expected_new = set(
+ [
+ (">f+++++++++", "/foo/bar/new_file"),
+ (">f+++++++++", "/foo/bar/directory_a/new_file_in_directory"),
+ ("cL+++++++++", "/foo/bar/new_symlink"),
+ ]
+ )
- expected_mod = set(
- [('>f..t......', '/foo/bar/touched file with spaces'),
- ('>f..t......', '/foo/bar/touched_file'),
- ('>f.st......', '/foo/bar/modified_contents_file'),
- ('.f...p.....', '/foo/bar/modified_permissions_file'),
- ('.f....o....', '/foo/bar/modified_owner_file'),
- ('>f..t......', '/foo/bar/directory_a/touched_file_in_directory')])
+ expected_mod = set(
+ [
+ (">f..t......", "/foo/bar/touched file with spaces"),
+ (">f..t......", "/foo/bar/touched_file"),
+ (">f.st......", "/foo/bar/modified_contents_file"),
+ (".f...p.....", "/foo/bar/modified_permissions_file"),
+ (".f....o....", "/foo/bar/modified_owner_file"),
+ (
+ ">f..t......",
+ "/foo/bar/directory_a/touched_file_in_directory",
+ ),
+ ]
+ )
- expected_dir = set([('cd+++++++++', '/foo/bar/new_empty_directory/')])
+ expected_dir = set([("cd+++++++++", "/foo/bar/new_empty_directory/")])
- report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
- RSYNC_TEST_OUTPUT, RSYNC_TEST_DESTINATION_PATH)
+ report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
+ RSYNC_TEST_OUTPUT, RSYNC_TEST_DESTINATION_PATH
+ )
- self.assertEqual(expected_new, set(report.new_files))
- self.assertEqual(expected_mod, set(report.modified_files))
- self.assertEqual(expected_dir, set(report.new_directories))
+ self.assertEqual(expected_new, set(report.new_files))
+ self.assertEqual(expected_mod, set(report.modified_files))
+ self.assertEqual(expected_dir, set(report.new_directories))
class PackageNameParsingTest(cros_test_lib.TestCase):
- """Test autotest_quickmerge.GetStalePackageNames."""
+ """Test autotest_quickmerge.GetStalePackageNames."""
- def testGetStalePackageNames(self):
- autotest_sysroot = '/an/arbitrary/path/'
- change_report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
- RSYNC_TEST_OUTPUT_FOR_PACKAGE_UPDATE, autotest_sysroot)
- package_matches = autotest_quickmerge.GetStalePackageNames(
- change_report.modified_files + change_report.new_files,
- autotest_sysroot)
- expected_set = set(['factory_Leds', 'login_UserPolicyKeys',
- 'platform_Cryptohome', 'power_Thermal'])
- self.assertEqual(set(package_matches), expected_set)
+ def testGetStalePackageNames(self):
+ autotest_sysroot = "/an/arbitrary/path/"
+ change_report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
+ RSYNC_TEST_OUTPUT_FOR_PACKAGE_UPDATE, autotest_sysroot
+ )
+ package_matches = autotest_quickmerge.GetStalePackageNames(
+ change_report.modified_files + change_report.new_files,
+ autotest_sysroot,
+ )
+ expected_set = set(
+ [
+ "factory_Leds",
+ "login_UserPolicyKeys",
+ "platform_Cryptohome",
+ "power_Thermal",
+ ]
+ )
+ self.assertEqual(set(package_matches), expected_set)
class RsyncCommandTest(cros_test_lib.RunCommandTestCase):
- """Test autotest_quickmerge.RsyncQuickmerge."""
+ """Test autotest_quickmerge.RsyncQuickmerge."""
- def testRsyncQuickmergeCommand(self):
- """Test that RsyncQuickMerge makes correct call to sudo_run"""
- include_file_name = 'an_include_file_name'
- source_path = 'a_source_path'
- sysroot_path = 'a_sysroot_path'
+ def testRsyncQuickmergeCommand(self):
+ """Test that RsyncQuickMerge makes correct call to sudo_run"""
+ include_file_name = "an_include_file_name"
+ source_path = "a_source_path"
+ sysroot_path = "a_sysroot_path"
- expected_command = ['rsync', '-a', '-n', '-u', '-i',
- '--exclude=**.pyc', '--exclude=**.pyo',
- '--exclude=** -> *',
- '--include-from=%s' % include_file_name,
- '--exclude=*',
- source_path,
- sysroot_path]
+ expected_command = [
+ "rsync",
+ "-a",
+ "-n",
+ "-u",
+ "-i",
+ "--exclude=**.pyc",
+ "--exclude=**.pyo",
+ "--exclude=** -> *",
+ "--include-from=%s" % include_file_name,
+ "--exclude=*",
+ source_path,
+ sysroot_path,
+ ]
- autotest_quickmerge.RsyncQuickmerge(source_path, sysroot_path,
- include_file_name,
- pretend=True,
- overwrite=False)
+ autotest_quickmerge.RsyncQuickmerge(
+ source_path,
+ sysroot_path,
+ include_file_name,
+ pretend=True,
+ overwrite=False,
+ )
- self.assertCommandContains(expected_command)
+ self.assertCommandContains(expected_command)
class PortageManipulationsTest(cros_test_lib.MockTestCase):
- """Test usage of autotest_quickmerge.portage."""
+ """Test usage of autotest_quickmerge.portage."""
- def testUpdatePackageContents(self):
- """Test that UpdatePackageContents makes the correct calls to portage."""
- autotest_quickmerge.portage = mock.MagicMock()
- portage = autotest_quickmerge.portage
+ def testUpdatePackageContents(self):
+ """Test that UpdatePackageContents makes the correct calls to portage."""
+ autotest_quickmerge.portage = mock.MagicMock()
+ portage = autotest_quickmerge.portage
- portage.root = TEST_PORTAGE_ROOT
+ portage.root = TEST_PORTAGE_ROOT
- mock_vartree = mock.MagicMock()
- mock_vartree.settings = {'an arbitrary' : 'dictionary'}
- mock_tree = {TEST_PORTAGE_ROOT : {'vartree' : mock_vartree}}
- portage.create_trees.return_value = mock_tree
+ mock_vartree = mock.MagicMock()
+ mock_vartree.settings = {"an arbitrary": "dictionary"}
+ mock_tree = {TEST_PORTAGE_ROOT: {"vartree": mock_vartree}}
+ portage.create_trees.return_value = mock_tree
- mock_vartree.dbapi = mock.MagicMock()
- mock_vartree.dbapi.cp_list.return_value = [TEST_PACKAGE_CPV]
+ mock_vartree.dbapi = mock.MagicMock()
+ mock_vartree.dbapi.cp_list.return_value = [TEST_PACKAGE_CPV]
- mock_package = mock.MagicMock()
- portage.dblink.return_value = mock_package # pylint: disable=no-member
- mock_package.getcontents.return_value = TEST_PACKAGE_OLDCONTENTS
+ mock_package = mock.MagicMock()
+ portage.dblink.return_value = mock_package # pylint: disable=no-member
+ mock_package.getcontents.return_value = TEST_PACKAGE_OLDCONTENTS
- EXPECTED_NEW_ENTRIES = {
- '/foo/bar/new_empty_directory': (u'dir',),
- '/foo/bar/directory_a/new_file_in_directory': (u'obj', '0', '0'),
- '/foo/bar/new_file': (u'obj', '0', '0'),
- '/foo/bar/new_symlink': (u'obj', '0', '0')
- }
- RESULT_DICIONARY = TEST_PACKAGE_OLDCONTENTS.copy()
- RESULT_DICIONARY.update(EXPECTED_NEW_ENTRIES)
+ EXPECTED_NEW_ENTRIES = {
+ "/foo/bar/new_empty_directory": ("dir",),
+ "/foo/bar/directory_a/new_file_in_directory": ("obj", "0", "0"),
+ "/foo/bar/new_file": ("obj", "0", "0"),
+ "/foo/bar/new_symlink": ("obj", "0", "0"),
+ }
+ RESULT_DICIONARY = TEST_PACKAGE_OLDCONTENTS.copy()
+ RESULT_DICIONARY.update(EXPECTED_NEW_ENTRIES)
- mock_vartree.dbapi.writeContentsToContentsFile(mock_package,
- RESULT_DICIONARY)
+ mock_vartree.dbapi.writeContentsToContentsFile(
+ mock_package, RESULT_DICIONARY
+ )
- change_report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
- RSYNC_TEST_OUTPUT, RSYNC_TEST_DESTINATION_PATH)
- autotest_quickmerge.UpdatePackageContents(change_report, TEST_PACKAGE_CP,
- TEST_PORTAGE_ROOT)
+ change_report = autotest_quickmerge.ItemizeChangesFromRsyncOutput(
+ RSYNC_TEST_OUTPUT, RSYNC_TEST_DESTINATION_PATH
+ )
+ autotest_quickmerge.UpdatePackageContents(
+ change_report, TEST_PACKAGE_CP, TEST_PORTAGE_ROOT
+ )
class PortageAPITest(cros_test_lib.TestCase):
- """Ensures that required portage API exists."""
+ """Ensures that required portage API exists."""
- def runTest(self):
- try:
- import portage
- except ImportError:
- self.skipTest('Portage not available in test environment. Re-run test '
- 'in chroot.')
- try:
- # pylint: disable=no-member
- f = portage.vardbapi.writeContentsToContentsFile
- except AttributeError:
- self.fail('Required writeContentsToContentsFile function does '
- 'not exist.')
+ def runTest(self):
+ try:
+ import portage
+ except ImportError:
+ self.skipTest(
+ "Portage not available in test environment. Re-run test "
+ "in chroot."
+ )
+ try:
+ # pylint: disable=no-member
+ f = portage.vardbapi.writeContentsToContentsFile
+ except AttributeError:
+ self.fail(
+ "Required writeContentsToContentsFile function does "
+ "not exist."
+ )
- self.assertTrue(
- callable(f),
- msg='Required writeContentsToContentsFile is not a function.')
+ self.assertTrue(
+ callable(f),
+ msg="Required writeContentsToContentsFile is not a function.",
+ )