Skip to content

Removing deprecated warnings #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions optimizely/event/event_processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2020 Optimizely
# Copyright 2019-2021 Optimizely
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(
@property
def is_running(self):
""" Property to check if consumer thread is alive or not. """
return self.executor.isAlive() if self.executor else False
return self.executor.is_alive() if self.executor else False

def _validate_instantiation_props(self, prop, prop_name, default_value):
""" Method to determine if instantiation properties like batch_size, flush_interval
Expand Down
8 changes: 7 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2020, Optimizely
# Copyright 2016-2021, Optimizely
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -22,6 +22,12 @@
def long(a):
raise NotImplementedError('Tests should only call `long` if running in PY2')

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


class BaseTest(unittest.TestCase):
def assertStrictTrue(self, to_assert):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019, Optimizely
# Copyright 2016-2019, 2021, Optimizely
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def setUp(self):
def test_get_experiment_from_key__invalid_key(self):
""" Test that exception is raised when provided experiment key is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidExperimentException,
enums.Errors.INVALID_EXPERIMENT_KEY,
self.project_config.get_experiment_from_key,
Expand All @@ -1127,14 +1127,14 @@ def test_get_experiment_from_key__invalid_key(self):
def test_get_audience__invalid_id(self):
""" Test that message is logged when provided audience ID is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidAudienceException, enums.Errors.INVALID_AUDIENCE, self.project_config.get_audience, '42',
)

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

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidExperimentException,
enums.Errors.INVALID_EXPERIMENT_KEY,
self.project_config.get_variation_from_key,
Expand All @@ -1145,7 +1145,7 @@ def test_get_variation_from_key__invalid_experiment_key(self):
def test_get_variation_from_key__invalid_variation_key(self):
""" Test that exception is raised when provided variation key is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidVariationException,
enums.Errors.INVALID_VARIATION,
self.project_config.get_variation_from_key,
Expand All @@ -1156,7 +1156,7 @@ def test_get_variation_from_key__invalid_variation_key(self):
def test_get_variation_from_id__invalid_experiment_key(self):
""" Test that exception is raised when provided experiment key is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidExperimentException,
enums.Errors.INVALID_EXPERIMENT_KEY,
self.project_config.get_variation_from_id,
Expand All @@ -1167,7 +1167,7 @@ def test_get_variation_from_id__invalid_experiment_key(self):
def test_get_variation_from_id__invalid_variation_id(self):
""" Test that exception is raised when provided variation ID is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidVariationException,
enums.Errors.INVALID_VARIATION,
self.project_config.get_variation_from_key,
Expand All @@ -1178,7 +1178,7 @@ def test_get_variation_from_id__invalid_variation_id(self):
def test_get_event__invalid_key(self):
""" Test that exception is raised when provided event key is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidEventException,
enums.Errors.INVALID_EVENT_KEY,
self.project_config.get_event,
Expand All @@ -1188,7 +1188,7 @@ def test_get_event__invalid_key(self):
def test_get_attribute_id__invalid_key(self):
""" Test that exception is raised when provided attribute key is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidAttributeException,
enums.Errors.INVALID_ATTRIBUTE,
self.project_config.get_attribute_id,
Expand All @@ -1198,7 +1198,7 @@ def test_get_attribute_id__invalid_key(self):
def test_get_group__invalid_id(self):
""" Test that exception is raised when provided group ID is invalid. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidGroupException, enums.Errors.INVALID_GROUP_ID, self.project_config.get_group, '42',
)

Expand Down
22 changes: 11 additions & 11 deletions tests/test_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2020, Optimizely
# Copyright 2019-2021, Optimizely
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -32,7 +32,7 @@ def test_init__invalid_logger_fails(self):
class InvalidLogger(object):
pass

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException, 'Provided "logger" is in an invalid format.',
):
config_manager.StaticConfigManager(logger=InvalidLogger())
Expand All @@ -43,7 +43,7 @@ def test_init__invalid_error_handler_fails(self):
class InvalidErrorHandler(object):
pass

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException, 'Provided "error_handler" is in an invalid format.',
):
config_manager.StaticConfigManager(error_handler=InvalidErrorHandler())
Expand All @@ -54,7 +54,7 @@ def test_init__invalid_notification_center_fails(self):
class InvalidNotificationCenter(object):
pass

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException, 'Provided "notification_center" is in an invalid format.',
):
config_manager.StaticConfigManager(notification_center=InvalidNotificationCenter())
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_get_config_blocks(self):
class PollingConfigManagerTest(base.BaseTest):
def test_init__no_sdk_key_no_url__fails(self, _):
""" Test that initialization fails if there is no sdk_key or url provided. """
self.assertRaisesRegexp(
self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException,
'Must provide at least one of sdk_key or url.',
config_manager.PollingConfigManager,
Expand All @@ -232,7 +232,7 @@ def test_init__no_sdk_key_no_url__fails(self, _):

def test_get_datafile_url__no_sdk_key_no_url_raises(self, _):
""" Test that get_datafile_url raises exception if no sdk_key or url is provided. """
self.assertRaisesRegexp(
self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException,
'Must provide at least one of sdk_key or url.',
config_manager.PollingConfigManager.get_datafile_url,
Expand All @@ -244,7 +244,7 @@ def test_get_datafile_url__no_sdk_key_no_url_raises(self, _):
def test_get_datafile_url__invalid_url_template_raises(self, _):
""" Test that get_datafile_url raises if url_template is invalid. """
# No url_template provided
self.assertRaisesRegexp(
self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException,
'Invalid url_template None provided',
config_manager.PollingConfigManager.get_datafile_url,
Expand All @@ -255,7 +255,7 @@ def test_get_datafile_url__invalid_url_template_raises(self, _):

# Incorrect url_template provided
test_url_template = 'invalid_url_template_without_sdk_key_field_{key}'
self.assertRaisesRegexp(
self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException,
'Invalid url_template {} provided'.format(test_url_template),
config_manager.PollingConfigManager.get_datafile_url,
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_set_update_interval(self, _):
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')

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

# Assert that if invalid blocking_timeout is set, then exception is raised.
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException, 'Invalid blocking timeout "invalid timeout" provided.',
):
project_config_manager.set_blocking_timeout('invalid timeout')
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_is_running(self, _):
class AuthDatafilePollingConfigManagerTest(base.BaseTest):
def test_init__datafile_access_token_none__fails(self, _):
""" Test that initialization fails if datafile_access_token is None. """
self.assertRaisesRegexp(
self.assertRaisesRegex(
optimizely_exceptions.InvalidInputException,
'datafile_access_token cannot be empty or None.',
config_manager.AuthDatafilePollingConfigManager,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -4633,7 +4633,7 @@ def setUp(self):
def test_activate__with_attributes__invalid_attributes(self):
""" Test that activate raises exception if attributes are in invalid format. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidAttributeException,
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
self.optimizely.activate,
Expand All @@ -4645,7 +4645,7 @@ def test_activate__with_attributes__invalid_attributes(self):
def test_track__with_attributes__invalid_attributes(self):
""" Test that track raises exception if attributes are in invalid format. """

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidAttributeException,
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
self.optimizely.track,
Expand All @@ -4657,7 +4657,7 @@ def test_track__with_attributes__invalid_attributes(self):
def test_track__with_event_tag__invalid_event_tag(self):
""" Test that track raises exception if event_tag is in invalid format. """

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

self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.InvalidAttributeException,
enums.Errors.INVALID_ATTRIBUTE_FORMAT,
self.optimizely.get_variation,
Expand Down
16 changes: 8 additions & 8 deletions tests/test_user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def test_decide__option__include_reasons__feature_test(self):
'User "test_user" is in variation "control" of experiment test_experiment.'
]

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

def test_decide__option__enabled_flags_only(self):
opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
Expand Down Expand Up @@ -1135,7 +1135,7 @@ def test_decide_reasons__hit_everyone_else_rule__fails_bucketing(self):
'Bucketed into an empty traffic range. Returning nil.'
]

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)

def test_decide_reasons__whitelisted_variation(self):
user_id = 'user_1'
Expand All @@ -1246,4 +1246,4 @@ def test_decide_reasons__whitelisted_variation(self):

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

self.assertEquals(expected_reasons, actual.reasons)
self.assertEqual(expected_reasons, actual.reasons)