From bba6af2cb8a169a34ad6460d395eae4823a28405 Mon Sep 17 00:00:00 2001 From: Christopher Krolak Date: Sun, 2 Feb 2025 09:45:41 -0600 Subject: [PATCH] flake8 fixes --- tests/test_flask_generic.py | 30 +++++++++++++++++---------- tests/test_supervisor_flask_server.py | 4 +++- thermostatsupervisor/utilities.py | 2 -- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/test_flask_generic.py b/tests/test_flask_generic.py index 8e3ce30..4a6b9ad 100644 --- a/tests/test_flask_generic.py +++ b/tests/test_flask_generic.py @@ -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 @@ -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. @@ -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 @@ -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") @@ -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 diff --git a/tests/test_supervisor_flask_server.py b/tests/test_supervisor_flask_server.py index a0f80b7..8effee5 100644 --- a/tests/test_supervisor_flask_server.py +++ b/tests/test_supervisor_flask_server.py @@ -152,7 +152,9 @@ def test_run_supervise_response(self): response = sfs.index() self.assertEqual(response.status_code, 200) self.assertIn( - f"{utc.unit_test_argv[1]} thermostat zone {utc.unit_test_argv[2]}, {utc.unit_test_argv[7]} measurements", + f"{utc.unit_test_argv[1]} thermostat zone " + f"{utc.unit_test_argv[2]}, {utc.unit_test_argv[7]} " + "measurements", response.get_data(as_text=True), ) diff --git a/thermostatsupervisor/utilities.py b/thermostatsupervisor/utilities.py index 593d44f..56d375b 100644 --- a/thermostatsupervisor/utilities.py +++ b/thermostatsupervisor/utilities.py @@ -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, ""]: