Skip to content

Commit 711e3c3

Browse files
committed
Fix lint issues
1 parent f15669d commit 711e3c3

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

optimizely/project_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ def __init__(self, datafile: str | bytes, logger: Logger, error_handler: Any):
9898
for holdout in self.holdouts:
9999
if holdout.get('status') != 'Running':
100100
continue
101-
101+
102102
holdout_id = holdout['id']
103103
self.holdout_id_map[holdout_id] = holdout
104-
104+
105105
included_flags = holdout.get('includedFlags')
106106
if not included_flags:
107107
# This is a global holdout
108108
self.global_holdouts[holdout_id] = holdout
109-
109+
110110
excluded_flags = holdout.get('excludedFlags')
111111
if excluded_flags:
112112
for flag_id in excluded_flags:

tests/test_config.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,15 +1380,14 @@ def test_get_variation_from_key_by_experiment_id_missing(self):
13801380
class HoldoutConfigTest(base.BaseTest):
13811381
def setUp(self):
13821382
base.BaseTest.setUp(self)
1383-
1383+
13841384
# Create config with holdouts
13851385
config_body_with_holdouts = self.config_dict_with_features.copy()
1386-
1386+
13871387
# Use correct feature flag IDs from the datafile
13881388
boolean_feature_id = '91111' # boolean_single_variable_feature
13891389
multi_variate_feature_id = '91114' # test_feature_in_experiment_and_rollout
1390-
string_feature_id = '91112' # test_feature_in_rollout
1391-
1390+
13921391
config_body_with_holdouts['holdouts'] = [
13931392
{
13941393
'id': 'holdout_1',
@@ -1412,63 +1411,63 @@ def setUp(self):
14121411
'excludedFlags': []
14131412
}
14141413
]
1415-
1414+
14161415
self.config_json_with_holdouts = json.dumps(config_body_with_holdouts)
14171416
opt_obj = optimizely.Optimizely(self.config_json_with_holdouts)
14181417
self.config_with_holdouts = opt_obj.config_manager.get_config()
14191418

14201419
def test_get_holdouts_for_flag__non_existent_flag(self):
14211420
""" Test that get_holdouts_for_flag returns empty array for non-existent flag. """
1422-
1421+
14231422
holdouts = self.config_with_holdouts.get_holdouts_for_flag('non_existent_flag')
14241423
self.assertEqual([], holdouts)
14251424

14261425
def test_get_holdouts_for_flag__returns_global_and_specific_holdouts(self):
14271426
""" Test that get_holdouts_for_flag returns global holdouts that do not exclude the flag
14281427
and specific holdouts that include the flag. """
1429-
1428+
14301429
holdouts = self.config_with_holdouts.get_holdouts_for_flag('test_feature_in_experiment_and_rollout')
14311430
self.assertEqual(2, len(holdouts))
1432-
1431+
14331432
global_holdout = next((h for h in holdouts if h['key'] == 'global_holdout'), None)
14341433
self.assertIsNotNone(global_holdout)
14351434
self.assertEqual('holdout_1', global_holdout['id'])
1436-
1435+
14371436
specific_holdout = next((h for h in holdouts if h['key'] == 'specific_holdout'), None)
14381437
self.assertIsNotNone(specific_holdout)
14391438
self.assertEqual('holdout_2', specific_holdout['id'])
14401439

14411440
def test_get_holdouts_for_flag__excludes_global_holdouts_for_excluded_flags(self):
14421441
""" Test that get_holdouts_for_flag does not return global holdouts that exclude the flag. """
1443-
1442+
14441443
holdouts = self.config_with_holdouts.get_holdouts_for_flag('boolean_single_variable_feature')
14451444
self.assertEqual(0, len(holdouts))
1446-
1445+
14471446
global_holdout = next((h for h in holdouts if h['key'] == 'global_holdout'), None)
14481447
self.assertIsNone(global_holdout)
14491448

14501449
def test_get_holdouts_for_flag__caches_results(self):
14511450
""" Test that get_holdouts_for_flag caches results for subsequent calls. """
1452-
1451+
14531452
holdouts1 = self.config_with_holdouts.get_holdouts_for_flag('test_feature_in_experiment_and_rollout')
14541453
holdouts2 = self.config_with_holdouts.get_holdouts_for_flag('test_feature_in_experiment_and_rollout')
1455-
1454+
14561455
# Should be the same object (cached)
14571456
self.assertIs(holdouts1, holdouts2)
14581457
self.assertEqual(2, len(holdouts1))
14591458

14601459
def test_get_holdouts_for_flag__returns_only_global_for_non_targeted_flags(self):
14611460
""" Test that get_holdouts_for_flag returns only global holdouts for flags not specifically targeted. """
1462-
1461+
14631462
holdouts = self.config_with_holdouts.get_holdouts_for_flag('test_feature_in_rollout')
1464-
1463+
14651464
# Should only include global holdout (not excluded and no specific targeting)
14661465
self.assertEqual(1, len(holdouts))
14671466
self.assertEqual('global_holdout', holdouts[0]['key'])
14681467

14691468
def test_get_holdout__returns_holdout_for_valid_id(self):
14701469
""" Test that get_holdout returns holdout when valid ID is provided. """
1471-
1470+
14721471
holdout = self.config_with_holdouts.get_holdout('holdout_1')
14731472
self.assertIsNotNone(holdout)
14741473
self.assertEqual('holdout_1', holdout['id'])
@@ -1477,7 +1476,7 @@ def test_get_holdout__returns_holdout_for_valid_id(self):
14771476

14781477
def test_get_holdout__returns_holdout_regardless_of_status(self):
14791478
""" Test that get_holdout returns holdout regardless of status when valid ID is provided. """
1480-
1479+
14811480
holdout = self.config_with_holdouts.get_holdout('holdout_2')
14821481
self.assertIsNotNone(holdout)
14831482
self.assertEqual('holdout_2', holdout['id'])
@@ -1486,52 +1485,52 @@ def test_get_holdout__returns_holdout_regardless_of_status(self):
14861485

14871486
def test_get_holdout__returns_none_for_non_existent_id(self):
14881487
""" Test that get_holdout returns None for non-existent holdout ID. """
1489-
1488+
14901489
holdout = self.config_with_holdouts.get_holdout('non_existent_holdout')
14911490
self.assertIsNone(holdout)
14921491

14931492
def test_get_holdout__logs_error_when_not_found(self):
14941493
""" Test that get_holdout logs error when holdout is not found. """
1495-
1494+
14961495
with mock.patch.object(self.config_with_holdouts, 'logger') as mock_logger:
14971496
result = self.config_with_holdouts.get_holdout('invalid_holdout_id')
1498-
1497+
14991498
self.assertIsNone(result)
15001499
mock_logger.error.assert_called_once_with('Holdout with ID "invalid_holdout_id" not found.')
15011500

15021501
def test_get_holdout__does_not_log_when_found(self):
15031502
""" Test that get_holdout does not log when holdout is found. """
1504-
1503+
15051504
with mock.patch.object(self.config_with_holdouts, 'logger') as mock_logger:
15061505
result = self.config_with_holdouts.get_holdout('holdout_1')
1507-
1506+
15081507
self.assertIsNotNone(result)
15091508
mock_logger.error.assert_not_called()
15101509

15111510
def test_holdout_initialization__categorizes_holdouts_properly(self):
15121511
""" Test that holdouts are properly categorized during initialization. """
1513-
1512+
15141513
self.assertIn('holdout_1', self.config_with_holdouts.holdout_id_map)
15151514
self.assertIn('holdout_2', self.config_with_holdouts.holdout_id_map)
15161515
self.assertIn('holdout_1', self.config_with_holdouts.global_holdouts)
1517-
1516+
15181517
# Use correct feature flag IDs
15191518
boolean_feature_id = '91111'
15201519
multi_variate_feature_id = '91114'
1521-
1520+
15221521
self.assertIn(multi_variate_feature_id, self.config_with_holdouts.included_holdouts)
15231522
self.assertTrue(len(self.config_with_holdouts.included_holdouts[multi_variate_feature_id]) > 0)
15241523
self.assertNotIn(boolean_feature_id, self.config_with_holdouts.included_holdouts)
1525-
1524+
15261525
self.assertIn(boolean_feature_id, self.config_with_holdouts.excluded_holdouts)
15271526
self.assertTrue(len(self.config_with_holdouts.excluded_holdouts[boolean_feature_id]) > 0)
15281527

15291528
def test_holdout_initialization__only_processes_running_holdouts(self):
15301529
""" Test that only running holdouts are processed during initialization. """
1531-
1530+
15321531
self.assertNotIn('holdout_3', self.config_with_holdouts.holdout_id_map)
15331532
self.assertNotIn('holdout_3', self.config_with_holdouts.global_holdouts)
1534-
1533+
15351534
boolean_feature_id = '91111'
15361535
included_for_boolean = self.config_with_holdouts.included_holdouts.get(boolean_feature_id)
15371536
self.assertIsNone(included_for_boolean)

0 commit comments

Comments
 (0)