From bfa9b0ca4b4f78d52c2b7cca13d2294583896377 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Mon, 16 Sep 2024 17:20:00 +0200 Subject: [PATCH] Fix flake8 for tests directory (#3168) Followup on #3123 --- setup.py | 1 + tests/test_ha.py | 6 ++++-- tests/test_patroni.py | 2 -- tests/test_postgresql.py | 2 +- tests/test_slots.py | 3 ++- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 0d69a840..c3a6dc54 100644 --- a/setup.py +++ b/setup.py @@ -88,6 +88,7 @@ class _Lint(_Command): def aux_directories(self): for dir_name in ('tests', 'features'): + yield dir_name for root, dirs, files in os.walk(dir_name): for name in dirs: yield os.path.join(root, name) diff --git a/tests/test_ha.py b/tests/test_ha.py index 87316984..34a77950 100644 --- a/tests/test_ha.py +++ b/tests/test_ha.py @@ -584,14 +584,16 @@ class TestHa(PostgresInit): self.ha.patroni.request.return_value.status = 200 with patch('patroni.ha.logger.info') as mock_logger: ret = self.ha.call_failsafe_member({}, member) - self.assertEqual(mock_logger.call_args_list[0][0], ('Got response from %s %s: %s', 'test', 'http://localhost:8011/failsafe', 'Accepted')) + self.assertEqual(mock_logger.call_args_list[0][0], + ('Got response from %s %s: %s', 'test', 'http://localhost:8011/failsafe', 'Accepted')) self.assertTrue(ret.accepted) e = Exception('request failed') self.ha.patroni.request.side_effect = e with patch('patroni.ha.logger.warning') as mock_logger: ret = self.ha.call_failsafe_member({}, member) - self.assertEqual(mock_logger.call_args_list[0][0], ('Request failed to %s: POST %s (%s)', 'test', 'http://localhost:8011/failsafe', e)) + self.assertEqual(mock_logger.call_args_list[0][0], + ('Request failed to %s: POST %s (%s)', 'test', 'http://localhost:8011/failsafe', e)) self.assertFalse(ret.accepted) @patch('time.sleep', Mock()) diff --git a/tests/test_patroni.py b/tests/test_patroni.py index ae017c47..76fe3fb2 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -106,7 +106,6 @@ class TestPatroni(unittest.TestCase): self.p.apply_dynamic_configuration(cluster) self.assertEqual(self.p.config._dynamic_configuration['ttl'], 40) - @patch('sys.argv', ['patroni.py', 'postgres0.yml']) @patch('time.sleep', Mock(side_effect=SleepException)) @patch.object(etcd.Client, 'delete', Mock()) @@ -320,4 +319,3 @@ class TestPatroni(unittest.TestCase): result = self.p.ensure_dcs_access() self.assertEqual(result, None) self.assertEqual(mock_logger.call_count, 2) - diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 3bc5f55d..dffc8ba7 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -1113,7 +1113,7 @@ class TestPostgresql(BaseTestPostgresql): file1_mock = MagicMock(**file1_attrs) file1_mock.name = '__init__.py' file2_attrs = {'is_file.return_value': False, 'is_dir.return_value': True, - 'iterdir.side_effect': PermissionError(13, 'Permission denied')} + 'iterdir.side_effect': PermissionError(13, 'Permission denied')} file2_mock = MagicMock(**file2_attrs) file2_mock.name = '__pycache__' file3_attrs = {'is_file.return_value': True, 'is_dir.return_value': False} diff --git a/tests/test_slots.py b/tests/test_slots.py index 93852125..68845d5c 100644 --- a/tests/test_slots.py +++ b/tests/test_slots.py @@ -321,7 +321,8 @@ class TestSlotsHandler(BaseTestPostgresql): patch.object(SlotsHandler, 'drop_replication_slot', Mock(return_value=(True, False))), \ patch('patroni.postgresql.slots.logger.warning') as mock_warning: self.s.sync_replication_slots(cluster, self.tags) - self.assertEqual(mock_warning.call_args_list[-1][0], ("Unable to drop replication slot '%s', slot is active", 'test_1')) + self.assertEqual(mock_warning.call_args_list[-1][0], + ("Unable to drop replication slot '%s', slot is active", 'test_1')) with patch.object(SlotsHandler, '_query', Mock(side_effect=[[('test_1', 'physical', 1, 12345, None, None, None, None, None)], Exception])), \