Skip to content

Commit

Permalink
Now cleaning tests from out folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Höglund committed Feb 18, 2015
1 parent ff6ad6b commit b6bd113
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ module.exports = function(grunt) {
buildAppEnginePackageWithTests: {
command: ['python', './build/build_app_engine_package.py', 'src',
out_app_engine_dir, '--include-tests'].join(' ')
},
removePythonTestsFromOutAppEngineDir: {
command: ['python', './build/remove_python_tests.py',
out_app_engine_dir].join(' ')
}
},

Expand Down Expand Up @@ -178,7 +182,8 @@ module.exports = function(grunt) {
'default']);
grunt.registerTask('runPythonTests', ['shell:buildAppEnginePackageWithTests',
'shell:getPythonTestDeps',
'shell:runPythonTests']);
'shell:runPythonTests',
'shell:removePythonTestsFromOutAppEngineDir']);
grunt.registerTask('jstests', ['closurecompiler:debug', 'jstdPhantom']);
// buildAppEnginePackage must be done before closurecompiler since buildAppEnginePackage resets out/app_engine.
grunt.registerTask('build', ['shell:buildAppEnginePackage', 'closurecompiler:debug', 'grunt-chrome-build']);
Expand Down
13 changes: 4 additions & 9 deletions build/build_app_engine_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import subprocess
import sys

import test_file_herder

USAGE = """%prog src_path dest_path
Build the GAE source code package.
Expand Down Expand Up @@ -96,14 +98,6 @@ def CopyApprtcSource(src_path, dest_path):
build_version_info_file(os.path.join(dest_path, 'version_info.json'))


def CopyTests(src_path, dest_path):
for dirpath, _, files in os.walk(src_path):
if dirpath.endswith('app_engine'):
tests = [name for name in files if 'test' in name]
for test in tests:
shutil.copy(os.path.join(dirpath, test), dest_path)


def main():
parser = optparse.OptionParser(USAGE)
parser.add_option("-t", "--include-tests", action="store_true",
Expand All @@ -115,7 +109,8 @@ def main():
src_path, dest_path = args[0:2]
CopyApprtcSource(src_path, dest_path)
if options.include_tests:
CopyTests(src_path, dest_path)
app_engine_code = os.path.join(src_path, 'app_engine')
test_file_herder.CopyTests(os.path.join(src_path, 'app_engine'), dest_path)


if __name__ == '__main__':
Expand Down
18 changes: 18 additions & 0 deletions build/remove_python_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/python

import optparse
import sys

import test_file_herder


def main():
parser = optparse.OptionParser('Usage: %prog path_to_tests')
_, args = parser.parse_args()
if len(args) != 1:
parser.error('Expected precisely one argument.')

return test_file_herder.RemoveTests(args[0])

if __name__ == '__main__':
sys.exit(main())
32 changes: 32 additions & 0 deletions build/test_file_herder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python

"""Copies and deletes tests."""

import os
import shutil


def _IsPythonTest(filename):
return 'test' in filename and filename.endswith('.py')


def CopyTests(src_path, dest_path):
if not os.path.exists(src_path):
raise Exception('Failed to copy tests from %s; does not exist.' % src_path)

for dirpath, _, files in os.walk(src_path):
tests = [name for name in files if _IsPythonTest(name)]
for test in tests:
shutil.copy(os.path.join(dirpath, test), dest_path)


def RemoveTests(path):
if not os.path.exists(path):
raise Exception('Failed to remove tests from %s; does not exist.' % path)

for dirpath, _, files in os.walk(path):
tests = [name for name in files if _IsPythonTest(name)]
for test in tests:
to_remove = os.path.join(dirpath, test)
print 'Removing %s.' % to_remove
os.remove(to_remove)

0 comments on commit b6bd113

Please sign in to comment.