Skip to content

Commit 620e90b

Browse files
committedJan 29, 2024
drop some pointless if six.PY3 else blocks in tests
1 parent 80c7ee3 commit 620e90b

File tree

7 files changed

+25
-92
lines changed

7 files changed

+25
-92
lines changed
 

Diff for: ‎contrib/runners/orquesta_runner/tests/unit/test_data_flow.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from __future__ import absolute_import
1919

2020
import mock
21-
import six
2221

2322
from orquesta import statuses as wf_statuses
2423

@@ -215,7 +214,7 @@ def assert_data_flow(self, data):
215214
self.assertEqual(ac_ex_db.status, ac_const.LIVEACTION_STATUS_SUCCEEDED)
216215

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

220219
expected_output = {
221220
"a6": expected_value,

Diff for: ‎contrib/runners/orquesta_runner/tests/unit/test_error_handling.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from __future__ import absolute_import
1717

1818
import mock
19-
import six
2019

2120
from orquesta import statuses as wf_statuses
2221

@@ -333,10 +332,7 @@ def test_fail_start_task_input_expr_eval(self):
333332
self.assertDictEqual(ac_ex_db.result, expected_result)
334333

335334
def test_fail_start_task_input_value_type(self):
336-
if six.PY3:
337-
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
338-
else:
339-
msg = "Value \"{u'x': u'foobar'}\" must either be a string or None. Got \"dict\"."
335+
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
340336

341337
msg = "ValueError: " + msg
342338

@@ -488,10 +484,7 @@ def test_fail_next_task_input_expr_eval(self):
488484
self.assertDictEqual(ac_ex_db.result, expected_result)
489485

490486
def test_fail_next_task_input_value_type(self):
491-
if six.PY3:
492-
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
493-
else:
494-
msg = "Value \"{u'x': u'foobar'}\" must either be a string or None. Got \"dict\"."
487+
msg = "Value \"{'x': 'foobar'}\" must either be a string or None. Got \"dict\"."
495488

496489
msg = "ValueError: " + msg
497490

Diff for: ‎st2api/tests/unit/controllers/v1/test_actions.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
except ImportError:
2525
import json
2626

27-
import six
2827
import mock
2928
import unittest2
3029
from six.moves import http_client
@@ -539,14 +538,9 @@ def test_post_parameter_type_is_array_and_invalid(self):
539538
post_resp = self.__do_post(ACTION_13, expect_errors=True)
540539
self.assertEqual(post_resp.status_int, 400)
541540

542-
if six.PY3:
543-
expected_error = (
544-
b"['string', 'object'] is not valid under any of the given schemas"
545-
)
546-
else:
547-
expected_error = (
548-
b"[u'string', u'object'] is not valid under any of the given schemas"
549-
)
541+
expected_error = (
542+
b"['string', 'object'] is not valid under any of the given schemas"
543+
)
550544

551545
self.assertIn(expected_error, post_resp.body)
552546

Diff for: ‎st2api/tests/unit/controllers/v1/test_rules.py

+5-18
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,9 @@ def test_post_trigger_parameter_schema_validation_fails(self):
336336
post_resp = self.__do_post(RulesControllerTestCase.RULE_2)
337337
self.assertEqual(post_resp.status_int, http_client.BAD_REQUEST)
338338

339-
if six.PY3:
340-
expected_msg = (
341-
b"Additional properties are not allowed ('minutex' was unexpected)"
342-
)
343-
else:
344-
expected_msg = (
345-
b"Additional properties are not allowed (u'minutex' was unexpected)"
346-
)
339+
expected_msg = (
340+
b"Additional properties are not allowed ('minutex' was unexpected)"
341+
)
347342

348343
self.assertIn(expected_msg, post_resp.body)
349344

@@ -385,16 +380,8 @@ def test_post_invalid_custom_trigger_parameter_trigger_param_validation_enabled(
385380
post_resp = self.__do_post(RulesControllerTestCase.RULE_9)
386381
self.assertEqual(post_resp.status_int, http_client.BAD_REQUEST)
387382

388-
if six.PY3:
389-
expected_msg_1 = (
390-
"Failed validating 'type' in schema['properties']['param1']:"
391-
)
392-
expected_msg_2 = "12345 is not of type 'string'"
393-
else:
394-
expected_msg_1 = (
395-
"Failed validating u'type' in schema[u'properties'][u'param1']:"
396-
)
397-
expected_msg_2 = "12345 is not of type u'string'"
383+
expected_msg_1 = "Failed validating 'type' in schema['properties']['param1']:"
384+
expected_msg_2 = "12345 is not of type 'string'"
398385

399386
self.assertIn(expected_msg_1, post_resp.json["faultstring"])
400387
self.assertIn(expected_msg_2, post_resp.json["faultstring"])

Diff for: ‎st2common/tests/unit/test_configs_registrar.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from __future__ import absolute_import
1717

18-
import six
1918
import mock
2019

2120
from st2common.content import utils as content_utils
@@ -122,16 +121,10 @@ def test_register_all_configs_with_config_schema_validation_validation_failure_1
122121
registrar._register_pack(pack_name="dummy_pack_5", pack_dir=PACK_6_PATH)
123122
packs_base_paths = content_utils.get_packs_base_paths()
124123

125-
if six.PY3:
126-
expected_msg = (
127-
'Failed validating attribute "regions" in config for pack '
128-
"\"dummy_pack_6\" (.*?): 1000 is not of type 'array'"
129-
)
130-
else:
131-
expected_msg = (
132-
'Failed validating attribute "regions" in config for pack '
133-
"\"dummy_pack_6\" (.*?): 1000 is not of type u'array'"
134-
)
124+
expected_msg = (
125+
'Failed validating attribute "regions" in config for pack '
126+
"\"dummy_pack_6\" (.*?): 1000 is not of type 'array'"
127+
)
135128

136129
self.assertRaisesRegexp(
137130
ValueError,
@@ -161,18 +154,11 @@ def test_register_all_configs_with_config_schema_validation_validation_failure_2
161154
registrar._register_pack(pack_name=DUMMY_PACK_19, pack_dir=PACK_19_PATH)
162155
packs_base_paths = content_utils.get_packs_base_paths()
163156

164-
if six.PY3:
165-
expected_msg = (
166-
'Failed validating attribute "instances.0.alias" in config for pack '
167-
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
168-
"'string'"
169-
)
170-
else:
171-
expected_msg = (
172-
'Failed validating attribute "instances.0.alias" in config for pack '
173-
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
174-
"u'string'"
175-
)
157+
expected_msg = (
158+
'Failed validating attribute "instances.0.alias" in config for pack '
159+
"\"dummy_pack_19\" (.*?): {'not': 'string'} is not of type "
160+
"'string'"
161+
)
176162

177163
self.assertRaisesRegexp(
178164
ValueError,

Diff for: ‎st2common/tests/unit/test_param_utils.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,7 @@ def test_unicode_value_casting(self):
374374
rendered=rendered, parameter_schemas=parameter_schemas
375375
)
376376

377-
if six.PY3:
378-
expected = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
379-
else:
380-
expected = {
381-
"a1": (
382-
"unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc"
383-
"\x83\xcc\xbe\xe2\x80\xa2\xcc\x83\xcc\xbe)\xdb\xb6 unicode2"
384-
)
385-
}
377+
expected = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
386378

387379
self.assertEqual(result, expected)
388380

@@ -398,15 +390,7 @@ def test_get_finalized_params_with_casting_unicode_values(self):
398390
runner_param_info, action_param_info, params, action_context
399391
)
400392

401-
if six.PY3:
402-
expected_action_params = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
403-
else:
404-
expected_action_params = {
405-
"a1": (
406-
"unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc"
407-
"\x83\xcc\xbe\xe2\x80\xa2\xcc\x83\xcc\xbe)\xdb\xb6 unicode2"
408-
)
409-
}
393+
expected_action_params = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
410394

411395
self.assertEqual(r_runner_params, {})
412396
self.assertEqual(r_action_params, expected_action_params)

Diff for: ‎st2common/tests/unit/test_service_setup.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import tempfile
1919

20-
import six
2120
import mock
2221

2322
from oslo_config.cfg import ConfigFilesNotFoundError
@@ -104,10 +103,7 @@ def tearDown(self):
104103
def test_no_logging_config_found(self):
105104
config.get_logging_config_path = mock_get_logging_config_path
106105

107-
if six.PY3:
108-
expected_msg = ".*KeyError:.*"
109-
else:
110-
expected_msg = "No section: .*"
106+
expected_msg = ".*KeyError:.*"
111107

112108
self.assertRaisesRegexp(
113109
Exception,
@@ -134,14 +130,8 @@ def mock_get_logging_config_path():
134130

135131
config.get_logging_config_path = mock_get_logging_config_path
136132

137-
if six.PY3:
138-
expected_msg = "ValueError: Unknown level: 'invalid_log_level'"
139-
exc_type = ValueError
140-
else:
141-
expected_msg = (
142-
"Invalid log level selected. Log level names need to be all uppercase"
143-
)
144-
exc_type = KeyError
133+
expected_msg = "ValueError: Unknown level: 'invalid_log_level'"
134+
exc_type = ValueError
145135

146136
self.assertRaisesRegexp(
147137
exc_type,

0 commit comments

Comments
 (0)
Please sign in to comment.