Skip to content

Commit ab61e86

Browse files
krisroweanaik91
authored andcommitted
fix: flake8 linting issues
1 parent ee9eaa4 commit ab61e86

File tree

1 file changed

+67
-21
lines changed

1 file changed

+67
-21
lines changed

tests/test_qualification_report.py

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,9 @@ def test_close(self):
889889
self.mock_workbook.close.assert_called_once()
890890

891891
@patch('qualification_report.anti_patterns_mapping')
892-
def test_report_anti_patterns_with_none_values(self, mock_mapping):
892+
def test_report_anti_patterns_missing_attrs(self, mock_mapping):
893893
"""
894-
Test report_anti_patterns method with None values (missing XML attributes).
894+
Test report_anti_patterns with missing XML attributes (None values).
895895
"""
896896
mock_mapping.__getitem__.side_effect = (
897897
self.anti_patterns_mapping.__getitem__)
@@ -918,15 +918,58 @@ def test_report_anti_patterns_with_none_values(self, mock_mapping):
918918
mock_sheet = Mock()
919919
self.mock_workbook.add_worksheet.return_value = mock_sheet
920920
report.report_anti_patterns()
921-
922-
# Verify the complex lines with multiple invocations work with None values
923-
mock_sheet.write.assert_any_call(1, 3, "None") # _safe_value(None) returns "None"
924-
mock_sheet.write.assert_any_call(1, 4, "None") # _safe_value(None) returns "None"
921+
922+
# Verify complex lines work with None values
923+
mock_sheet.write.assert_any_call(1, 3, "None")
924+
mock_sheet.write.assert_any_call(1, 4, "None")
925+
926+
@patch('qualification_report.anti_patterns_mapping')
927+
def test_report_anti_patterns_corrupted_data(self, mock_mapping):
928+
"""
929+
Test report_anti_patterns with corrupted data (dict values).
930+
"""
931+
mock_mapping.__getitem__.side_effect = (
932+
self.anti_patterns_mapping.__getitem__)
933+
self.export_data['proxy_dependency_map'] = {
934+
'proxy1': {
935+
'qualification': {
936+
'AntiPatternQuota': {
937+
'policy1': {
938+
'distributed': {
939+
'nested_key': 'nested_value',
940+
'another_key': 123
941+
},
942+
'Synchronous': 'true' # Normal string value
943+
}
944+
}
945+
}
946+
}
947+
}
948+
report = QualificationReport(
949+
'test.xlsx',
950+
self.export_data,
951+
self.topology_mapping,
952+
self.cfg,
953+
self.backend_cfg,
954+
self.org_name
955+
)
956+
mock_sheet = Mock()
957+
self.mock_workbook.add_worksheet.return_value = mock_sheet
958+
report.report_anti_patterns()
959+
960+
# Verify complex lines handle corrupted data
961+
expected_distributed = str({
962+
'nested_key': 'nested_value',
963+
'another_key': 123
964+
})
965+
mock_sheet.write.assert_any_call(1, 3, expected_distributed)
966+
mock_sheet.write.assert_any_call(1, 4, 'true')
925967

926968
@patch('qualification_report.anti_patterns_mapping')
927969
def test_report_anti_patterns_with_boolean_values(self, mock_mapping):
928970
"""
929-
Test report_anti_patterns method with boolean values (XML parser conversion).
971+
Test report_anti_patterns method with boolean values
972+
(XML parser conversion).
930973
"""
931974
mock_mapping.__getitem__.side_effect = (
932975
self.anti_patterns_mapping.__getitem__)
@@ -935,8 +978,8 @@ def test_report_anti_patterns_with_boolean_values(self, mock_mapping):
935978
'qualification': {
936979
'AntiPatternQuota': {
937980
'policy1': {
938-
'distributed': True, # XML parser converted "true" to boolean
939-
'Synchronous': False # XML parser converted "false" to boolean
981+
'distributed': True, # XML "true" to boolean
982+
'Synchronous': False # XML "false" to boolean
940983
}
941984
}
942985
}
@@ -953,15 +996,16 @@ def test_report_anti_patterns_with_boolean_values(self, mock_mapping):
953996
mock_sheet = Mock()
954997
self.mock_workbook.add_worksheet.return_value = mock_sheet
955998
report.report_anti_patterns()
956-
999+
9571000
# Verify the complex lines with multiple invocations work with booleans
958-
mock_sheet.write.assert_any_call(1, 3, True) # _safe_value(True) returns True
959-
mock_sheet.write.assert_any_call(1, 4, False) # _safe_value(False) returns False
1001+
mock_sheet.write.assert_any_call(1, 3, True) # _safe_value(True)
1002+
mock_sheet.write.assert_any_call(1, 4, False) # _safe_value(False)
9601003

9611004
@patch('qualification_report.anti_patterns_mapping')
9621005
def test_report_anti_patterns_with_integer_values(self, mock_mapping):
9631006
"""
964-
Test report_anti_patterns method with integer values (XML parser conversion).
1007+
Test report_anti_patterns method with integer values
1008+
(XML parser conversion).
9651009
"""
9661010
mock_mapping.__getitem__.side_effect = (
9671011
self.anti_patterns_mapping.__getitem__)
@@ -970,8 +1014,8 @@ def test_report_anti_patterns_with_integer_values(self, mock_mapping):
9701014
'qualification': {
9711015
'AntiPatternQuota': {
9721016
'policy1': {
973-
'distributed': 1, # XML parser converted "true" to 1
974-
'Synchronous': 0 # XML parser converted "false" to 0
1017+
'distributed': 1, # XML parser "true" to 1
1018+
'Synchronous': 0 # XML parser "false" to 0
9751019
}
9761020
}
9771021
}
@@ -988,15 +1032,16 @@ def test_report_anti_patterns_with_integer_values(self, mock_mapping):
9881032
mock_sheet = Mock()
9891033
self.mock_workbook.add_worksheet.return_value = mock_sheet
9901034
report.report_anti_patterns()
991-
1035+
9921036
# Verify the complex lines with multiple invocations work with integers
993-
mock_sheet.write.assert_any_call(1, 3, 1) # _safe_value(1) returns 1
994-
mock_sheet.write.assert_any_call(1, 4, 0) # _safe_value(0) returns 0
1037+
mock_sheet.write.assert_any_call(1, 3, 1) # _safe_value(1)
1038+
mock_sheet.write.assert_any_call(1, 4, 0) # _safe_value(0)
9951039

9961040
@patch('qualification_report.anti_patterns_mapping')
9971041
def test_report_anti_patterns_with_dictionary_values(self, mock_mapping):
9981042
"""
999-
Test report_anti_patterns method with dictionary values (malformed XML parsing).
1043+
Test report_anti_patterns method with dictionary values
1044+
(malformed XML parsing).
10001045
"""
10011046
mock_mapping.__getitem__.side_effect = (
10021047
self.anti_patterns_mapping.__getitem__)
@@ -1026,8 +1071,9 @@ def test_report_anti_patterns_with_dictionary_values(self, mock_mapping):
10261071
mock_sheet = Mock()
10271072
self.mock_workbook.add_worksheet.return_value = mock_sheet
10281073
report.report_anti_patterns()
1029-
1030-
# Verify the complex lines handle dictionary values (the customer's error scenario)
1074+
1075+
# Verify the complex lines handle dictionary values
1076+
# (the customer's error scenario)
10311077
expected_distributed = str({
10321078
'nested_key': 'nested_value',
10331079
'another_key': 123

0 commit comments

Comments
 (0)