Skip to content

Commit

Permalink
Address nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Ng committed May 31, 2017
1 parent 6d5c461 commit b4de51c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 6 additions & 5 deletions optimizely/project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ def __init__(self, datafile, logger, error_handler):
for feature in self.feature_key_map.values():
feature.variables = self._generate_key_map(feature.variables, 'key', entities.Variable)

# check if any of the experiments are in a group and add the group id for faster bucketing later on
# Check if any of the experiments are in a group and add the group id for faster bucketing later on
for exp_id in feature.experimentIds:
experiment_in_feature = self.experiment_id_map[exp_id]
if experiment_in_feature.groupId:
feature.groupId = experiment_in_feature.groupId
break # experiments in feature can only belong to one mutex group
# Experiments in feature can only belong to one mutex group
break

self.parsing_succeeded = True

Expand Down Expand Up @@ -421,13 +422,13 @@ def get_variable_value_for_variation(self, variable, variation):
return None

if variation.id not in self.variation_variable_usage_map:
self.logger.log(enums.LogLevels.ERROR, 'Variation with id "%s" is not in the datafile.' % variation.id)
self.logger.log(enums.LogLevels.ERROR, 'Variation with ID "%s" is not in the datafile.' % variation.id)
return None

# get all variable usages for the given variation
# Get all variable usages for the given variation
variable_usages = self.variation_variable_usage_map[variation.id]

# find usage in given variation
# Find usage in given variation
variable_usage = variable_usages[variable.id]

value = self._get_typecast_value(variable_usage.value, variable.type)
Expand Down
2 changes: 1 addition & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def setUp(self):
'projectId': '111001'
}

# stripped down datafile (used for testing features-related methods currently)
# datafile version 4
self.config_dict_with_features = {
'revision': '1',
'accountId': '12001',
Expand Down
14 changes: 8 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,9 @@ def test_init__with_v4_datafile(self):
'number_of_days': entities.Variable('129', 'number_of_days', 'integer', '192'),
'significance_value': entities.Variable('130', 'significance_value', 'double', '0.00098')
}),
'test_feature_2': entities.Feature('91112', 'test_feature_2', [], '211111', {'number_of_projects': entities.Variable('131', 'number_of_projects', 'integer', '10')}),
'test_feature_2': entities.Feature('91112', 'test_feature_2', [], '211111', {
'number_of_projects': entities.Variable('131', 'number_of_projects', 'integer', '10')
}),
'test_feature_in_group': entities.Feature('91113', 'test_feature_in_group', ['32222'], '', {}, '19228')
}

Expand Down Expand Up @@ -1125,7 +1127,7 @@ def test_get_feature_from_key__valid_feature_key(self):
project_config = optimizely_instance.config

expected_feature = entities.Feature('91112', 'test_feature_2', [], '211111', {})
self.assertEquals(expected_feature, project_config.get_feature_from_key('test_feature_2'))
self.assertEqual(expected_feature, project_config.get_feature_from_key('test_feature_2'))

def test_get_feature_from_key__invalid_feature_key(self):
""" Test that None is returned given an invalid feature key. """
Expand Down Expand Up @@ -1160,7 +1162,7 @@ def test_get_layer_from_id__valid_layer_id(self):
'id': '211129'
}]
}])
self.assertEquals(expected_layer, project_config.get_layer_from_id('211111'))
self.assertEqual(expected_layer, project_config.get_layer_from_id('211111'))

def test_get_variable_value_for_variation__returns_valid_value(self):
""" Test that the right value and type are returned. """
Expand All @@ -1170,8 +1172,8 @@ def test_get_variable_value_for_variation__returns_valid_value(self):
variation = project_config.get_variation_from_id('test_experiment', '111128')
is_working_variable = project_config.get_variable_for_feature('test_feature_1', 'is_working')
environment_variable = project_config.get_variable_for_feature('test_feature_1', 'environment')
self.assertEquals(False, project_config.get_variable_value_for_variation(is_working_variable, variation))
self.assertEquals('prod', project_config.get_variable_value_for_variation(environment_variable, variation))
self.assertEqual(False, project_config.get_variable_value_for_variation(is_working_variable, variation))
self.assertEqual('prod', project_config.get_variable_value_for_variation(environment_variable, variation))

def test_get_variable_value_for_variation__invalid_variable(self):
""" Test that an invalid variable key will return None. """
Expand All @@ -1196,7 +1198,7 @@ def test_get_variable_for_feature__returns_valid_variable(self):
project_config = optimizely_instance.config

variable = project_config.get_variable_for_feature('test_feature_1', 'is_working')
self.assertEquals(entities.Variable('127', 'is_working', 'boolean', 'true'), variable)
self.assertEqual(entities.Variable('127', 'is_working', 'boolean', 'true'), variable)

def test_get_variable_for_feature__invalid_feature_key(self):
""" Test that an invalid feature key will return None. """
Expand Down

0 comments on commit b4de51c

Please sign in to comment.