Skip to content

Commit

Permalink
tests: drop some pointless if six.PY3 else blocks
Browse files Browse the repository at this point in the history
We only support python 3, so these are hold overs from the 2->3
transition.
  • Loading branch information
cognifloyd committed Jan 29, 2024
1 parent 591e0cd commit 34d831c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def assert_data_flow(self, data):
self.assertEqual(ac_ex_db.status, ac_const.LIVEACTION_STATUS_SUCCEEDED)

# Check workflow output.
expected_value = wf_input["a1"] if six.PY3 else wf_input["a1"].decode("utf-8")
expected_value = wf_input["a1"]

expected_output = {
"a6": expected_value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,7 @@ def test_fail_start_task_input_expr_eval(self):
self.assertDictEqual(ac_ex_db.result, expected_result)

def test_fail_start_task_input_value_type(self):
if six.PY3:
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
else:
msg = "Value \"{u'x': u'foobar'}\" must either be a string or None. Got \"dict\"."
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."

msg = "ValueError: " + msg

Expand Down Expand Up @@ -488,10 +485,7 @@ def test_fail_next_task_input_expr_eval(self):
self.assertDictEqual(ac_ex_db.result, expected_result)

def test_fail_next_task_input_value_type(self):
if six.PY3:
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
else:
msg = "Value \"{u'x': u'foobar'}\" must either be a string or None. Got \"dict\"."
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."

msg = "ValueError: " + msg

Expand Down
11 changes: 3 additions & 8 deletions st2api/tests/unit/controllers/v1/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,9 @@ def test_post_parameter_type_is_array_and_invalid(self):
post_resp = self.__do_post(ACTION_13, expect_errors=True)
self.assertEqual(post_resp.status_int, 400)

if six.PY3:
expected_error = (
b"['string', 'object'] is not valid under any of the given schemas"
)
else:
expected_error = (
b"[u'string', u'object'] is not valid under any of the given schemas"
)
expected_error = (
b"['string', 'object'] is not valid under any of the given schemas"
)

self.assertIn(expected_error, post_resp.body)

Expand Down
23 changes: 5 additions & 18 deletions st2api/tests/unit/controllers/v1/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,9 @@ def test_post_trigger_parameter_schema_validation_fails(self):
post_resp = self.__do_post(RulesControllerTestCase.RULE_2)
self.assertEqual(post_resp.status_int, http_client.BAD_REQUEST)

if six.PY3:
expected_msg = (
b"Additional properties are not allowed ('minutex' was unexpected)"
)
else:
expected_msg = (
b"Additional properties are not allowed (u'minutex' was unexpected)"
)
expected_msg = (
b"Additional properties are not allowed ('minutex' was unexpected)"
)

self.assertIn(expected_msg, post_resp.body)

Expand Down Expand Up @@ -385,16 +380,8 @@ def test_post_invalid_custom_trigger_parameter_trigger_param_validation_enabled(
post_resp = self.__do_post(RulesControllerTestCase.RULE_9)
self.assertEqual(post_resp.status_int, http_client.BAD_REQUEST)

if six.PY3:
expected_msg_1 = (
"Failed validating 'type' in schema['properties']['param1']:"
)
expected_msg_2 = "12345 is not of type 'string'"
else:
expected_msg_1 = (
"Failed validating u'type' in schema[u'properties'][u'param1']:"
)
expected_msg_2 = "12345 is not of type u'string'"
expected_msg_1 = "Failed validating 'type' in schema['properties']['param1']:"
expected_msg_2 = "12345 is not of type 'string'"

self.assertIn(expected_msg_1, post_resp.json["faultstring"])
self.assertIn(expected_msg_2, post_resp.json["faultstring"])
Expand Down
31 changes: 9 additions & 22 deletions st2common/tests/unit/test_configs_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,10 @@ def test_register_all_configs_with_config_schema_validation_validation_failure_1
registrar._register_pack(pack_name="dummy_pack_5", pack_dir=PACK_6_PATH)
packs_base_paths = content_utils.get_packs_base_paths()

if six.PY3:
expected_msg = (
'Failed validating attribute "regions" in config for pack '
"\"dummy_pack_6\" (.*?): 1000 is not of type 'array'"
)
else:
expected_msg = (
'Failed validating attribute "regions" in config for pack '
"\"dummy_pack_6\" (.*?): 1000 is not of type u'array'"
)
expected_msg = (
'Failed validating attribute "regions" in config for pack '
"\"dummy_pack_6\" (.*?): 1000 is not of type 'array'"
)

self.assertRaisesRegexp(
ValueError,
Expand Down Expand Up @@ -161,18 +155,11 @@ def test_register_all_configs_with_config_schema_validation_validation_failure_2
registrar._register_pack(pack_name=DUMMY_PACK_19, pack_dir=PACK_19_PATH)
packs_base_paths = content_utils.get_packs_base_paths()

if six.PY3:
expected_msg = (
'Failed validating attribute "instances.0.alias" in config for pack '
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
"'string'"
)
else:
expected_msg = (
'Failed validating attribute "instances.0.alias" in config for pack '
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
"u'string'"
)
expected_msg = (
'Failed validating attribute "instances.0.alias" in config for pack '
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
"'string'"
)

self.assertRaisesRegexp(
ValueError,
Expand Down
20 changes: 2 additions & 18 deletions st2common/tests/unit/test_param_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,7 @@ def test_unicode_value_casting(self):
rendered=rendered, parameter_schemas=parameter_schemas
)

if six.PY3:
expected = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
else:
expected = {
"a1": (
"unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc"
"\x83\xcc\xbe\xe2\x80\xa2\xcc\x83\xcc\xbe)\xdb\xb6 unicode2"
)
}
expected = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}

self.assertEqual(result, expected)

Expand All @@ -398,15 +390,7 @@ def test_get_finalized_params_with_casting_unicode_values(self):
runner_param_info, action_param_info, params, action_context
)

if six.PY3:
expected_action_params = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
else:
expected_action_params = {
"a1": (
"unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc"
"\x83\xcc\xbe\xe2\x80\xa2\xcc\x83\xcc\xbe)\xdb\xb6 unicode2"
)
}
expected_action_params = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}

self.assertEqual(r_runner_params, {})
self.assertEqual(r_action_params, expected_action_params)
Expand Down
15 changes: 3 additions & 12 deletions st2common/tests/unit/test_service_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ def tearDown(self):
def test_no_logging_config_found(self):
config.get_logging_config_path = mock_get_logging_config_path

if six.PY3:
expected_msg = ".*KeyError:.*"
else:
expected_msg = "No section: .*"
expected_msg = ".*KeyError:.*"

self.assertRaisesRegexp(
Exception,
Expand All @@ -134,14 +131,8 @@ def mock_get_logging_config_path():

config.get_logging_config_path = mock_get_logging_config_path

if six.PY3:
expected_msg = "ValueError: Unknown level: 'invalid_log_level'"
exc_type = ValueError
else:
expected_msg = (
"Invalid log level selected. Log level names need to be all uppercase"
)
exc_type = KeyError
expected_msg = "ValueError: Unknown level: 'invalid_log_level'"
exc_type = ValueError

self.assertRaisesRegexp(
exc_type,
Expand Down

0 comments on commit 34d831c

Please sign in to comment.