From c2a2ff1cbc764830ee3638b38e9eae7a68c446a3 Mon Sep 17 00:00:00 2001 From: mcencini Date: Sat, 5 Oct 2024 21:00:02 -0400 Subject: [PATCH] linting --- src/pulseclient/lib.py | 4 ++- tests/test_pulseclient.py | 52 ++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/pulseclient/lib.py b/src/pulseclient/lib.py index 91f3ca3..5fb6393 100644 --- a/src/pulseclient/lib.py +++ b/src/pulseclient/lib.py @@ -44,7 +44,9 @@ def load_config(): # If the file exists in the specified or default location, load the configuration if os.path.exists(config_file): - print("Loading configuration from: {}".format(config_file)) # Use .format for compatibility + print( + "Loading configuration from: {}".format(config_file) + ) # Use .format for compatibility parser = configparser.ConfigParser() parser.read(config_file) diff --git a/tests/test_pulseclient.py b/tests/test_pulseclient.py index b377530..7191db3 100644 --- a/tests/test_pulseclient.py +++ b/tests/test_pulseclient.py @@ -13,37 +13,55 @@ else: from unittest.mock import patch, mock_open, MagicMock # For Python 3.x -from pulseclient.lib import load_config, is_server_running, start_server, is_file_complete, send_file_to_server, watch_file +from pulseclient.lib import ( + load_config, + is_server_running, + start_server, + is_file_complete, + send_file_to_server, + watch_file, +) + class TestPulseClient(unittest.TestCase): - @patch('os.path.exists') - @patch('builtins.open', new_callable=mock_open, read_data='[DEFAULT]\nSERVER_IP = 192.168.1.100\n') + @patch("os.path.exists") + @patch( + "builtins.open", + new_callable=mock_open, + read_data="[DEFAULT]\nSERVER_IP = 192.168.1.100\n", + ) def test_load_config_from_default_location(self, mock_file, mock_exists): mock_exists.return_value = True # Simulate that the config file exists config = load_config() - self.assertEqual(config['SERVER_IP'], '192.168.1.100') + self.assertEqual(config["SERVER_IP"], "192.168.1.100") - @patch('os.path.exists') - @patch('builtins.open', new_callable=mock_open, read_data='[DEFAULT]\nSERVER_PORT = 12345\n') - @patch.dict(os.environ, {'PULSECLIENT_CONFIG': '/custom/path/to/pulseclient.ini'}) + @patch("os.path.exists") + @patch( + "builtins.open", + new_callable=mock_open, + read_data="[DEFAULT]\nSERVER_PORT = 12345\n", + ) + @patch.dict(os.environ, {"PULSECLIENT_CONFIG": "/custom/path/to/pulseclient.ini"}) def test_load_config_from_env_variable(self, mock_file, mock_exists): mock_exists.return_value = True config = load_config() - self.assertEqual(config['SERVER_PORT'], 12345) + self.assertEqual(config["SERVER_PORT"], 12345) - @patch('os.path.exists') - @patch('builtins.open', new_callable=mock_open, read_data='[DEFAULT]\n') + @patch("os.path.exists") + @patch("builtins.open", new_callable=mock_open, read_data="[DEFAULT]\n") def test_load_config_partial_custom_values(self, mock_file, mock_exists): mock_exists.return_value = True config = load_config() - self.assertEqual(config['SERVER_IP'], '192.168.1.100') # Default value should be used + self.assertEqual( + config["SERVER_IP"], "192.168.1.100" + ) # Default value should be used - @patch('subprocess.Popen') + @patch("subprocess.Popen") def test_is_server_running(self, mock_popen): # Mock the output of the command mock_process = MagicMock() - mock_process.communicate.return_value = (b'external_server.py', b'') + mock_process.communicate.return_value = (b"external_server.py", b"") mock_process.returncode = 0 mock_popen.return_value = mock_process @@ -51,16 +69,16 @@ def test_is_server_running(self, mock_popen): result = is_server_running(config) self.assertTrue(result) # The server is running - @patch('subprocess.Popen') + @patch("subprocess.Popen") def test_start_server_when_running(self, mock_popen): config = load_config() # Load config to pass to the function - with patch('pulseclient.lib.is_server_running', return_value=True): + with patch("pulseclient.lib.is_server_running", return_value=True): start_server(config) # Should not raise an error mock_popen.assert_not_called() # Ensure no command is executed - @patch('subprocess.Popen') + @patch("subprocess.Popen") def test_start_server_when_not_running(self, mock_popen): config = load_config() # Load config to pass to the function - with patch('pulseclient.lib.is_server_running', return_value=False): + with patch("pulseclient.lib.is_server_running", return_value=False): mock_process = MagicMock() mock_process.returnc