Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 1, 2023
1 parent 63483d4 commit 44bb49b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 40 deletions.
10 changes: 5 additions & 5 deletions scripts/conversion_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ def to_dict(self):

def check_for_inhibitors_in_rollback():
"""Returns lines with errors in rollback section of c2r log file, or empty string."""
print(
"Checking content of '%s' for possible rollback problems ..."
% C2R_LOG_FILE
)
print("Checking content of '%s' for possible rollback problems ..." % C2R_LOG_FILE)
matches = ""
start_of_rollback_section = "WARNING - Abnormal exit! Performing rollback ..."
try:
Expand All @@ -123,7 +120,10 @@ def check_for_inhibitors_in_rollback():
matches = list(filter(DETECT_ERROR_IN_ROLLBACK_PATTERN.match, actual_data))
matches = "\n".join(matches)
except ValueError:
print("Failed to find rollback section ('%s') in '%s' file." % (start_of_rollback_section, C2R_LOG_FILE))
print(
"Failed to find rollback section ('%s') in '%s' file."
% (start_of_rollback_section, C2R_LOG_FILE)
)
except IOError:
print("Failed to read '%s' file.")
return matches
Expand Down
10 changes: 5 additions & 5 deletions scripts/preconversion_assessment_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ def to_dict(self):

def check_for_inhibitors_in_rollback():
"""Returns lines with errors in rollback section of c2r log file, or empty string."""
print(
"Checking content of '%s' for possible rollback problems ..."
% C2R_LOG_FILE
)
print("Checking content of '%s' for possible rollback problems ..." % C2R_LOG_FILE)
matches = ""
start_of_rollback_section = "WARNING - Abnormal exit! Performing rollback ..."
try:
Expand All @@ -122,7 +119,10 @@ def check_for_inhibitors_in_rollback():
matches = list(filter(DETECT_ERROR_IN_ROLLBACK_PATTERN.match, actual_data))
matches = "\n".join(matches)
except ValueError:
print("Failed to find rollback section ('%s') in '%s' file." % (start_of_rollback_section, C2R_LOG_FILE))
print(
"Failed to find rollback section ('%s') in '%s' file."
% (start_of_rollback_section, C2R_LOG_FILE)
)
except IOError:
print("Failed to read '%s' file.")
return matches
Expand Down
45 changes: 30 additions & 15 deletions tests/conversion_script/test_check_rollback_inhibitors.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
from mock import patch, mock_open


from scripts.conversion_script import (
check_for_inhibitors_in_rollback
)
from scripts.conversion_script import check_for_inhibitors_in_rollback


@patch("__builtin__.open", mock_open(read_data="\n".join([
"Some lines before the warning",
"WARNING - Abnormal exit! Performing rollback ...",
"Error message 1",
"Error message 2",
"Pre-conversion analysis report",
"Some lines after the report",
])))
@patch(
"__builtin__.open",
mock_open(
read_data="\n".join(
[
"Some lines before the warning",
"WARNING - Abnormal exit! Performing rollback ...",
"Error message 1",
"Error message 2",
"Pre-conversion analysis report",
"Some lines after the report",
]
)
),
)
def test_rollback_with_errors():
result = check_for_inhibitors_in_rollback()
assert result == "Error message 1\nError message 2"

@patch("__builtin__.open", mock_open(read_data="".join([
"No warning or report",
"No errors here",
])))

@patch(
"__builtin__.open",
mock_open(
read_data="".join(
[
"No warning or report",
"No errors here",
]
)
),
)
def test_no_rollback_section_value_error():
result = check_for_inhibitors_in_rollback()
assert result == ""


@patch("__builtin__.open", side_effect=IOError("File not found"))
def test_io_error(mock_open):
result = check_for_inhibitors_in_rollback()
Expand Down
45 changes: 30 additions & 15 deletions tests/preconversion_assessment/test_check_rollback_inhibitors.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
from mock import patch, mock_open


from scripts.preconversion_assessment_script import (
check_for_inhibitors_in_rollback
)
from scripts.preconversion_assessment_script import check_for_inhibitors_in_rollback


@patch("__builtin__.open", mock_open(read_data="\n".join([
"Some lines before the warning",
"WARNING - Abnormal exit! Performing rollback ...",
"Error message 1",
"Error message 2",
"Pre-conversion analysis report",
"Some lines after the report",
])))
@patch(
"__builtin__.open",
mock_open(
read_data="\n".join(
[
"Some lines before the warning",
"WARNING - Abnormal exit! Performing rollback ...",
"Error message 1",
"Error message 2",
"Pre-conversion analysis report",
"Some lines after the report",
]
)
),
)
def test_rollback_with_errors():
result = check_for_inhibitors_in_rollback()
assert result == "Error message 1\nError message 2"

@patch("__builtin__.open", mock_open(read_data="".join([
"No warning or report",
"No errors here",
])))

@patch(
"__builtin__.open",
mock_open(
read_data="".join(
[
"No warning or report",
"No errors here",
]
)
),
)
def test_no_rollback_section_value_error():
result = check_for_inhibitors_in_rollback()
assert result == ""


@patch("__builtin__.open", side_effect=IOError("File not found"))
def test_io_error(mock_open):
result = check_for_inhibitors_in_rollback()
Expand Down

0 comments on commit 44bb49b

Please sign in to comment.