Skip to content

Commit

Permalink
Merge pull request #6187 from StackStorm/drop-unittest2
Browse files Browse the repository at this point in the history
Drop unittest2
  • Loading branch information
cognifloyd authored Apr 22, 2024
2 parents 8a5b7b8 + 3948c57 commit 5865d12
Show file tree
Hide file tree
Showing 158 changed files with 526 additions and 576 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changed
~~~~~~~
* Bumped `jsonschema` 2.6.0 -> 3.2.0 now that python3.6 is not supported. #6118
* Bumped many deps based on the lockfile generated by pants+pex. #6181 (by @cognifloyd and @nzlosh)
* Switch to python3's standard lib unittest from unittest2, a backport of python3 unittest features for python2. #6187 (by @nzlosh)

Added
~~~~~
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ REQUIREMENTS := test-requirements.txt requirements.txt
# Pin common pip version here across all the targets
# Note! Periodic maintenance pip upgrades are required to be up-to-date with the latest pip security fixes and updates
PIP_VERSION ?= 24.0
SETUPTOOLS_VERSION ?= 69.2.0
SETUPTOOLS_VERSION ?= 69.5.1
PIP_OPTIONS := $(ST2_PIP_OPTIONS)

ifndef PYLINT_CONCURRENCY
Expand Down
18 changes: 9 additions & 9 deletions contrib/packs/tests/test_action_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def mock_acquire(self, timeout=None):
fp.write("")

expected_msg = "Timeout waiting to acquire lock for"
self.assertRaisesRegexp(
self.assertRaisesRegex(
LockTimeout,
expected_msg,
action.run,
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_run_pack_download_invalid_version(self):
"is not a valid version, hash, tag or branch.*?"
"Available versions are: 1.0.0, 2.0.0."
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -351,7 +351,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "2.2.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -364,7 +364,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "2.3.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -377,7 +377,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "1.5.9"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -390,7 +390,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "1.5.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_download_pack_python_version_check(self):
r'Pack "test3" requires Python 2.x, but current Python version is '
'"3.5.2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -497,7 +497,7 @@ def test_download_pack_python_version_check(self):
r'Pack "test3" requires Python 3.x, but current Python version is '
'"2.7.2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down Expand Up @@ -657,7 +657,7 @@ def test_run_pack_download_local_directory(self):

# 1. Local directory doesn't exist
expected_msg = r'Local pack directory ".*" doesn\'t exist'
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def test_chain_runner_bad_default(self, request):
expected_msg = (
'Unable to find node with name "bad_default" referenced in "default".'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down Expand Up @@ -434,7 +434,7 @@ def test_chain_runner_broken_on_success_path_static_task_name(self, request):
'Unable to find node with name "c5" referenced in "on-success" '
'in task "c2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand All @@ -453,7 +453,7 @@ def test_chain_runner_broken_on_failure_path_static_task_name(self, request):
'Unable to find node with name "c6" referenced in "on-failure" '
'in task "c2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down Expand Up @@ -896,7 +896,7 @@ def test_chain_task_passes_invalid_parameter_type_to_action(self, mock_request):
r'Failed to cast value "stringnotanarray" \(type: str\) for parameter '
r'"arrtype" of type "array"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
chain_runner.run,
Expand Down Expand Up @@ -944,7 +944,7 @@ def test_exception_is_thrown_if_both_params_and_parameters_attributes_are_provid
'Either "params" or "parameters" attribute needs to be provided, but '
"not both"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

from __future__ import absolute_import
import unittest2
import unittest

import mock

Expand All @@ -24,7 +24,7 @@
from st2common.models.system.actionchain import Node


class ActionChainRunnerResolveParamsTests(unittest2.TestCase):
class ActionChainRunnerResolveParamsTests(unittest.TestCase):
def test_render_params_action_context(self):
runner = acr.get_runner()
chain_context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_announcement_no_experimental(self, dispatch):
runner.liveaction = mock.Mock(context={})

expected_msg = "Experimental flag is missing for action some.thing"
self.assertRaisesRegexp(Exception, expected_msg, runner.pre_run)
self.assertRaisesRegex(Exception, expected_msg, runner.pre_run)

@mock.patch("st2common.models.api.trace.TraceContext.__new__")
def test_announcement_with_trace(self, context, dispatch):
Expand Down
14 changes: 7 additions & 7 deletions contrib/runners/http_runner/tests/unit/test_http_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import six
import mock
import unittest2
import unittest

from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from http_runner.http_runner import HTTPClient
Expand All @@ -41,7 +41,7 @@ class MockResult(object):
close = mock.Mock()


class HTTPClientTestCase(unittest2.TestCase):
class HTTPClientTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
tests_config.parse_args()
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_blacklisted_url_url_hosts_blacklist_runner_parameter(self, mock_request
client = HTTPClient(
url=url, method="GET", url_hosts_blacklist=url_hosts_blacklist
)
self.assertRaisesRegexp(ValueError, expected_msg, client.run)
self.assertRaisesRegex(ValueError, expected_msg, client.run)

# Non blacklisted URLs
urls = ["https://example2.com", "http://example3.com", "http://example4.com:81"]
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_whitelisted_url_url_hosts_whitelist_runner_parameter(self, mock_request
client = HTTPClient(
url=url, method="GET", url_hosts_whitelist=url_hosts_whitelist
)
self.assertRaisesRegexp(ValueError, expected_msg, client.run)
self.assertRaisesRegex(ValueError, expected_msg, client.run)

# Whitelisted URLS
urls = [
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_url_host_blacklist_and_url_host_blacklist_params_are_mutually_exclusive
r'"url_hosts_blacklist" and "url_hosts_whitelist" parameters are mutually '
"exclusive."
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
HTTPClient,
Expand All @@ -383,7 +383,7 @@ def test_url_host_blacklist_and_url_host_blacklist_params_are_mutually_exclusive
)


class HTTPRunnerTestCase(unittest2.TestCase):
class HTTPRunnerTestCase(unittest.TestCase):
@mock.patch("http_runner.http_runner.requests")
def test_get_success(self, mock_requests):
mock_result = MockResult()
Expand Down Expand Up @@ -423,4 +423,4 @@ def test_url_host_blacklist_and_url_host_blacklist_params_are_mutually_exclusive
r'"url_hosts_blacklist" and "url_hosts_whitelist" parameters are mutually '
"exclusive."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.run, {})
self.assertRaisesRegex(ValueError, expected_msg, runner.run, {})
2 changes: 1 addition & 1 deletion contrib/runners/noop_runner/tests/unit/test_nooprunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

tests_config.parse_args()

from unittest2 import TestCase
from unittest import TestCase
from st2common.constants import action as action_constants
from st2tests.fixtures.generic.fixture import PACK_NAME as GENERIC_PACK
from st2tests.fixturesloader import FixturesLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import mock
import six
import unittest2
import unittest

import st2tests

Expand All @@ -42,7 +42,7 @@
MOCK_CTX_NO_USER = {"__vars": {"st2": {}}}


class DatastoreFunctionTest(unittest2.TestCase):
class DatastoreFunctionTest(unittest.TestCase):
def test_missing_user_context(self):
self.assertRaises(KeyError, st2kv.st2kv_, MOCK_CTX_NO_USER, "foo")

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_key_exists(self):
self.assertIsNone(st2kv.st2kv_(MOCK_CTX, "foo_null"))

def test_key_does_not_exist(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
'The key ".*" does not exist in the StackStorm datastore.',
st2kv.st2kv_,
Expand All @@ -120,7 +120,7 @@ def test_key_decrypt(self):
kvp_util, "get_key", mock.MagicMock(side_effect=Exception("Mock failure."))
)
def test_get_key_exception(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
"Mock failure.",
st2kv.st2kv_,
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_key_exists(self):
self.assertIsNone(st2kv.st2kv_(MOCK_CTX, "system.foo_null"))

def test_key_does_not_exist(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
'The key ".*" does not exist in the StackStorm datastore.',
st2kv.st2kv_,
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_key_decrypt(self):
kvp_util, "get_key", mock.MagicMock(side_effect=Exception("Mock failure."))
)
def test_get_key_exception(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
"Mock failure.",
st2kv.st2kv_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import os
import json

import unittest2
import unittest
from shutil import which as shutil_which

from st2common.util.shell import run_command
Expand Down Expand Up @@ -65,8 +65,8 @@
TIME_BINARY_AVAILABLE = TIME_BINARY_PATH is not None


@unittest2.skipIf(not TIME_BINARY_PATH, "time binary not available")
class PythonRunnerActionWrapperProcessTestCase(unittest2.TestCase):
@unittest.skipIf(not TIME_BINARY_PATH, "time binary not available")
class PythonRunnerActionWrapperProcessTestCase(unittest.TestCase):
def test_process_wrapper_exits_in_reasonable_timeframe(self):
# 1. Verify wrapper script path is correct and file exists
self.assertTrue(os.path.isfile(WRAPPER_SCRIPT_PATH))
Expand Down
18 changes: 9 additions & 9 deletions contrib/runners/python_runner/tests/unit/test_pythonrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_simple_action_no_entry_point(self):
runner.entry_point = ""

expected_msg = "Action .*? is missing entry_point attribute"
self.assertRaisesRegexp(Exception, expected_msg, runner.run, {})
self.assertRaisesRegex(Exception, expected_msg, runner.run, {})

@mock.patch("st2common.util.concurrency.subprocess_popen")
def test_action_with_user_supplied_env_vars(self, mock_popen):
Expand Down Expand Up @@ -720,7 +720,7 @@ def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(se
expected_msg = (
'File "/tmp/doesnt.exist" has no action class or the file doesn\'t exist.'
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

# File in a directory which is a Python package
wrapper = PythonActionWrapper(
Expand All @@ -732,7 +732,7 @@ def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(se
r"\(action file most likely doesn\'t exist or contains invalid syntax\): "
r"\[Errno 2\] No such file or directory"
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friendly_error(
self,
Expand All @@ -745,7 +745,7 @@ def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friend
r"\(action file most likely doesn\'t exist or contains invalid syntax\): "
r"No module named \'?invalid\'?"
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

def test_simple_action_log_messages_and_log_level_runner_param(self):
expected_msg_1 = (
Expand Down Expand Up @@ -927,7 +927,7 @@ def test_content_version_success(self, mock_get_sandbox_virtualenv_path):
'"v0.30.0" provided. Make sure that git repository is up '
"to date and contains that revision."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("python_runner.python_runner.get_sandbox_virtualenv_path")
@mock.patch("st2common.util.concurrency.subprocess_popen")
Expand Down Expand Up @@ -978,7 +978,7 @@ def test_content_version_success_local_modules_work_fine(
"<module '?local_module'? from '?%s/actions/local_module.py'?>.*"
% runner.git_worktree_path
)
self.assertRegexpMatches(output["stdout"].strip(), expected_stdout)
self.assertRegex(output["stdout"].strip(), expected_stdout)

@mock.patch("st2common.runners.base.run_command")
def test_content_version_old_git_version(self, mock_run_command):
Expand All @@ -998,7 +998,7 @@ def test_content_version_old_git_version(self, mock_run_command):
"doesn't support git worktree command. To be able to utilize this "
"functionality you need to use git >= 2.5.0."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("st2common.runners.base.run_command")
def test_content_version_pack_repo_not_git_repository(self, mock_run_command):
Expand All @@ -1020,7 +1020,7 @@ def test_content_version_pack_repo_not_git_repository(self, mock_run_command):
"git repository. To utilize this functionality, pack directory needs to "
"be a git repository."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("st2common.runners.base.run_command")
def test_content_version_invalid_git_revision(self, mock_run_command):
Expand All @@ -1040,7 +1040,7 @@ def test_content_version_invalid_git_revision(self, mock_run_command):
'"vinvalid" provided. Make sure that git repository is up '
"to date and contains that revision."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

def test_missing_config_item_user_friendly_error(self):
runner = self._get_mock_runner_obj()
Expand Down
Loading

0 comments on commit 5865d12

Please sign in to comment.