From 6a0910cb44ce892dc6346a8e75501a9a8326b4fc Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 16 Jun 2020 11:47:59 +0200 Subject: [PATCH 1/3] tests: stop using assertNotEquals --- tests/test_examples.py | 4 ++-- tests/test_service.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 3b63fc6da..92aed9ca7 100755 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -150,7 +150,7 @@ def test_handlers(self): result = run( "handlers/handlers_certs.py --ca_file=handlers/cacert.bad.pem", stderr=PIPE) - self.assertNotEquals(result, 0) + self.assertNotEqual(result, 0) # The proxy handler example requires that there be a proxy available # to relay requests, so we spin up a local proxy using the proxy @@ -171,7 +171,7 @@ def test_handlers(self): # Run it again without the proxy and it should fail. result = run( "handlers/handler_proxy.py --proxy=localhost:80801", stderr=PIPE) - self.assertNotEquals(result, 0) + self.assertNotEqual(result, 0) def test_index(self): self.check_commands( diff --git a/tests/test_service.py b/tests/test_service.py index df78f54f7..2d239afb1 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -184,7 +184,7 @@ def test_login_and_store_cookie(self): self.assertEqual(len(self.service.get_cookies()), 0) self.service.login() self.assertIsNotNone(self.service.get_cookies()) - self.assertNotEquals(self.service.get_cookies(), {}) + self.assertNotEqual(self.service.get_cookies(), {}) self.assertEqual(len(self.service.get_cookies()), 1) def test_login_with_cookie(self): From 99d28bcd5deeb3bf1957f8aa109efba84aa43c4b Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 16 Jun 2020 11:50:17 +0200 Subject: [PATCH 2/3] searchcommands: don't use deprecated BaseException.message --- splunklib/searchcommands/validators.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/splunklib/searchcommands/validators.py b/splunklib/searchcommands/validators.py index 0278fbd59..62fdf6235 100644 --- a/splunklib/searchcommands/validators.py +++ b/splunklib/searchcommands/validators.py @@ -95,10 +95,7 @@ def __call__(self, value): try: return Code.object(compile(value, 'string', self._mode), six.text_type(value)) except (SyntaxError, TypeError) as error: - if six.PY2: - message = error.message - else: - message = str(error) + message = str(error) six.raise_from(ValueError(message), error) From 5aaef2970f99c09debf2006db5ce909bc231665f Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 16 Jun 2020 11:57:18 +0200 Subject: [PATCH 3/3] tests: use six.assertRegex instead of deprecated assertRegexpMatches --- tests/searchcommands/test_search_command.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/searchcommands/test_search_command.py b/tests/searchcommands/test_search_command.py index 1ebb29fb9..38c49bd54 100755 --- a/tests/searchcommands/test_search_command.py +++ b/tests/searchcommands/test_search_command.py @@ -127,7 +127,7 @@ def test_process_scpv1(self): result = BytesIO() self.assertRaises(SystemExit, command.process, argv, ofile=result) - self.assertRegexpMatches(result.getvalue().decode('UTF-8'), expected) + six.assertRegex(self, result.getvalue().decode('UTF-8'), expected) # TestCommand.process should return configuration settings on Getinfo probe @@ -294,7 +294,8 @@ def test_process_scpv1(self): command.process(argv, ifile, ofile=result) except SystemExit as error: self.assertNotEqual(error.code, 0) - self.assertRegexpMatches( + six.assertRegex( + self, result.getvalue().decode('UTF-8'), r'^error_message=RuntimeError at ".+", line \d+ : Testing\r\n\r\n$') except BaseException as error: @@ -318,7 +319,8 @@ def test_process_scpv1(self): except BaseException as error: self.fail('Expected no exception, but caught {}: {}'.format(type(error).__name__, error)) else: - self.assertRegexpMatches( + six.assertRegex( + self, result.getvalue().decode('UTF-8'), r'^\r\n' r'(' @@ -705,7 +707,8 @@ def test_process_scpv2(self): r'logging_configuration=\\\".+\\\" logging_level=\\\"WARNING\\\" record=\\\"f\\\" ' \ r'required_option_1=\\\"value_1\\\" required_option_2=\\\"value_2\\\" show_configuration=\\\"f\\\"\"\]\]\}' - self.assertRegexpMatches( + six.assertRegex( + self, result.getvalue().decode('utf-8'), r'^chunked 1.0,2,0\n' r'\{\}\n'