Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: run_tests.py

Issue 1451373002: Updating mozdownload (excluding tests) (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/mozdownload@master
Patch Set: Updated README.md Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pylama.ini ('k') | setup.cfg » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: run_tests.py
diff --git a/run_tests.py b/run_tests.py
new file mode 100755
index 0000000000000000000000000000000000000000..97c40441a712bbac213d7283c23957c38a46f0f0
--- /dev/null
+++ b/run_tests.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import shutil
+from subprocess import check_call
+import sys
+import urllib2
+import zipfile
+
+# Link to the folder which contains the zip archives of virtualenv
+URL_VIRTUALENV = 'https://codeload.github.com/pypa/virtualenv/zip/'
+VERSION_VIRTUALENV = '1.9.1'
+
+DIR_BASE = os.path.abspath(os.path.dirname(__file__))
+DIR_ENV = os.path.join(DIR_BASE, 'tmp', 'venv')
+DIR_TMP = os.path.join(DIR_BASE, 'tmp')
+
+REQ_TXT = os.path.join('tests', 'requirements.txt')
+
+
+def download(url, target):
+ """Downloads the specified url to the given target."""
+ response = urllib2.urlopen(url)
+ with open(target, 'wb') as f:
+ f.write(response.read())
+ return target
+
+
+# see http://stackoverflow.com/questions/12332975/installing-python-module-within-code
+def install(package, version):
+ package_arg = "%s==%s" % (package, version)
+ check_call(['pip', 'install', '--upgrade', package_arg])
+
+
+def python(*args):
+ pypath = [os.path.join(DIR_ENV, 'bin', 'python')]
+ check_call(pypath + list(args))
+
+
+try:
+ # Remove potentially pre-existing tmp_dir
+ shutil.rmtree(DIR_TMP, True)
+ # Start out clean
+ os.makedirs(DIR_TMP)
+
+ print 'Downloading virtualenv %s' % VERSION_VIRTUALENV
+ virtualenv_file = download(URL_VIRTUALENV + VERSION_VIRTUALENV,
+ os.path.join(DIR_TMP, 'virtualenv.zip'))
+ virtualenv_zip = zipfile.ZipFile(virtualenv_file)
+ virtualenv_zip.extractall(DIR_TMP)
+ virtualenv_zip.close()
+
+ print 'Creating new virtual environment'
+ virtualenv_script = os.path.join(DIR_TMP,
+ 'virtualenv-%s' % VERSION_VIRTUALENV,
+ 'virtualenv.py')
+ check_call(['python', virtualenv_script, DIR_ENV])
+
+ print 'Activating virtual environment'
+ # for more info see:
+ # http://www.virtualenv.org/en/latest/#using-virtualenv-without-bin-python
+ if sys.platform == 'win32':
+ activate_this_file = os.path.join(DIR_ENV, 'Scripts',
+ 'activate_this.py')
+ else:
+ activate_this_file = os.path.join(DIR_ENV, 'bin',
+ 'activate_this.py')
+
+ if not os.path.isfile(activate_this_file):
+ # create venv
+ check_call(['virtualenv', '--no-site-packages', DIR_ENV])
+
+ execfile(activate_this_file, dict(__file__=activate_this_file))
+ print "Virtual environment activated successfully."
+
+except:
+ print "Could not activate virtual environment."
+ print "Exiting."
+ sys.exit(1)
+
+
+# Install dependent packages
+check_call(['pip', 'install', '--upgrade', '-r', REQ_TXT])
+
+# Install mozdownload
+python('setup.py', 'develop')
+
+# run the tests
+python(os.path.join('tests', 'test.py'))
+
+# Clean up
+shutil.rmtree(DIR_TMP)
« no previous file with comments | « pylama.ini ('k') | setup.cfg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698