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/api/controller/firmware_unittest.py b/api/controller/firmware_unittest.py
index e84dbb9..1049c5a 100644
--- a/api/controller/firmware_unittest.py
+++ b/api/controller/firmware_unittest.py
@@ -17,82 +17,105 @@
from chromite.lib import cros_test_lib
-class BuildAllFirmwareTestCase(cros_test_lib.MockTempDirTestCase,
- api_config.ApiConfigMixin):
- """BuildAllFirmware tests."""
+class BuildAllFirmwareTestCase(
+ cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin
+):
+ """BuildAllFirmware tests."""
- def setUp(self):
- self.chroot_path = '/path/to/chroot'
- self.cros_build_run_patch = self.PatchObject(
- cros_build_lib,
- 'run',
- return_value=cros_build_lib.CompletedProcess(returncode=0))
+ def setUp(self):
+ self.chroot_path = "/path/to/chroot"
+ self.cros_build_run_patch = self.PatchObject(
+ cros_build_lib,
+ "run",
+ return_value=cros_build_lib.CompletedProcess(returncode=0),
+ )
- def _GetInput(self,
- chroot_path=None,
- fw_location=common_pb2.PLATFORM_EC,
- code_coverage=False):
- """Helper for creating input message."""
- proto = firmware_pb2.BuildAllFirmwareRequest(
- firmware_location=fw_location,
- chroot={'path': chroot_path},
- code_coverage=code_coverage)
- return proto
+ def _GetInput(
+ self,
+ chroot_path=None,
+ fw_location=common_pb2.PLATFORM_EC,
+ code_coverage=False,
+ ):
+ """Helper for creating input message."""
+ proto = firmware_pb2.BuildAllFirmwareRequest(
+ firmware_location=fw_location,
+ chroot={"path": chroot_path},
+ code_coverage=code_coverage,
+ )
+ return proto
- def testBuildAllFirmware(self):
- """Test invocation of endpoint by verifying call to cros_build_lib.run."""
- for fw_loc in common_pb2.FwLocation.values():
- fw_path = firmware.get_fw_loc(fw_loc)
- if not fw_path:
- continue
- request = self._GetInput(chroot_path=self.chroot_path,
- fw_location=fw_loc,
- code_coverage=True)
- # TODO(mmortensen): Consider refactoring firmware._call_entry code
- # (putting the parsing of the output file in a function) so that we don't
- # have to mock something as generic as 'json_format.Parse' to avoid an
- # error on parsing an empty(due to mock call) file.
- json_format_patch = self.PatchObject(json_format, 'Parse')
- response = firmware_pb2.BuildAllFirmwareResponse()
- # Call the method under test.
- firmware.BuildAllFirmware(request, response, self.api_config)
- # Because we mock out the function, we verify that it is called as we
- # expect it to be called.
- called_function = os.path.join(constants.SOURCE_ROOT,
- fw_path, 'firmware_builder.py')
- self.cros_build_run_patch.assert_called_with(
- [called_function, '--metrics', mock.ANY, '--code-coverage', 'build'],
- check=False)
- # Verify that we try to parse the metrics file.
- json_format_patch.assert_called()
+ def testBuildAllFirmware(self):
+ """Test invocation of endpoint by verifying call to cros_build_lib.run."""
+ for fw_loc in common_pb2.FwLocation.values():
+ fw_path = firmware.get_fw_loc(fw_loc)
+ if not fw_path:
+ continue
+ request = self._GetInput(
+ chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True,
+ )
+ # TODO(mmortensen): Consider refactoring firmware._call_entry code
+ # (putting the parsing of the output file in a function) so that we don't
+ # have to mock something as generic as 'json_format.Parse' to avoid an
+ # error on parsing an empty(due to mock call) file.
+ json_format_patch = self.PatchObject(json_format, "Parse")
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ # Call the method under test.
+ firmware.BuildAllFirmware(request, response, self.api_config)
+ # Because we mock out the function, we verify that it is called as we
+ # expect it to be called.
+ called_function = os.path.join(
+ constants.SOURCE_ROOT, fw_path, "firmware_builder.py"
+ )
+ self.cros_build_run_patch.assert_called_with(
+ [
+ called_function,
+ "--metrics",
+ mock.ANY,
+ "--code-coverage",
+ "build",
+ ],
+ check=False,
+ )
+ # Verify that we try to parse the metrics file.
+ json_format_patch.assert_called()
- def testValidateOnly(self):
- """Sanity check that a validate only call does not execute any logic."""
- for fw_loc in common_pb2.FwLocation.values():
- if not firmware.get_fw_loc(fw_loc):
- continue
- request = self._GetInput(chroot_path=self.chroot_path,
- fw_location=fw_loc,
- code_coverage=True)
- response = firmware_pb2.BuildAllFirmwareResponse()
- firmware.BuildAllFirmware(request, response, self.validate_only_config)
- self.cros_build_run_patch.assert_not_called()
+ def testValidateOnly(self):
+ """Sanity check that a validate only call does not execute any logic."""
+ for fw_loc in common_pb2.FwLocation.values():
+ if not firmware.get_fw_loc(fw_loc):
+ continue
+ request = self._GetInput(
+ chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True,
+ )
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ firmware.BuildAllFirmware(
+ request, response, self.validate_only_config
+ )
+ self.cros_build_run_patch.assert_not_called()
- def testMockCall(self):
- """Test that a mock call does not execute logic, returns mocked value."""
- for fw_loc in common_pb2.FwLocation.values():
- if not firmware.get_fw_loc(fw_loc):
- continue
- request = self._GetInput(chroot_path=self.chroot_path,
- fw_location=fw_loc,
- code_coverage=True)
- response = firmware_pb2.BuildAllFirmwareResponse()
- firmware.BuildAllFirmware(request, response, self.mock_call_config)
- self.cros_build_run_patch.assert_not_called()
- self.assertEqual(len(response.metrics.value), 1)
- self.assertEqual(response.metrics.value[0].target_name, 'foo')
- self.assertEqual(response.metrics.value[0].platform_name, 'bar')
- self.assertEqual(len(response.metrics.value[0].fw_section), 1)
- self.assertEqual(response.metrics.value[0].fw_section[0].region, 'EC_RO')
- self.assertEqual(response.metrics.value[0].fw_section[0].used, 100)
- self.assertEqual(response.metrics.value[0].fw_section[0].total, 150)
+ def testMockCall(self):
+ """Test that a mock call does not execute logic, returns mocked value."""
+ for fw_loc in common_pb2.FwLocation.values():
+ if not firmware.get_fw_loc(fw_loc):
+ continue
+ request = self._GetInput(
+ chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True,
+ )
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ firmware.BuildAllFirmware(request, response, self.mock_call_config)
+ self.cros_build_run_patch.assert_not_called()
+ self.assertEqual(len(response.metrics.value), 1)
+ self.assertEqual(response.metrics.value[0].target_name, "foo")
+ self.assertEqual(response.metrics.value[0].platform_name, "bar")
+ self.assertEqual(len(response.metrics.value[0].fw_section), 1)
+ self.assertEqual(
+ response.metrics.value[0].fw_section[0].region, "EC_RO"
+ )
+ self.assertEqual(response.metrics.value[0].fw_section[0].used, 100)
+ self.assertEqual(response.metrics.value[0].fw_section[0].total, 150)