Skip to content

Commit

Permalink
Use pip to download requests and webtests and address the rest of the…
Browse files Browse the repository at this point in the history
… comments
  • Loading branch information
KaptenJansson committed Oct 5, 2016
1 parent 6978031 commit 1c89d07
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 111 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
*.pyc
.DS_Store
browser*
/src/web_app/js/enums.js
bower_components
browser*
firefox*
temp/*
node_modules
out
secrets.json
temp/*
validation-report.json
validation-status.json
/src/web_app/js/enums.js
19 changes: 2 additions & 17 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ module.exports = function(grunt) {
getPythonTestDeps: {
command: 'python build/get_python_test_deps.py'
},
installPythonTestDepsOnLinux: {
command: 'python build/install_webtest_on_linux.py temp/webtest-master/'
},
runPythonTests: {
command: ['python', 'build/run_python_tests.py',
'temp/google_appengine/', out_app_engine_dir,
'temp/webtest-master/'].join(' ')
'temp/google_appengine/', out_app_engine_dir].join(' ')
},
buildAppEnginePackage: {
command: ['python', './build/build_app_engine_package.py', 'src',
Expand Down Expand Up @@ -125,15 +121,6 @@ module.exports = function(grunt) {
}
},

jstdPhantom: {
options: {
useLatest : true,
port: 9876,
},
files: [
'build/js_test_driver.conf',
]},

closurecompiler: {
debug: {
files: {
Expand Down Expand Up @@ -183,9 +170,7 @@ module.exports = function(grunt) {
// Set default tasks to run when grunt is called without parameters.
grunt.registerTask('default', ['csslint', 'htmlhint', 'eslint',
'runPythonTests', 'build', 'runUnitTests']);
grunt.registerTask('travis', ['shell:getPythonTestDeps',
'shell:installPythonTestDepsOnLinux',
'default']);
grunt.registerTask('travis', ['shell:getPythonTestDeps', 'default']);
grunt.registerTask('runPythonTests', ['shell:getPythonTestDeps',
'shell:buildAppEnginePackageWithTests',
'shell:runPythonTests',
Expand Down
85 changes: 17 additions & 68 deletions build/get_python_test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
import os
import re
import sys
import tarfile
import urllib2
import zipfile
import pip


GAE_DOWNLOAD_URL = 'https://storage.googleapis.com/appengine-sdks/featured/'
GAE_UPDATECHECK_URL = 'https://appengine.google.com/api/updatecheck'
WEBTEST_URL = 'https://nodeload.github.com/Pylons/webtest/tar.gz/master'
REQUESTS_URL = 'https://github.com/kennethreitz/requests/tarball/master'
TEMP_DIR = 'temp'

def setUpTempDir():
if not os.path.exists(TEMP_DIR):
os.mkdir(TEMP_DIR)

os.chdir(TEMP_DIR)

def _GetLatestAppEngineSdkVersion():
response = urllib2.urlopen(GAE_UPDATECHECK_URL)
Expand All @@ -45,81 +36,39 @@ def _Download(url, to):
to_file.write(response.read())


def _Unzip(path):
def _Unzip(path, dir):
print 'Unzipping %s in %s...' % (path, os.getcwd())
zip_file = zipfile.ZipFile(path)
try:
zip_file.extractall()
zip_file.extractall(dir)
finally:
zip_file.close()


def _Untar(path):
print 'Untarring %s in %s...' % (path, os.getcwd())
tar_file = tarfile.open(path, 'r:gz')
try:
tar_file.extractall()
finally:
dir_name = tar_file.getnames()
tar_file.close()
# Return the first member in the returned list as it's the top dir
# name. Useful for passing on the top/first output dir name to other
# functions.
return dir_name[0]

# Installs the requests python module.
def _InstallRequests(requests_dir):
cwd = os.getcwd()
try:
print 'About to install requests module into your system python.'
os.chdir(requests_dir)
result = os.system('sudo python setup.py install')
if result == 0:
print 'Install successful.'
else:
return ('Failed to install requests; are you missing setuptools / '
'easy_install in your system python?')
finally:
os.chdir(cwd)
def Install(package):
pip.main(['install' , package])
print 'Installing python package using pip: ' + package


def DownloadAppEngineSdkIfNecessary():
gae_sdk_version = _GetLatestAppEngineSdkVersion()
gae_sdk_file = 'google_appengine_%s.zip' % gae_sdk_version
if os.path.exists(gae_sdk_file):
print 'Already has %s, skipping' % gae_sdk_file
return

_Download(GAE_DOWNLOAD_URL + gae_sdk_file, gae_sdk_file)
_Unzip(gae_sdk_file)
temp_dir = 'temp/'
if not os.path.exists(temp_dir):
os.mkdir(temp_dir)


def DownloadWebTestIfNecessary():
webtest_file = 'webtest-master.tar.gz'
if os.path.exists(webtest_file):
print 'Already has %s, skipping' % webtest_file
if os.path.exists(temp_dir + gae_sdk_file):
print 'Already has %s, skipping' % gae_sdk_file
return

_Download(WEBTEST_URL, webtest_file)
_Untar(webtest_file)

# Downloads the requests python module used to download other deps.
def DownloadRequestsIfNecessary():
request_file = 'requestsPythonModule'
if 'requests' in sys.modules or os.path.exists(request_file):
print 'Already has %s, skipping' % request_file
# return

_Download(REQUESTS_URL, request_file )
untarred_dir_name = _Untar(request_file)

_InstallRequests(untarred_dir_name)

_Download(GAE_DOWNLOAD_URL + gae_sdk_file, temp_dir + gae_sdk_file)
_Unzip(temp_dir + gae_sdk_file, temp_dir)

def main():
setUpTempDir()
Install('requests')
Install('WebTest')
DownloadAppEngineSdkIfNecessary()
DownloadWebTestIfNecessary()
DownloadRequestsIfNecessary()
# setUpTempDir()

if __name__ == '__main__':
sys.exit(main())
28 changes: 10 additions & 18 deletions build/run_python_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import sys
import unittest

USAGE = """%prog sdk_path test_path webtest_path
USAGE = """%prog sdk_path test_path
Run unit tests for App Engine apps.
sdk_path Path to the SDK installation.
test_path Path to package containing test modules.
webtest_path Path to the webtest library."""
test_path Path to package containing test modules."""


def _WebTestIsInstalled():
Expand All @@ -19,28 +18,21 @@ def _WebTestIsInstalled():
return True
except ImportError:
print 'You need to install webtest dependencies before you can proceed '
print 'running the tests. To do this you need to get easy_install since '
print 'that is how webtest provisions its dependencies.'
print 'See https://pythonhosted.org/setuptools/easy_install.html.'
print 'Then:'
print 'cd webtest-master'
print 'python setup.py install'
print '(Prefix with sudo / run in admin shell as necessary).'
print 'running the tests. To do this you need to have pip installed.'
print 'Go to https://packaging.python.org/installing/ and follow the '
print 'instructions and then rerun the grunt command.'
return False


def main(sdk_path, test_path, webtest_path):
def main(sdk_path, test_path):
if not os.path.exists(sdk_path):
return 'Missing %s: try grunt shell:getPythonTestDeps.' % sdk_path
if not os.path.exists(test_path):
return 'Missing %s: try grunt build.' % test_path
if not os.path.exists(webtest_path):
return 'Missing %s: try grunt shell:getPythonTestDeps.' % webtest_path

sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
sys.path.append(webtest_path)
if not _WebTestIsInstalled():
return 1
suite = unittest.loader.TestLoader().discover(test_path,
Expand All @@ -52,8 +44,8 @@ def main(sdk_path, test_path, webtest_path):
if __name__ == '__main__':
parser = optparse.OptionParser(USAGE)
options, args = parser.parse_args()
if len(args) != 3:
parser.error('Error: Exactly 3 arguments required.')
if len(args) != 2:
parser.error('Error: Exactly 2 arguments required.')

sdk_path, test_path, webtest_path = args[0:3]
sys.exit(main(sdk_path, test_path, webtest_path))
sdk_path, test_path = args[0:2]
sys.exit(main(sdk_path, test_path))
7 changes: 3 additions & 4 deletions src/web_app/js/appcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,9 @@ AppController.prototype.setIconTimeout_ = function() {
if (this.hideIconsAfterTimeout) {
window.clearTimeout.bind(this, this.hideIconsAfterTimeout);
}
this.hideIconsAfterTimeout =
window.setTimeout(function() {
this.hideIcons_();
}.bind(this), 5000);
this.hideIconsAfterTimeout = window.setTimeout(function() {
this.hideIcons_();
}.bind(this), 5000);
};

AppController.prototype.iconEventSetup_ = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/web_app/js/appcontroller_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
Expand Down

0 comments on commit 1c89d07

Please sign in to comment.