Skip to content

Commit c3b191b

Browse files
Removing deprecated warnings (#335)
* [MAINTENANCE] Remove Deprecated warnings during build - assertRaisesRegexp -> assertRaisesRegex - assertEquals -> assertEqual - isAlive() -> is_alive() - Check added to base.py to confirm attribute assertRaisesRegex for backwards compatibility to Python2.7 * Updating copyrights to 2021 on touched files.
1 parent cdc652e commit c3b191b

File tree

6 files changed

+42
-36
lines changed

6 files changed

+42
-36
lines changed

Diff for: optimizely/event/event_processor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2020 Optimizely
1+
# Copyright 2019-2021 Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -120,7 +120,7 @@ def __init__(
120120
@property
121121
def is_running(self):
122122
""" Property to check if consumer thread is alive or not. """
123-
return self.executor.isAlive() if self.executor else False
123+
return self.executor.is_alive() if self.executor else False
124124

125125
def _validate_instantiation_props(self, prop, prop_name, default_value):
126126
""" Method to determine if instantiation properties like batch_size, flush_interval

Diff for: tests/base.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2020, Optimizely
1+
# Copyright 2016-2021, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -22,6 +22,12 @@
2222
def long(a):
2323
raise NotImplementedError('Tests should only call `long` if running in PY2')
2424

25+
# Check to verify if TestCase has the attribute assertRasesRegex or assertRaisesRegexp
26+
# This check depends on the version of python with assertRaisesRegexp being used by
27+
# python2.7. Later versions of python are using the non-deprecated assertRaisesRegex.
28+
if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
29+
unittest.TestCase.assertRaisesRegex = getattr(unittest.TestCase, 'assertRaisesRegexp')
30+
2531

2632
class BaseTest(unittest.TestCase):
2733
def assertStrictTrue(self, to_assert):

Diff for: tests/test_config.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2019, Optimizely
1+
# Copyright 2016-2019, 2021, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -1117,7 +1117,7 @@ def setUp(self):
11171117
def test_get_experiment_from_key__invalid_key(self):
11181118
""" Test that exception is raised when provided experiment key is invalid. """
11191119

1120-
self.assertRaisesRegexp(
1120+
self.assertRaisesRegex(
11211121
exceptions.InvalidExperimentException,
11221122
enums.Errors.INVALID_EXPERIMENT_KEY,
11231123
self.project_config.get_experiment_from_key,
@@ -1127,14 +1127,14 @@ def test_get_experiment_from_key__invalid_key(self):
11271127
def test_get_audience__invalid_id(self):
11281128
""" Test that message is logged when provided audience ID is invalid. """
11291129

1130-
self.assertRaisesRegexp(
1130+
self.assertRaisesRegex(
11311131
exceptions.InvalidAudienceException, enums.Errors.INVALID_AUDIENCE, self.project_config.get_audience, '42',
11321132
)
11331133

11341134
def test_get_variation_from_key__invalid_experiment_key(self):
11351135
""" Test that exception is raised when provided experiment key is invalid. """
11361136

1137-
self.assertRaisesRegexp(
1137+
self.assertRaisesRegex(
11381138
exceptions.InvalidExperimentException,
11391139
enums.Errors.INVALID_EXPERIMENT_KEY,
11401140
self.project_config.get_variation_from_key,
@@ -1145,7 +1145,7 @@ def test_get_variation_from_key__invalid_experiment_key(self):
11451145
def test_get_variation_from_key__invalid_variation_key(self):
11461146
""" Test that exception is raised when provided variation key is invalid. """
11471147

1148-
self.assertRaisesRegexp(
1148+
self.assertRaisesRegex(
11491149
exceptions.InvalidVariationException,
11501150
enums.Errors.INVALID_VARIATION,
11511151
self.project_config.get_variation_from_key,
@@ -1156,7 +1156,7 @@ def test_get_variation_from_key__invalid_variation_key(self):
11561156
def test_get_variation_from_id__invalid_experiment_key(self):
11571157
""" Test that exception is raised when provided experiment key is invalid. """
11581158

1159-
self.assertRaisesRegexp(
1159+
self.assertRaisesRegex(
11601160
exceptions.InvalidExperimentException,
11611161
enums.Errors.INVALID_EXPERIMENT_KEY,
11621162
self.project_config.get_variation_from_id,
@@ -1167,7 +1167,7 @@ def test_get_variation_from_id__invalid_experiment_key(self):
11671167
def test_get_variation_from_id__invalid_variation_id(self):
11681168
""" Test that exception is raised when provided variation ID is invalid. """
11691169

1170-
self.assertRaisesRegexp(
1170+
self.assertRaisesRegex(
11711171
exceptions.InvalidVariationException,
11721172
enums.Errors.INVALID_VARIATION,
11731173
self.project_config.get_variation_from_key,
@@ -1178,7 +1178,7 @@ def test_get_variation_from_id__invalid_variation_id(self):
11781178
def test_get_event__invalid_key(self):
11791179
""" Test that exception is raised when provided event key is invalid. """
11801180

1181-
self.assertRaisesRegexp(
1181+
self.assertRaisesRegex(
11821182
exceptions.InvalidEventException,
11831183
enums.Errors.INVALID_EVENT_KEY,
11841184
self.project_config.get_event,
@@ -1188,7 +1188,7 @@ def test_get_event__invalid_key(self):
11881188
def test_get_attribute_id__invalid_key(self):
11891189
""" Test that exception is raised when provided attribute key is invalid. """
11901190

1191-
self.assertRaisesRegexp(
1191+
self.assertRaisesRegex(
11921192
exceptions.InvalidAttributeException,
11931193
enums.Errors.INVALID_ATTRIBUTE,
11941194
self.project_config.get_attribute_id,
@@ -1198,7 +1198,7 @@ def test_get_attribute_id__invalid_key(self):
11981198
def test_get_group__invalid_id(self):
11991199
""" Test that exception is raised when provided group ID is invalid. """
12001200

1201-
self.assertRaisesRegexp(
1201+
self.assertRaisesRegex(
12021202
exceptions.InvalidGroupException, enums.Errors.INVALID_GROUP_ID, self.project_config.get_group, '42',
12031203
)
12041204

Diff for: tests/test_config_manager.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2020, Optimizely
1+
# Copyright 2019-2021, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -32,7 +32,7 @@ def test_init__invalid_logger_fails(self):
3232
class InvalidLogger(object):
3333
pass
3434

35-
with self.assertRaisesRegexp(
35+
with self.assertRaisesRegex(
3636
optimizely_exceptions.InvalidInputException, 'Provided "logger" is in an invalid format.',
3737
):
3838
config_manager.StaticConfigManager(logger=InvalidLogger())
@@ -43,7 +43,7 @@ def test_init__invalid_error_handler_fails(self):
4343
class InvalidErrorHandler(object):
4444
pass
4545

46-
with self.assertRaisesRegexp(
46+
with self.assertRaisesRegex(
4747
optimizely_exceptions.InvalidInputException, 'Provided "error_handler" is in an invalid format.',
4848
):
4949
config_manager.StaticConfigManager(error_handler=InvalidErrorHandler())
@@ -54,7 +54,7 @@ def test_init__invalid_notification_center_fails(self):
5454
class InvalidNotificationCenter(object):
5555
pass
5656

57-
with self.assertRaisesRegexp(
57+
with self.assertRaisesRegex(
5858
optimizely_exceptions.InvalidInputException, 'Provided "notification_center" is in an invalid format.',
5959
):
6060
config_manager.StaticConfigManager(notification_center=InvalidNotificationCenter())
@@ -222,7 +222,7 @@ def test_get_config_blocks(self):
222222
class PollingConfigManagerTest(base.BaseTest):
223223
def test_init__no_sdk_key_no_url__fails(self, _):
224224
""" Test that initialization fails if there is no sdk_key or url provided. """
225-
self.assertRaisesRegexp(
225+
self.assertRaisesRegex(
226226
optimizely_exceptions.InvalidInputException,
227227
'Must provide at least one of sdk_key or url.',
228228
config_manager.PollingConfigManager,
@@ -232,7 +232,7 @@ def test_init__no_sdk_key_no_url__fails(self, _):
232232

233233
def test_get_datafile_url__no_sdk_key_no_url_raises(self, _):
234234
""" Test that get_datafile_url raises exception if no sdk_key or url is provided. """
235-
self.assertRaisesRegexp(
235+
self.assertRaisesRegex(
236236
optimizely_exceptions.InvalidInputException,
237237
'Must provide at least one of sdk_key or url.',
238238
config_manager.PollingConfigManager.get_datafile_url,
@@ -244,7 +244,7 @@ def test_get_datafile_url__no_sdk_key_no_url_raises(self, _):
244244
def test_get_datafile_url__invalid_url_template_raises(self, _):
245245
""" Test that get_datafile_url raises if url_template is invalid. """
246246
# No url_template provided
247-
self.assertRaisesRegexp(
247+
self.assertRaisesRegex(
248248
optimizely_exceptions.InvalidInputException,
249249
'Invalid url_template None provided',
250250
config_manager.PollingConfigManager.get_datafile_url,
@@ -255,7 +255,7 @@ def test_get_datafile_url__invalid_url_template_raises(self, _):
255255

256256
# Incorrect url_template provided
257257
test_url_template = 'invalid_url_template_without_sdk_key_field_{key}'
258-
self.assertRaisesRegexp(
258+
self.assertRaisesRegex(
259259
optimizely_exceptions.InvalidInputException,
260260
'Invalid url_template {} provided'.format(test_url_template),
261261
config_manager.PollingConfigManager.get_datafile_url,
@@ -298,7 +298,7 @@ def test_set_update_interval(self, _):
298298
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')
299299

300300
# Assert that if invalid update_interval is set, then exception is raised.
301-
with self.assertRaisesRegexp(
301+
with self.assertRaisesRegex(
302302
optimizely_exceptions.InvalidInputException, 'Invalid update_interval "invalid interval" provided.',
303303
):
304304
project_config_manager.set_update_interval('invalid interval')
@@ -325,7 +325,7 @@ def test_set_blocking_timeout(self, _):
325325
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')
326326

327327
# Assert that if invalid blocking_timeout is set, then exception is raised.
328-
with self.assertRaisesRegexp(
328+
with self.assertRaisesRegex(
329329
optimizely_exceptions.InvalidInputException, 'Invalid blocking timeout "invalid timeout" provided.',
330330
):
331331
project_config_manager.set_blocking_timeout('invalid timeout')
@@ -484,7 +484,7 @@ def test_is_running(self, _):
484484
class AuthDatafilePollingConfigManagerTest(base.BaseTest):
485485
def test_init__datafile_access_token_none__fails(self, _):
486486
""" Test that initialization fails if datafile_access_token is None. """
487-
self.assertRaisesRegexp(
487+
self.assertRaisesRegex(
488488
optimizely_exceptions.InvalidInputException,
489489
'datafile_access_token cannot be empty or None.',
490490
config_manager.AuthDatafilePollingConfigManager,

Diff for: tests/test_optimizely.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4633,7 +4633,7 @@ def setUp(self):
46334633
def test_activate__with_attributes__invalid_attributes(self):
46344634
""" Test that activate raises exception if attributes are in invalid format. """
46354635

4636-
self.assertRaisesRegexp(
4636+
self.assertRaisesRegex(
46374637
exceptions.InvalidAttributeException,
46384638
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
46394639
self.optimizely.activate,
@@ -4645,7 +4645,7 @@ def test_activate__with_attributes__invalid_attributes(self):
46454645
def test_track__with_attributes__invalid_attributes(self):
46464646
""" Test that track raises exception if attributes are in invalid format. """
46474647

4648-
self.assertRaisesRegexp(
4648+
self.assertRaisesRegex(
46494649
exceptions.InvalidAttributeException,
46504650
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
46514651
self.optimizely.track,
@@ -4657,7 +4657,7 @@ def test_track__with_attributes__invalid_attributes(self):
46574657
def test_track__with_event_tag__invalid_event_tag(self):
46584658
""" Test that track raises exception if event_tag is in invalid format. """
46594659

4660-
self.assertRaisesRegexp(
4660+
self.assertRaisesRegex(
46614661
exceptions.InvalidEventTagException,
46624662
enums.Errors.INVALID_EVENT_TAG_FORMAT,
46634663
self.optimizely.track,
@@ -4669,7 +4669,7 @@ def test_track__with_event_tag__invalid_event_tag(self):
46694669
def test_get_variation__with_attributes__invalid_attributes(self):
46704670
""" Test that get variation raises exception if attributes are in invalid format. """
46714671

4672-
self.assertRaisesRegexp(
4672+
self.assertRaisesRegex(
46734673
exceptions.InvalidAttributeException,
46744674
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
46754675
self.optimizely.get_variation,

Diff for: tests/test_user_context.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def test_decide__option__include_reasons__feature_test(self):
759759
'User "test_user" is in variation "control" of experiment test_experiment.'
760760
]
761761

762-
self.assertEquals(expected_reasons, actual.reasons)
762+
self.assertEqual(expected_reasons, actual.reasons)
763763

764764
def test_decide__option__include_reasons__feature_rollout(self):
765765
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
@@ -775,7 +775,7 @@ def test_decide__option__include_reasons__feature_rollout(self):
775775
'User "test_user" is in the traffic group of targeting rule 1.'
776776
]
777777

778-
self.assertEquals(expected_reasons, actual.reasons)
778+
self.assertEqual(expected_reasons, actual.reasons)
779779

780780
def test_decide__option__enabled_flags_only(self):
781781
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
@@ -1135,7 +1135,7 @@ def test_decide_reasons__hit_everyone_else_rule__fails_bucketing(self):
11351135
'Bucketed into an empty traffic range. Returning nil.'
11361136
]
11371137

1138-
self.assertEquals(expected_reasons, actual.reasons)
1138+
self.assertEqual(expected_reasons, actual.reasons)
11391139

11401140
def test_decide_reasons__hit_everyone_else_rule(self):
11411141
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
@@ -1156,7 +1156,7 @@ def test_decide_reasons__hit_everyone_else_rule(self):
11561156
'User "abcde" meets conditions for targeting rule "Everyone Else".'
11571157
]
11581158

1159-
self.assertEquals(expected_reasons, actual.reasons)
1159+
self.assertEqual(expected_reasons, actual.reasons)
11601160

11611161
def test_decide_reasons__hit_rule2__fails_bucketing(self):
11621162
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
@@ -1179,7 +1179,7 @@ def test_decide_reasons__hit_rule2__fails_bucketing(self):
11791179
'Bucketed into an empty traffic range. Returning nil.'
11801180
]
11811181

1182-
self.assertEquals(expected_reasons, actual.reasons)
1182+
self.assertEqual(expected_reasons, actual.reasons)
11831183

11841184
def test_decide_reasons__hit_user_profile_service(self):
11851185
user_id = 'test_user'
@@ -1215,7 +1215,7 @@ def save(self, user_profile):
12151215
expected_reasons = [('Returning previously activated variation ID "control" of experiment '
12161216
'"test_experiment" for user "test_user" from user profile.')]
12171217

1218-
self.assertEquals(expected_reasons, actual.reasons)
1218+
self.assertEqual(expected_reasons, actual.reasons)
12191219

12201220
def test_decide_reasons__forced_variation(self):
12211221
user_id = 'test_user'
@@ -1232,7 +1232,7 @@ def test_decide_reasons__forced_variation(self):
12321232
expected_reasons = [('Variation "control" is mapped to experiment '
12331233
'"test_experiment" and user "test_user" in the forced variation map')]
12341234

1235-
self.assertEquals(expected_reasons, actual.reasons)
1235+
self.assertEqual(expected_reasons, actual.reasons)
12361236

12371237
def test_decide_reasons__whitelisted_variation(self):
12381238
user_id = 'user_1'
@@ -1246,4 +1246,4 @@ def test_decide_reasons__whitelisted_variation(self):
12461246

12471247
expected_reasons = ['User "user_1" is forced in variation "control".']
12481248

1249-
self.assertEquals(expected_reasons, actual.reasons)
1249+
self.assertEqual(expected_reasons, actual.reasons)

0 commit comments

Comments
 (0)