Skip to content

Commit a3b46a2

Browse files
oakbanialiabbasrizvi
authored andcommitted
ci: Replace pep8 by flake8 and separate linting stage on Travis (#162)
1 parent a6709f2 commit a3b46a2

File tree

10 files changed

+29
-24
lines changed

10 files changed

+29
-24
lines changed

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ python:
88
- "pypy"
99
- "pypy3"
1010
install: "pip install -r requirements/core.txt;pip install -r requirements/test.txt"
11-
before_script: "pep8"
1211
addons:
1312
srcclr: true
1413
script: "nosetests --with-coverage --cover-package=optimizely"
1514
after_success:
1615
- coveralls
1716

18-
# Integration tests need to run first to reset the PR build status to pending
17+
# Linting and Integration tests need to run first to reset the PR build status to pending.
1918
stages:
19+
- 'Linting'
2020
- 'Integration tests'
2121
- 'Test'
2222

2323
jobs:
2424
include:
25-
- stage: 'Integration tests'
25+
- stage: 'Linting'
26+
language: python
27+
python: "2.7"
28+
install: "pip install flake8"
29+
script: "flake8"
30+
after_success: travis_terminate 0
31+
- stage: 'Integration Tests'
2632
merge_mode: replace
2733
env: SDK=python
2834
cache: false
2935
language: python
30-
before_install: skip
3136
install:
3237
- "pip install awscli"
3338
before_script:

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Pull request acceptance criteria
3737
Style
3838
-----
3939

40-
We enforce PEP-8 rules with a few minor `deviations`_.
40+
We enforce Flake8 rules with a few minor `deviations`_.
4141

4242
License
4343
-------

optimizely/helpers/condition.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, 2018, Optimizely
1+
# Copyright 2016, 2018-2019, 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
@@ -12,7 +12,6 @@
1212
# limitations under the License.
1313

1414
import json
15-
import numbers
1615

1716
from six import string_types
1817

optimizely/helpers/condition_tree_evaluator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018, Optimizely
1+
# Copyright 2018-2019, 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
@@ -86,6 +86,7 @@ def not_evaluator(conditions, leaf_evaluator):
8686
result = evaluate(conditions[0], leaf_evaluator)
8787
return None if result is None else not result
8888

89+
8990
EVALUATORS_BY_OPERATOR_TYPE = {
9091
ConditionOperatorTypes.AND: and_evaluator,
9192
ConditionOperatorTypes.OR: or_evaluator,

requirements/test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
coverage==4.0.3
2+
flake8==3.6.0
23
funcsigs==0.4
34
mock==1.3.0
45
nose==1.3.7
5-
pep8==1.7.0
66
python-coveralls==2.7.0
77
tabulate==0.7.5

tests/benchmarking/benchmarking_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, Optimizely
1+
# Copyright 2016, 2019, 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
@@ -231,5 +231,6 @@ def run_benchmarking_tests():
231231

232232
display_results(all_test_results_average, all_test_results_median)
233233

234+
234235
if __name__ == '__main__':
235236
run_benchmarking_tests()

tests/benchmarking/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, Optimizely
1+
# Copyright 2016, 2019, 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
@@ -3281,6 +3281,7 @@ def dispatch_event(url, params):
32813281

32823282
return optimizely.Optimizely(datafile, event_dispatcher=NoOpEventDispatcher)
32833283

3284+
32843285
optimizely_obj_10_exp = create_optimizely_object(json.dumps(datafiles.get(10)))
32853286
optimizely_obj_25_exp = create_optimizely_object(json.dumps(datafiles.get(25)))
32863287
optimizely_obj_50_exp = create_optimizely_object(json.dumps(datafiles.get(50)))

tests/helpers_tests/test_audience.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2018, Optimizely
1+
# Copyright 2016-2019, 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
@@ -14,7 +14,6 @@
1414
import json
1515
import mock
1616

17-
from optimizely import entities
1817
from optimizely import optimizely
1918
from optimizely.helpers import audience
2019
from tests import base
@@ -97,7 +96,7 @@ def test_is_user_in_experiment__returns_True__when_condition_tree_evaluator_retu
9796

9897
user_attributes = {'test_attribute': 'test_value_1'}
9998
experiment = self.project_config.get_experiment_from_key('test_experiment')
100-
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=True) as cond_tree_eval:
99+
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=True):
101100

102101
self.assertStrictTrue(audience.is_user_in_experiment(self.project_config, experiment, user_attributes))
103102

@@ -106,19 +105,18 @@ def test_is_user_in_experiment__returns_False__when_condition_tree_evaluator_ret
106105

107106
user_attributes = {'test_attribute': 'test_value_1'}
108107
experiment = self.project_config.get_experiment_from_key('test_experiment')
109-
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=None) as cond_tree_eval:
108+
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=None):
110109

111110
self.assertStrictFalse(audience.is_user_in_experiment(self.project_config, experiment, user_attributes))
112111

113-
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=False) as cond_tree_eval:
112+
with mock.patch('optimizely.helpers.condition_tree_evaluator.evaluate', return_value=False):
114113

115114
self.assertStrictFalse(audience.is_user_in_experiment(self.project_config, experiment, user_attributes))
116115

117116
def test_is_user_in_experiment__evaluates_audienceIds(self):
118117
""" Test that is_user_in_experiment correctly evaluates audience Ids and
119118
calls custom attribute evaluator for leaf nodes. """
120119

121-
user_attributes = {'test_attribute': 'test_value_1'}
122120
experiment = self.project_config.get_experiment_from_key('test_experiment')
123121
experiment.audienceIds = ['11154', '11159']
124122
experiment.audienceConditions = None

tests/test_optimizely.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ def on_custom_event(test_string):
372372

373373
def test_add_invalid_listener(self):
374374
""" Test adding a invalid listener """
375-
not_a_listener = "This is not a listener"
376375
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))
377376

378377
def test_add_multi_listener(self):
@@ -456,7 +455,7 @@ def test_track_listener_with_attr(self):
456455
with mock.patch('optimizely.decision_service.DecisionService.get_variation',
457456
return_value=self.project_config.get_variation_from_id(
458457
'test_experiment', '111128'
459-
)) as mock_get_variation, \
458+
)), \
460459
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event') as mock_dispatch, \
461460
mock.patch('optimizely.notification_center.NotificationCenter.send_notifications') as mock_event_tracked:
462461
self.optimizely.track('test_event', 'test_user', attributes={'test_attribute': 'test_value'})
@@ -471,7 +470,7 @@ def test_track_listener_with_attr_with_event_tags(self):
471470
with mock.patch('optimizely.decision_service.DecisionService.get_variation',
472471
return_value=self.project_config.get_variation_from_id(
473472
'test_experiment', '111128'
474-
)) as mock_get_variation, \
473+
)), \
475474
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event') as mock_dispatch, \
476475
mock.patch('optimizely.notification_center.NotificationCenter.send_notifications') as mock_event_tracked:
477476
self.optimizely.track('test_event', 'test_user', attributes={'test_attribute': 'test_value'},
@@ -506,7 +505,7 @@ def on_activate(experiment, user_id, attributes, variation, event):
506505
mock_variation,
507506
decision_service.DECISION_SOURCE_EXPERIMENT
508507
)) as mock_decision, \
509-
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event') as mock_dispatch_event, \
508+
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event'), \
510509
mock.patch('uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'), \
511510
mock.patch('time.time', return_value=42):
512511
self.assertTrue(opt_obj.is_feature_enabled('test_feature_in_experiment', 'test_user'))
@@ -2558,7 +2557,7 @@ def test_get_variation__whitelisted_user_forced_bucketing(self):
25582557
def test_get_variation__user_profile__forced_bucketing(self):
25592558
""" Test that the expected forced variation is called if a user profile exists """
25602559
with mock.patch('optimizely.decision_service.DecisionService.get_stored_variation',
2561-
return_value=entities.Variation('111128', 'control')) as mock_get_stored_variation:
2560+
return_value=entities.Variation('111128', 'control')):
25622561
self.assertTrue(self.optimizely.set_forced_variation('test_experiment', 'test_user', 'variation'))
25632562
self.assertEqual('variation', self.optimizely.get_forced_variation('test_experiment', 'test_user'))
25642563
variation_key = self.optimizely.get_variation('test_experiment',

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
[pep8]
1+
[flake8]
22
# E111 - indentation is not a multiple of four
33
# E114 - indentation is not a multiple of four (comment)
44
# E121 - continuation line indentation is not a multiple of four
55
# E127 - continuation line over-indented for visual indent
6-
ignore = E111,E114,E121,E127
6+
# E722 - do not use bare 'except'
7+
ignore = E111,E114,E121,E127, E722
78
exclude = optimizely/lib/pymmh3.py,*virtualenv*
89
max-line-length = 120

0 commit comments

Comments
 (0)