-
Notifications
You must be signed in to change notification settings - Fork 76
Convert run_tests script to Python (#168) #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
261457c
4adcaaa
597b673
39d7cc9
6c40776
f5f34e8
cc8ee44
a1493ea
8909103
cd0fbc6
66be146
e0972d0
c25e63a
2610667
dd65331
8550419
f1bd987
05d5132
54ff092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ install: | |
- pip install pep8 | ||
before_script: | ||
- "pep8 mozdownload" | ||
script: ./run_tests.sh | ||
script: ./run_tests.py | ||
notifications: | ||
email: | ||
- [email protected] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the discussion came up a couple of times but I'm still behind that we should make sure that our applicatoin works and would not fail if e.g. permissions for files/folders to delete are not correct. So I'm highly in favor of using mozfile.remove(), which will make our code way more cleaner. I think we can live with the small extra depenency to mozfile very well. |
||
# 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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put this except higher in the code right after the code which could fail. Then you can exit with the right exit code via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will have to call sys.exit() with an appropriate error code here, so that we really exit the script at this point. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for mozfile.remove() |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
'mozlog>=1.3', | ||
'progressbar==2.2', | ||
'requests==1.2.2' | ||
] | ||
] | ||
|
||
setup(name='mozdownload', | ||
version=version, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ManifestDestiny==0.5.6 | ||
mozfile==1.1 | ||
mozhttpd==0.6 | ||
mozlog==1.3 | ||
moztest==0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we don't need 2 blank lines between global functions. That only applies to classes, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Separate top-level function and class definitions with two blank lines." - http://www.python.org/dev/peps/pep-0008/#blank-lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!