Skip to content

Commit

Permalink
flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkrolak committed Feb 2, 2025
1 parent ae20851 commit bba6af2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
30 changes: 19 additions & 11 deletions tests/test_flask_generic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Unit tests for the `flask_generic` module in the `thermostatsupervisor` package.
Classes:
TestFlaskGeneric: Contains unit tests for the `schedule_ipban_block_list_report` and `print_ipban_block_list_with_timestamp` functions.
TestFlaskGeneric: Contains unit tests for the `schedule_ipban_block_list_report`
and `print_ipban_block_list_with_timestamp` functions.
Methods:
test_schedule_ipban_block_list_report(MockAPScheduler):
Tests the `schedule_ipban_block_list_report` function to ensure it schedules the IP ban block list report correctly with different debug modes.
Tests the `schedule_ipban_block_list_report` function to ensure it schedules
the IP ban block list report correctly with different debug modes.
test_print_ipban_block_list_with_timestamp(mock_datetime):
Tests the `print_ipban_block_list_with_timestamp` function to ensure it prints the IP ban block list with the correct timestamp.
Tests the `print_ipban_block_list_with_timestamp` function to ensure it prints
the IP ban block list with the correct timestamp.
"""

# built-in modules
Expand Down Expand Up @@ -35,7 +38,8 @@ class TestFlaskGeneric(utc.UnitTest):
the print function is called with the expected output string containing the
timestamp and the IP ban block list.
2. `test_schedule_ipban_block_list_report_debug_mode`:
- Tests the `schedule_ipban_block_list_report` function to ensure that it schedules
- Tests the `schedule_ipban_block_list_report` function to ensure that it
schedules.
- Sets `debug_mode` to True and verifies that the print function is called with
the expected message indicating that the IP ban blacklist report is scheduled
every 1.0 minutes.
Expand Down Expand Up @@ -75,10 +79,11 @@ def test_print_ipban_block_list_with_timestamp(self, mock_print):
- Set the expected timestamp to "2024-01-01 12:00:00".
- Mock the current datetime to return the expected timestamp.
Act:
- Call the print_ipban_block_list_with_timestamp function with the mocked IP ban list.
- Call the print_ipban_block_list_with_timestamp function with the mocked
IP ban list.
Assert:
- Verify that the print function is called once with the expected output string
containing the timestamp and the IP ban block list.
- Verify that the print function is called once with the expected output
string containing the timestamp and the IP ban block list.
"""

# Arrange
Expand All @@ -93,7 +98,8 @@ def test_print_ipban_block_list_with_timestamp(self, mock_print):

# Assert
mock_print.assert_called_once_with(
f"{expected_timestamp}: ip_ban black list: {self.mock_ip_ban.get_block_list()}"
f"{expected_timestamp}: ip_ban black list: "
f"{self.mock_ip_ban.get_block_list()}"
)

@patch("builtins.print")
Expand All @@ -108,10 +114,12 @@ def test_schedule_ipban_block_list_report_debug_mode(self, mock_print):
- Define the expected interval as "1.0" minutes.
Act:
- Patch the `BackgroundScheduler` from `apscheduler.schedulers.background`.
- Call `schedule_ipban_block_list_report` with the mock IP ban object and debug mode.
- Call `schedule_ipban_block_list_report` with the mock IP ban object and
debug mode.
Assert:
- Verify that the print function is called once with the expected message indicating
that the IP ban blacklist report is scheduled every 1.0 minutes.
- Verify that the print function is called once with the expected message
indicating that the IP ban blacklist report is scheduled every
1.0 minutes.
"""

# Arrange
Expand Down
4 changes: 3 additions & 1 deletion tests/test_supervisor_flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def test_run_supervise_response(self):
response = sfs.index()
self.assertEqual(response.status_code, 200)
self.assertIn(
f"<title>{utc.unit_test_argv[1]} thermostat zone {utc.unit_test_argv[2]}, {utc.unit_test_argv[7]} measurements</title>",
f"<title>{utc.unit_test_argv[1]} thermostat zone "
f"{utc.unit_test_argv[2]}, {utc.unit_test_argv[7]} "
"measurements</title>",
response.get_data(as_text=True),
)

Expand Down
2 changes: 0 additions & 2 deletions thermostatsupervisor/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,6 @@ def is_valid_file(self, arg=None):
returns:
open file handle
"""
# if arg is None:
# raise ValueError(f"filename input '{arg}' to 'is_valid_file' cannot be None")
if arg is not None:
arg = arg.strip() # remove any leading spaces
if arg in [None, ""]:
Expand Down

0 comments on commit bba6af2

Please sign in to comment.