49
49
# Libraries that only work on Python 2.7
50
50
PY27_ONLY_LIBRARIES = ['mysql-python' ]
51
51
52
+ # Whether we're running on Travis CI
53
+ ON_TRAVIS = os .environ .get ('TRAVIS' , False )
54
+
52
55
53
56
def list_files (folder , pattern ):
54
57
"""Lists all files below the given folder that match the pattern."""
@@ -136,21 +139,14 @@ def setup_appengine(session):
136
139
137
140
def run_tests_in_sesssion (
138
141
session , interpreter , sample_directories , use_appengine = True ,
139
- skip_flaky = False , changed_only = False ):
142
+ skip_flaky = False ):
140
143
"""This is the main function for executing tests.
141
144
142
145
It:
143
146
1. Install the common testing utilities.
144
147
2. Installs the test requirements.
145
148
3. Determines which pytest arguments to use. skip_flaky causes extra
146
149
arguments to be passed that will skip tests marked flaky.
147
- 4. If posargs are specified, it will use that as the list of samples to
148
- test.
149
- 5. If posargs is not specified, it will gather the list of samples by
150
- walking the repository tree.
151
- 6. If changed_only was specified, it'll use Travis environment variables
152
- to figure out which samples should be tested based on which files
153
- were changed.
154
150
7. For each sample directory, it runs py.test.
155
151
"""
156
152
session .interpreter = interpreter
@@ -165,13 +161,6 @@ def run_tests_in_sesssion(
165
161
if skip_flaky :
166
162
pytest_args .append ('-m not slow and not flaky' )
167
163
168
- if changed_only :
169
- changed_files = get_changed_files ()
170
- sample_directories = filter_samples (
171
- sample_directories , changed_files )
172
- print ('Running tests on a subset of samples: ' )
173
- print ('\n ' .join (sample_directories ))
174
-
175
164
for sample in sample_directories :
176
165
# Ignore lib and env directories
177
166
ignore_args = [
@@ -211,28 +200,62 @@ def session_gae(session):
211
200
def session_travis (session , subsession ):
212
201
"""On travis, just run with python3.4 and don't run slow or flaky tests."""
213
202
if subsession == 'tests' :
203
+ interpreter = 'python3.4'
214
204
sample_directories = collect_sample_dirs (
215
205
'.' , set ('./appengine/standard' ))
216
- run_tests_in_sesssion (
217
- session , 'python3.4' , sample_directories ,
218
- skip_flaky = True , changed_only = True )
219
- else :
206
+ elif subsession == 'gae' :
207
+ interpreter = 'python2.7'
220
208
sample_directories = collect_sample_dirs ('appengine/standard' )
221
- run_tests_in_sesssion (
222
- session , 'python2.7' , sample_directories ,
223
- skip_flaky = True , changed_only = True )
209
+
210
+ changed_files = get_changed_files ()
211
+ sample_directories = filter_samples (
212
+ sample_directories , changed_files )
213
+
214
+ if not sample_directories :
215
+ print ('No samples changed.' )
216
+ return
217
+
218
+ print ('Running tests on a subset of samples: ' )
219
+ print ('\n ' .join (sample_directories ))
220
+
221
+ run_tests_in_sesssion (
222
+ session , interpreter , sample_directories ,
223
+ skip_flaky = True , changed_only = True )
224
224
225
225
226
226
def session_lint (session ):
227
227
"""Lints each sample."""
228
+ sample_directories = session .posargs
229
+ if not sample_directories :
230
+ sample_directories = collect_sample_dirs ('.' )
231
+
232
+ # On travis, on lint changed samples.
233
+ if ON_TRAVIS :
234
+ changed_files = get_changed_files ()
235
+ sample_directories = filter_samples (
236
+ sample_directories , changed_files )
237
+
228
238
session .install ('flake8' , 'flake8-import-order' )
229
- session .run (
230
- 'flake8' , '--builtin=gettext' , '--max-complexity=15' ,
231
- '--import-order-style=google' ,
232
- '--exclude' ,
233
- 'container_engine/django_tutorial/polls/migrations/*,.nox,.cache,env,'
234
- 'lib' ,
235
- * (session .posargs or ['.' ]))
239
+
240
+ for sample_directory in sample_directories :
241
+ # Determine local import names
242
+ local_names = [
243
+ basename
244
+ for basename , extension
245
+ in [os .path .splitext (path ) for path
246
+ in os .listdir (sample_directory )]
247
+ if extension == '.py' or os .path .isdir (
248
+ os .path .join (sample_directory , basename ))]
249
+
250
+ session .run (
251
+ 'flake8' ,
252
+ '--show-source' ,
253
+ '--builtin' , 'gettext' ,
254
+ '--max-complexity' , '15' ,
255
+ '--import-order-style' , 'google' ,
256
+ '--exclude' , '.nox,.cache,env,lib' ,
257
+ '--application-import-names' , ',' .join (local_names ),
258
+ sample_directory )
236
259
237
260
238
261
def session_reqcheck (session ):
0 commit comments