Skip to content

Commit e1ba8bc

Browse files
committed
fit the py3.5 sytnax and flake8 format
1 parent abd4aa2 commit e1ba8bc

File tree

2 files changed

+94
-40
lines changed

2 files changed

+94
-40
lines changed

providers/base/bin/check_secure_boot_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from enum import Enum
6161

6262
# Global logger instance
63-
logger: "SecureBootLogger" = None
63+
logger = None
6464

6565

6666
class SecureBootLogger:

providers/base/tests/test_check_secure_boot_state.py

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,22 @@ def test_find_fit_images_with_boot_kernel(self, mock_get_boot_kernel):
780780
"._get_boot_kernel_path"
781781
)
782782
@patch(
783-
"check_secure_boot_state.FITImageSecureBootChecker"
784-
"._get_snap_kernel_patterns"
783+
(
784+
"check_secure_boot_state.FITImageSecureBootChecker."
785+
"_get_snap_kernel_patterns"
786+
)
785787
)
786788
@patch(
787-
"check_secure_boot_state.FITImageSecureBootChecker"
788-
"._build_search_patterns"
789+
(
790+
"check_secure_boot_state.FITImageSecureBootChecker."
791+
"_build_search_patterns"
792+
)
789793
)
790794
@patch(
791-
"check_secure_boot_state.FITImageSecureBootChecker"
792-
"._find_files_by_patterns"
795+
(
796+
"check_secure_boot_state.FITImageSecureBootChecker."
797+
"_find_files_by_patterns"
798+
)
793799
)
794800
def test_find_fit_images_core_variant(
795801
self,
@@ -809,26 +815,28 @@ def test_find_fit_images_core_variant(
809815
images = self.checker._find_fit_images()
810816

811817
self.assertEqual(images, ["/snap/test/current/kernel.img"])
812-
mock_get_patterns.assert_called_once()
813-
mock_build_patterns.assert_called_once_with(
814-
["/snap/*/current/kernel.img"]
815-
)
818+
patterns = ["/snap/*/current/kernel.img"]
819+
mock_build_patterns.assert_called_once_with(patterns)
816820

817821
@patch(
818822
"check_secure_boot_state.FITImageSecureBootChecker"
819823
"._get_boot_kernel_path"
820824
)
821825
@patch(
822-
"check_secure_boot_state.FITImageSecureBootChecker"
823-
"._get_classic_fit_patterns"
826+
"check_secure_boot_state.FITImageSecureBootChecker."
827+
"_get_classic_fit_patterns"
824828
)
825829
@patch(
826-
"check_secure_boot_state.FITImageSecureBootChecker"
827-
"._build_search_patterns"
830+
(
831+
"check_secure_boot_state.FITImageSecureBootChecker."
832+
"_build_search_patterns"
833+
)
828834
)
829835
@patch(
830-
"check_secure_boot_state.FITImageSecureBootChecker"
831-
"._find_files_by_patterns"
836+
(
837+
"check_secure_boot_state.FITImageSecureBootChecker."
838+
"_find_files_by_patterns"
839+
)
832840
)
833841
def test_find_fit_images_classic_variant(
834842
self,
@@ -848,20 +856,32 @@ def test_find_fit_images_classic_variant(
848856
images = self.checker._find_fit_images()
849857

850858
self.assertEqual(images, ["/boot/vmlinuz-5.4.0"])
851-
mock_get_patterns.assert_called_once()
852-
mock_build_patterns.assert_called_once_with(["/boot/*.img"])
859+
patterns = ["/boot/*.img"]
860+
mock_build_patterns.assert_called_once_with(patterns)
853861

854862
@patch(
855-
"check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
863+
(
864+
"check_secure_boot_state.FITImageSecureBootChecker."
865+
"_get_boot_kernel_path"
866+
)
856867
)
857868
@patch(
858-
"check_secure_boot_state.FITImageSecureBootChecker._get_snap_kernel_patterns"
869+
(
870+
"check_secure_boot_state.FITImageSecureBootChecker."
871+
"_get_snap_kernel_patterns"
872+
)
859873
)
860874
@patch(
861-
"check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
875+
(
876+
"check_secure_boot_state.FITImageSecureBootChecker."
877+
"_build_search_patterns"
878+
)
862879
)
863880
@patch(
864-
"check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
881+
(
882+
"check_secure_boot_state.FITImageSecureBootChecker."
883+
"_find_files_by_patterns"
884+
)
865885
)
866886
def test_find_fit_images_no_images_found(
867887
self,
@@ -883,16 +903,28 @@ def test_find_fit_images_no_images_found(
883903
self.assertEqual(images, [])
884904

885905
@patch(
886-
"check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
906+
(
907+
"check_secure_boot_state.FITImageSecureBootChecker."
908+
"_get_boot_kernel_path"
909+
)
887910
)
888911
@patch(
889-
"check_secure_boot_state.FITImageSecureBootChecker._get_snap_kernel_patterns"
912+
(
913+
"check_secure_boot_state.FITImageSecureBootChecker."
914+
"_get_snap_kernel_patterns"
915+
)
890916
)
891917
@patch(
892-
"check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
918+
(
919+
"check_secure_boot_state.FITImageSecureBootChecker."
920+
"_build_search_patterns"
921+
)
893922
)
894923
@patch(
895-
"check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
924+
(
925+
"check_secure_boot_state.FITImageSecureBootChecker."
926+
"_find_files_by_patterns"
927+
)
896928
)
897929
def test_find_fit_images_with_hostfs_prefix(
898930
self,
@@ -925,16 +957,26 @@ def test_find_fit_images_with_hostfs_prefix(
925957
)
926958

927959
@patch(
928-
"check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
960+
(
961+
"check_secure_boot_state.FITImageSecureBootChecker."
962+
"_get_boot_kernel_path"
963+
)
929964
)
930965
@patch(
931-
"check_secure_boot_state.FITImageSecureBootChecker._get_classic_fit_patterns"
966+
"check_secure_boot_state.FITImageSecureBootChecker."
967+
"_get_classic_fit_patterns"
932968
)
933969
@patch(
934-
"check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
970+
(
971+
"check_secure_boot_state.FITImageSecureBootChecker."
972+
"_build_search_patterns"
973+
)
935974
)
936975
@patch(
937-
"check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
976+
(
977+
"check_secure_boot_state.FITImageSecureBootChecker."
978+
"_find_files_by_patterns"
979+
)
938980
)
939981
def test_find_fit_images_unknown_variant(
940982
self,
@@ -955,7 +997,7 @@ def test_find_fit_images_unknown_variant(
955997

956998
self.assertEqual(images, ["/boot/vmlinuz-5.4.0"])
957999
# Should default to classic patterns for unknown variant
958-
mock_get_patterns.assert_called_once()
1000+
self.assertEqual(mock_get_patterns.call_count, 1)
9591001

9601002

9611003
class TestUtilityFunctions(unittest.TestCase):
@@ -977,7 +1019,7 @@ def test_log_secure_boot_info(self):
9771019
error_msg = None
9781020
checker_name = "Test Checker"
9791021
log_secure_boot_info(state, error_msg, checker_name)
980-
self.mock_logger.info.assert_called()
1022+
self.mock_logger.info.assert_called_with("Current state: enabled")
9811023

9821024
def test_log_secure_boot_info_with_error(self):
9831025
"""Test secure boot info logging with error."""
@@ -994,7 +1036,9 @@ def test_check_secure_boot_result_processing_error(self):
9941036
check_mode = "enable"
9951037
result = check_secure_boot_result(state, error_msg, check_mode)
9961038
self.assertEqual(result, 1)
997-
self.mock_logger.error.assert_called()
1039+
self.mock_logger.error.assert_called_with(
1040+
"FAIL: Cannot determine if secure boot is enable - Test error"
1041+
)
9981042

9991043
def test_check_secure_boot_result_processing_error_no_mode(self):
10001044
"""Test secure boot result checking - processing error without mode."""
@@ -1003,7 +1047,9 @@ def test_check_secure_boot_result_processing_error_no_mode(self):
10031047
check_mode = None
10041048
result = check_secure_boot_result(state, error_msg, check_mode)
10051049
self.assertEqual(result, 1)
1006-
self.mock_logger.error.assert_called()
1050+
self.mock_logger.error.assert_called_with(
1051+
"FAIL: Cannot determine secure boot state - Test error"
1052+
)
10071053

10081054
def test_check_secure_boot_result_enable_success(self):
10091055
"""Test secure boot result checking - enable success."""
@@ -1012,7 +1058,9 @@ def test_check_secure_boot_result_enable_success(self):
10121058
check_mode = "enable"
10131059
result = check_secure_boot_result(state, error_msg, check_mode)
10141060
self.assertEqual(result, 0)
1015-
self.mock_logger.info.assert_called()
1061+
self.mock_logger.info.assert_called_with(
1062+
"PASS: Secure boot is enabled"
1063+
)
10161064

10171065
def test_check_secure_boot_result_enable_failure(self):
10181066
"""Test secure boot result checking - enable failure."""
@@ -1021,7 +1069,9 @@ def test_check_secure_boot_result_enable_failure(self):
10211069
check_mode = "enable"
10221070
result = check_secure_boot_result(state, error_msg, check_mode)
10231071
self.assertEqual(result, 1)
1024-
self.mock_logger.log_failure.assert_called()
1072+
self.mock_logger.log_failure.assert_called_with(
1073+
"enable", SecureBootState.DISABLED, None
1074+
)
10251075

10261076
def test_check_secure_boot_result_disabled_success(self):
10271077
"""Test secure boot result checking - disabled success."""
@@ -1030,7 +1080,9 @@ def test_check_secure_boot_result_disabled_success(self):
10301080
check_mode = "disabled"
10311081
result = check_secure_boot_result(state, error_msg, check_mode)
10321082
self.assertEqual(result, 0)
1033-
self.mock_logger.info.assert_called()
1083+
self.mock_logger.info.assert_called_with(
1084+
"PASS: Secure boot is disabled"
1085+
)
10341086

10351087
def test_check_secure_boot_result_disabled_failure(self):
10361088
"""Test secure boot result checking - disabled failure."""
@@ -1039,7 +1091,9 @@ def test_check_secure_boot_result_disabled_failure(self):
10391091
check_mode = "disabled"
10401092
result = check_secure_boot_result(state, error_msg, check_mode)
10411093
self.assertEqual(result, 1)
1042-
self.mock_logger.log_failure.assert_called()
1094+
self.mock_logger.log_failure.assert_called_with(
1095+
"disabled", SecureBootState.ENABLED, None
1096+
)
10431097

10441098
def test_check_secure_boot_result_no_mode(self):
10451099
"""Test secure boot result checking - no mode specified."""
@@ -1341,7 +1395,7 @@ def test_main_unexpected_error(
13411395
main()
13421396

13431397
mock_exit.assert_called_with(1)
1344-
mock_traceback.assert_called_once()
1398+
mock_traceback.assert_called_with()
13451399

13461400
@patch("sys.exit")
13471401
@patch("check_secure_boot_state.create_checker")

0 commit comments

Comments
 (0)