зеркало из https://github.com/mozilla/gecko-dev.git
Bug 708309 - Do not use zipfile.extract in mozbase components for peptest r=jhammel a=test-only
This commit is contained in:
Родитель
4b2598e457
Коммит
ee2dd7102f
|
@ -4,7 +4,7 @@ Universal manifests for Mozilla test harnesses
|
|||
|
||||
What ManifestDestiny gives you:
|
||||
|
||||
* manifests are (ordered) lists of tests
|
||||
* manifests are ordered lists of tests
|
||||
* tests may have an arbitrary number of key, value pairs
|
||||
* the parser returns an ordered list of test data structures, which
|
||||
are just dicts with some keys. For example, a test with no
|
||||
|
@ -23,6 +23,14 @@ additional key, value metadata to each test.
|
|||
|
||||
# Why have test manifests?
|
||||
|
||||
It is desirable to have a unified format for test manifests for testing
|
||||
[mozilla-central](http://hg.mozilla.org/mozilla-central), etc.
|
||||
|
||||
* It is desirable to be able to selectively enable or disable tests based on platform or other conditions. This should be easy to do. Currently, since many of the harnesses just crawl directories, there is no effective way of disabling a test except for removal from mozilla-central
|
||||
* It is desriable to do this in a universal way so that enabling and disabling tests as well as other tasks are easily accessible to a wider audience than just those intimately familiar with the specific test framework.
|
||||
* It is desirable to have other metadata on top of the test. For instance, let's say a test is marked as skipped. It would be nice to give the reason why.
|
||||
|
||||
|
||||
Most Mozilla test harnesses work by crawling a directory structure.
|
||||
While this is straight-forward, manifests offer several practical
|
||||
advantages::
|
||||
|
@ -37,8 +45,8 @@ advantages::
|
|||
removing it from the tree and a bug filed with the appropriate
|
||||
reason:
|
||||
|
||||
[test_broken.js]
|
||||
disabled = https://bugzilla.mozilla.org/show_bug.cgi?id=123456
|
||||
[test_broken.js]
|
||||
disabled = https://bugzilla.mozilla.org/show_bug.cgi?id=123456
|
||||
|
||||
* ability to run different (subsets of) tests on different
|
||||
platforms. Traditionally, we've done a bit of magic or had the test
|
||||
|
@ -46,8 +54,8 @@ advantages::
|
|||
can mark what platforms a test will or will not run on and change
|
||||
these without changing the test.
|
||||
|
||||
[test_works_on_windows_only.js]
|
||||
run-if = os == 'win'
|
||||
[test_works_on_windows_only.js]
|
||||
run-if = os == 'win'
|
||||
|
||||
* ability to markup tests with metadata. We have a large, complicated,
|
||||
and always changing infrastructure. key, value metadata may be used
|
||||
|
@ -65,32 +73,32 @@ advantages::
|
|||
Manifests are .ini file with the section names denoting the path
|
||||
relative to the manifest:
|
||||
|
||||
[foo.js]
|
||||
[bar.js]
|
||||
[fleem.js]
|
||||
[foo.js]
|
||||
[bar.js]
|
||||
[fleem.js]
|
||||
|
||||
The sections are read in order. In addition, tests may include
|
||||
arbitrary key, value metadata to be used by the harness. You may also
|
||||
have a `[DEFAULT]` section that will give key, value pairs that will
|
||||
be inherited by each test unless overridden:
|
||||
|
||||
[DEFAULT]
|
||||
type = restart
|
||||
[DEFAULT]
|
||||
type = restart
|
||||
|
||||
[lilies.js]
|
||||
color = white
|
||||
[lilies.js]
|
||||
color = white
|
||||
|
||||
[daffodils.js]
|
||||
color = yellow
|
||||
type = other
|
||||
# override type from DEFAULT
|
||||
[daffodils.js]
|
||||
color = yellow
|
||||
type = other
|
||||
# override type from DEFAULT
|
||||
|
||||
[roses.js]
|
||||
color = red
|
||||
[roses.js]
|
||||
color = red
|
||||
|
||||
You can also include other manifests:
|
||||
|
||||
[include:subdir/anothermanifest.ini]
|
||||
[include:subdir/anothermanifest.ini]
|
||||
|
||||
Manifests are included relative to the directory of the manifest with
|
||||
the `[include:]` directive unless they are absolute paths.
|
||||
|
@ -109,7 +117,7 @@ terms).
|
|||
|
||||
This data corresponds to a one-line manifest:
|
||||
|
||||
[testToolbar/testBackForwardButtons.js]
|
||||
[testToolbar/testBackForwardButtons.js]
|
||||
|
||||
If additional key, values were specified, they would be in this dict
|
||||
as well.
|
||||
|
@ -128,13 +136,13 @@ integration layer. This should allow whatever sort of logic is
|
|||
desired. For instance, if in yourtestharness you wanted to run only on
|
||||
mondays for a certain class of tests:
|
||||
|
||||
tests = []
|
||||
for test in manifests.tests:
|
||||
if 'runOnDay' in test:
|
||||
if calendar.day_name[calendar.weekday(*datetime.datetime.now().timetuple()[:3])].lower() == test['runOnDay'].lower():
|
||||
tests.append(test)
|
||||
else:
|
||||
tests.append(test)
|
||||
tests = []
|
||||
for test in manifests.tests:
|
||||
if 'runOnDay' in test:
|
||||
if calendar.day_name[calendar.weekday(*datetime.datetime.now().timetuple()[:3])].lower() == test['runOnDay'].lower():
|
||||
tests.append(test)
|
||||
else:
|
||||
tests.append(test)
|
||||
|
||||
To recap:
|
||||
* the manifests allow you to specify test data
|
||||
|
@ -146,7 +154,7 @@ http://hg.mozilla.org/automation/ManifestDestiny/file/tip/manifestdestiny/tests/
|
|||
|
||||
Additional manifest files may be included with an `[include:]` directive:
|
||||
|
||||
[include:path-to-additional-file.manifest]
|
||||
[include:path-to-additional-file.manifest]
|
||||
|
||||
The path to included files is relative to the current manifest.
|
||||
|
||||
|
@ -183,7 +191,7 @@ in particular.
|
|||
|
||||
A test harness will normally call `TestManifest.active_tests`:
|
||||
|
||||
def active_tests(self, exists=True, disabled=True, **tags):
|
||||
def active_tests(self, exists=True, disabled=True, **tags):
|
||||
|
||||
The manifests are passed to the `__init__` or `read` methods with
|
||||
appropriate arguments. `active_tests` then allows you to select the
|
||||
|
@ -216,7 +224,7 @@ files. Run `manifestparser help create` for usage information.
|
|||
|
||||
To copy tests and manifests from a source:
|
||||
|
||||
manifestparser [options] copy from_manifest to_directory -tag1 -tag2 --key1=value1 key2=value2 ...
|
||||
manifestparser [options] copy from_manifest to_directory -tag1 -tag2 --key1=value1 key2=value2 ...
|
||||
|
||||
|
||||
# Upating Tests
|
||||
|
@ -224,7 +232,81 @@ To copy tests and manifests from a source:
|
|||
To update the tests associated with with a manifest from a source
|
||||
directory:
|
||||
|
||||
manifestparser [options] update manifest from_directory -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
manifestparser [options] update manifest from_directory -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
|
||||
|
||||
# Usage example
|
||||
|
||||
Here is an example of how to create manifests for a directory tree and
|
||||
update the tests listed in the manifests from an external source.
|
||||
|
||||
## Creating Manifests
|
||||
|
||||
Let's say you want to make a series of manifests for a given directory structure containing `.js` test files:
|
||||
|
||||
testing/mozmill/tests/firefox/
|
||||
testing/mozmill/tests/firefox/testAwesomeBar/
|
||||
testing/mozmill/tests/firefox/testPreferences/
|
||||
testing/mozmill/tests/firefox/testPrivateBrowsing/
|
||||
testing/mozmill/tests/firefox/testSessionStore/
|
||||
testing/mozmill/tests/firefox/testTechnicalTools/
|
||||
testing/mozmill/tests/firefox/testToolbar/
|
||||
testing/mozmill/tests/firefox/restartTests
|
||||
|
||||
You can use `manifestparser create` to do this:
|
||||
|
||||
$ manifestparser help create
|
||||
Usage: manifestparser.py [options] create directory <directory> <...>
|
||||
|
||||
create a manifest from a list of directories
|
||||
|
||||
Options:
|
||||
-p PATTERN, --pattern=PATTERN
|
||||
glob pattern for files
|
||||
-i IGNORE, --ignore=IGNORE
|
||||
directories to ignore
|
||||
-w IN_PLACE, --in-place=IN_PLACE
|
||||
Write .ini files in place; filename to write to
|
||||
|
||||
We only want `.js` files and we want to skip the `restartTests` directory.
|
||||
We also want to write a manifest per directory, so I use the `--in-place`
|
||||
option to write the manifests:
|
||||
|
||||
manifestparser create . -i restartTests -p '*.js' -w manifest.ini
|
||||
|
||||
This creates a manifest.ini per directory that we care about with the JS test files:
|
||||
|
||||
testing/mozmill/tests/firefox/manifest.ini
|
||||
testing/mozmill/tests/firefox/testAwesomeBar/manifest.ini
|
||||
testing/mozmill/tests/firefox/testPreferences/manifest.ini
|
||||
testing/mozmill/tests/firefox/testPrivateBrowsing/manifest.ini
|
||||
testing/mozmill/tests/firefox/testSessionStore/manifest.ini
|
||||
testing/mozmill/tests/firefox/testTechnicalTools/manifest.ini
|
||||
testing/mozmill/tests/firefox/testToolbar/manifest.ini
|
||||
|
||||
The top-level `manifest.ini` merely has `[include:]` references to the sub manifests:
|
||||
|
||||
[include:testAwesomeBar/manifest.ini]
|
||||
[include:testPreferences/manifest.ini]
|
||||
[include:testPrivateBrowsing/manifest.ini]
|
||||
[include:testSessionStore/manifest.ini]
|
||||
[include:testTechnicalTools/manifest.ini]
|
||||
[include:testToolbar/manifest.ini]
|
||||
|
||||
Each sub-level manifest contains the (`.js`) test files relative to it.
|
||||
|
||||
## Updating the tests from manifests
|
||||
|
||||
You may need to update tests as given in manifests from a different source directory.
|
||||
`manifestparser update` was made for just this purpose:
|
||||
|
||||
Usage: manifestparser [options] update manifest directory -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
|
||||
update the tests as listed in a manifest from a directory
|
||||
|
||||
To update from a directory of tests in `~/mozmill/src/mozmill-tests/firefox/` run:
|
||||
|
||||
manifestparser update manifest.ini ~/mozmill/src/mozmill-tests/firefox/
|
||||
|
||||
|
||||
# Tests
|
||||
|
@ -252,20 +334,20 @@ Run `manifestparser help` for usage information.
|
|||
|
||||
To create a manifest from a set of directories:
|
||||
|
||||
manifestparser [options] create directory <directory> <...> [create-options]
|
||||
manifestparser [options] create directory <directory> <...> [create-options]
|
||||
|
||||
To output a manifest of tests:
|
||||
|
||||
manifestparser [options] write manifest <manifest> <...> -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
manifestparser [options] write manifest <manifest> <...> -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
|
||||
To copy tests and manifests from a source:
|
||||
|
||||
manifestparser [options] copy from_manifest to_manifest -tag1 -tag2 --key1=value1 key2=value2 ...
|
||||
manifestparser [options] copy from_manifest to_manifest -tag1 -tag2 --key1=value1 key2=value2 ...
|
||||
|
||||
To update the tests associated with with a manifest from a source
|
||||
directory:
|
||||
|
||||
manifestparser [options] update manifest from_directory -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
manifestparser [options] update manifest from_directory -tag1 -tag2 --key1=value1 --key2=value2 ...
|
||||
|
||||
|
||||
# Design Considerations
|
||||
|
@ -309,6 +391,14 @@ through several design considerations.
|
|||
installation.
|
||||
|
||||
|
||||
# Developing ManifestDestiny
|
||||
|
||||
ManifestDestiny is developed and maintained by Mozilla's
|
||||
[Automation and Testing Team](https://wiki.mozilla.org/Auto-tools).
|
||||
The project page is located at
|
||||
https://wiki.mozilla.org/Auto-tools/Projects/ManifestDestiny .
|
||||
|
||||
|
||||
# Historical Reference
|
||||
|
||||
Date-ordered list of links about how manifests came to be where they are today::
|
||||
|
|
|
@ -3,6 +3,7 @@ from devicemanager import DeviceManager, DMError
|
|||
import re
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
class DeviceManagerADB(DeviceManager):
|
||||
|
||||
|
@ -13,6 +14,7 @@ class DeviceManagerADB(DeviceManager):
|
|||
self.retries = 0
|
||||
self._sock = None
|
||||
self.useRunAs = False
|
||||
self.useZip = False
|
||||
self.packageName = None
|
||||
if packageName == None:
|
||||
if os.getenv('USER'):
|
||||
|
@ -30,6 +32,10 @@ class DeviceManagerADB(DeviceManager):
|
|||
except:
|
||||
self.useRunAs = False
|
||||
self.packageName = None
|
||||
try:
|
||||
self.verifyZip()
|
||||
except:
|
||||
self.useZip = False
|
||||
try:
|
||||
# a test to see if we have root privs
|
||||
files = self.listFiles("/data/data")
|
||||
|
@ -103,31 +109,41 @@ class DeviceManagerADB(DeviceManager):
|
|||
def pushDir(self, localDir, remoteDir):
|
||||
# adb "push" accepts a directory as an argument, but if the directory
|
||||
# contains symbolic links, the links are pushed, rather than the linked
|
||||
# files; we push file-by-file to get around this limitation
|
||||
# files; we either zip/unzip or push file-by-file to get around this
|
||||
# limitation
|
||||
try:
|
||||
if (not self.dirExists(remoteDir)):
|
||||
self.mkDirs(remoteDir+"/x")
|
||||
for root, dirs, files in os.walk(localDir, followlinks='true'):
|
||||
relRoot = os.path.relpath(root, localDir)
|
||||
for file in files:
|
||||
localFile = os.path.join(root, file)
|
||||
remoteFile = remoteDir + "/"
|
||||
if (relRoot!="."):
|
||||
remoteFile = remoteFile + relRoot + "/"
|
||||
remoteFile = remoteFile + file
|
||||
self.pushFile(localFile, remoteFile)
|
||||
for dir in dirs:
|
||||
targetDir = remoteDir + "/"
|
||||
if (relRoot!="."):
|
||||
targetDir = targetDir + relRoot + "/"
|
||||
targetDir = targetDir + dir
|
||||
if (not self.dirExists(targetDir)):
|
||||
self.mkDir(targetDir)
|
||||
if (self.useZip):
|
||||
localZip = tempfile.mktemp()+".zip"
|
||||
remoteZip = remoteDir + "/adbdmtmp.zip"
|
||||
subprocess.check_output(["zip", "-r", localZip, '.'], cwd=localDir)
|
||||
self.pushFile(localZip, remoteZip)
|
||||
os.remove(localZip)
|
||||
self.checkCmdAs(["shell", "unzip", "-o", remoteZip, "-d", remoteDir])
|
||||
self.checkCmdAs(["shell", "rm", remoteZip])
|
||||
else:
|
||||
if (not self.dirExists(remoteDir)):
|
||||
self.mkDirs(remoteDir+"/x")
|
||||
for root, dirs, files in os.walk(localDir, followlinks='true'):
|
||||
relRoot = os.path.relpath(root, localDir)
|
||||
for file in files:
|
||||
localFile = os.path.join(root, file)
|
||||
remoteFile = remoteDir + "/"
|
||||
if (relRoot!="."):
|
||||
remoteFile = remoteFile + relRoot + "/"
|
||||
remoteFile = remoteFile + file
|
||||
self.pushFile(localFile, remoteFile)
|
||||
for dir in dirs:
|
||||
targetDir = remoteDir + "/"
|
||||
if (relRoot!="."):
|
||||
targetDir = targetDir + relRoot + "/"
|
||||
targetDir = targetDir + dir
|
||||
if (not self.dirExists(targetDir)):
|
||||
self.mkDir(targetDir)
|
||||
self.checkCmdAs(["shell", "chmod", "777", remoteDir])
|
||||
return True
|
||||
return remoteDir
|
||||
except:
|
||||
print "pushing " + localDir + " to " + remoteDir + " failed"
|
||||
return False
|
||||
return None
|
||||
|
||||
# external function
|
||||
# returns:
|
||||
|
@ -241,11 +257,25 @@ class DeviceManagerADB(DeviceManager):
|
|||
acmd = ["shell", "am","start"]
|
||||
cmd = ' '.join(cmd).strip()
|
||||
i = cmd.find(" ")
|
||||
# SUT identifies the URL by looking for :\\ -- another strategy to consider
|
||||
re_url = re.compile('^[http|file|chrome|about].*')
|
||||
last = cmd.rfind(" ")
|
||||
uri = ""
|
||||
args = ""
|
||||
if re_url.match(cmd[last:].strip()):
|
||||
args = cmd[i:last].strip()
|
||||
uri = cmd[last:].strip()
|
||||
else:
|
||||
args = cmd[i:].strip()
|
||||
acmd.append("-n")
|
||||
acmd.append(cmd[0:i] + "/.App")
|
||||
acmd.append("--es")
|
||||
acmd.append("args")
|
||||
acmd.append(cmd[i:])
|
||||
if args != "":
|
||||
acmd.append("args")
|
||||
acmd.append(args)
|
||||
if uri != "":
|
||||
acmd.append("-d")
|
||||
acmd.append(''.join(['\'',uri, '\'']));
|
||||
print acmd
|
||||
self.checkCmd(acmd)
|
||||
return outputFile;
|
||||
|
@ -578,3 +608,25 @@ class DeviceManagerADB(DeviceManager):
|
|||
self.checkCmd(["shell", "rm", devroot + "/tmp/tmpfile"])
|
||||
self.checkCmd(["shell", "run-as", packageName, "rm", "-r", devroot + "/sanity"])
|
||||
|
||||
def isUnzipAvailable(self):
|
||||
data = self.runCmd(["shell", "unzip"]).stdout.read()
|
||||
if (re.search('Usage', data)):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def isLocalZipAvailable(self):
|
||||
try:
|
||||
subprocess.check_call(["zip", "-?"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
|
||||
def verifyZip(self):
|
||||
# If "zip" can be run locally, and "unzip" can be run remotely, then pushDir
|
||||
# can use these to push just one file per directory -- a significant
|
||||
# optimization for large directories.
|
||||
self.useZip = False
|
||||
if (self.isUnzipAvailable() and self.isLocalZipAvailable()):
|
||||
print "will use zip to push directories"
|
||||
self.useZip = True
|
||||
|
|
|
@ -110,31 +110,51 @@ def _extract(path, extdir=None, delete=False):
|
|||
If delete is set to True, deletes the bundle at path
|
||||
Returns the list of top level files that were extracted
|
||||
"""
|
||||
assert not os.path.isfile(extdir), "extdir cannot be a file"
|
||||
if extdir is None:
|
||||
extdir = os.path.dirname(path)
|
||||
elif not os.path.isdir(extdir):
|
||||
os.makedirs(extdir)
|
||||
if zipfile.is_zipfile(path):
|
||||
bundle = zipfile.ZipFile(path)
|
||||
namelist = bundle.namelist()
|
||||
if hasattr(bundle, 'extractall'):
|
||||
bundle.extractall(path=extdir)
|
||||
# zipfile.extractall doesn't exist in Python 2.5
|
||||
else:
|
||||
for name in namelist:
|
||||
filename = os.path.realpath(os.path.join(extdir, name))
|
||||
if name.endswith("/"):
|
||||
os.makedirs(filename)
|
||||
else:
|
||||
path = os.path.dirname(filename)
|
||||
if not os.path.isdir(path):
|
||||
os.makedirs(path)
|
||||
dest = open(filename, "wb")
|
||||
dest.write(bundle.read(name))
|
||||
dest.close()
|
||||
elif tarfile.is_tarfile(path):
|
||||
bundle = tarfile.open(path)
|
||||
namelist = bundle.getnames()
|
||||
if hasattr(bundle, 'extractall'):
|
||||
bundle.extractall(path=extdir)
|
||||
# tarfile.extractall doesn't exist in Python 2.4
|
||||
else:
|
||||
for name in namelist:
|
||||
bundle.extract(name, path=extdir)
|
||||
else:
|
||||
return
|
||||
if extdir is None:
|
||||
extdir = os.path.dirname(path)
|
||||
elif not os.path.exists(extdir):
|
||||
os.makedirs(extdir)
|
||||
bundle.extractall(path=extdir)
|
||||
bundle.close()
|
||||
if delete:
|
||||
os.remove(path)
|
||||
# namelist returns paths with forward slashes even in windows
|
||||
top_level_files = [os.path.join(extdir, name) for name in namelist
|
||||
if len(name.rstrip('/').split('/')) == 1]
|
||||
# namelist doesn't include folders in windows, append these to the list
|
||||
if mozinfo.isWin:
|
||||
for name in namelist:
|
||||
root = name[:name.find('/')]
|
||||
if root not in top_level_files:
|
||||
top_level_files.append(root)
|
||||
# namelist doesn't include folders, append these to the list
|
||||
for name in namelist:
|
||||
root = os.path.join(extdir, name[:name.find('/')])
|
||||
if root not in top_level_files:
|
||||
top_level_files.append(root)
|
||||
return top_level_files
|
||||
|
||||
def _install_dmg(src, dest):
|
||||
|
|
|
@ -100,10 +100,12 @@ TestSuite.prototype.loadTest = function(test) {
|
|||
log.log('TEST-END', test.name + ' ' + runTime + fThreshold);
|
||||
} catch (e) {
|
||||
log.error(test.name + ' | ' + e);
|
||||
log.debug(test.name + ' | Traceback:');
|
||||
lines = e.stack.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
log.debug('\t' + lines[i]);
|
||||
if (e['stack'] !== undefined) {
|
||||
log.debug(test.name + ' | Traceback:');
|
||||
lines = e.stack.split('\n');
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
log.debug('\t' + lines[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
from mozprocess import ProcessHandler
|
||||
from pepresults import Results
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
import mozlog
|
||||
import os
|
||||
|
||||
|
@ -57,6 +59,13 @@ class PepProcess(ProcessHandler):
|
|||
self.logger = mozlog.getLogger('PEP')
|
||||
results.fails[str(None)] = []
|
||||
|
||||
def waitForQuit(self, timeout=5):
|
||||
for i in range(1, timeout):
|
||||
if self.proc.returncode != None:
|
||||
return
|
||||
sleep(1)
|
||||
self.proc.kill()
|
||||
|
||||
def processOutputLine(self, line):
|
||||
"""
|
||||
Callback called on each line of output
|
||||
|
@ -68,6 +77,11 @@ class PepProcess(ProcessHandler):
|
|||
# The output is generated from the Peptest extension
|
||||
# Format is 'PEP <LEVEL> <MSG>' where <MSG> can have multiple tokens
|
||||
# The content of <MSG> depends on the <LEVEL>
|
||||
if line.find('Test Suite Finished') != -1:
|
||||
thread = Thread(target=self.waitForQuit)
|
||||
thread.setDaemon(True) # don't hang on quit
|
||||
thread.start()
|
||||
|
||||
level = tokens[1]
|
||||
if level == 'TEST-START':
|
||||
results.currentTest = tokens[2].rstrip()
|
||||
|
@ -81,11 +95,12 @@ class PepProcess(ProcessHandler):
|
|||
threshold = 0.0
|
||||
|
||||
msg = results.currentTest \
|
||||
+ ' | fail threshold: ' + str(threshold) \
|
||||
+ ' | metric: ' + str(metric)
|
||||
+ ' | fail threshold: ' + str(threshold)
|
||||
if metric > threshold:
|
||||
msg += ' < metric: ' + str(metric)
|
||||
self.logger.testFail(msg)
|
||||
else:
|
||||
msg += ' >= metric: ' + str(metric)
|
||||
self.logger.testPass(msg)
|
||||
|
||||
self.logger.testEnd(
|
||||
|
|
|
@ -68,25 +68,53 @@ def isURL(path):
|
|||
def extract(path, extdir=None, delete=False):
|
||||
"""
|
||||
Takes in a tar or zip file and extracts it to extdir
|
||||
If extdir is not specified, extracts to path
|
||||
If extdir is not specified, extracts to os.path.dirname(path)
|
||||
If delete is set to True, deletes the bundle at path
|
||||
Returns the list of top level files that were extracted
|
||||
"""
|
||||
assert not os.path.isfile(extdir), "extdir cannot be a file"
|
||||
if extdir is None:
|
||||
extdir = os.path.dirname(path)
|
||||
elif not os.path.isdir(extdir):
|
||||
os.makedirs(extdir)
|
||||
if zipfile.is_zipfile(path):
|
||||
bundle = zipfile.ZipFile(path)
|
||||
namelist = bundle.namelist()
|
||||
if hasattr(bundle, 'extractall'):
|
||||
bundle.extractall(path=extdir)
|
||||
# zipfile.extractall doesn't exist in Python 2.5
|
||||
else:
|
||||
for name in namelist:
|
||||
filename = os.path.realpath(os.path.join(extdir, name))
|
||||
if name.endswith("/"):
|
||||
os.makedirs(filename)
|
||||
else:
|
||||
path = os.path.dirname(filename)
|
||||
if not os.path.isdir(path):
|
||||
os.makedirs(path)
|
||||
dest = open(filename, "wb")
|
||||
dest.write(bundle.read(name))
|
||||
dest.close()
|
||||
elif tarfile.is_tarfile(path):
|
||||
bundle = tarfile.open(path)
|
||||
namelist = bundle.getnames()
|
||||
if hasattr(bundle, 'extractall'):
|
||||
bundle.extractall(path=extdir)
|
||||
# tarfile.extractall doesn't exist in Python 2.4
|
||||
else:
|
||||
for name in namelist:
|
||||
bundle.extract(name, path=extdir)
|
||||
else:
|
||||
return
|
||||
if extdir is None:
|
||||
extdir = os.path.dirname(path)
|
||||
elif not os.path.exists(extdir):
|
||||
os.makedirs(extdir)
|
||||
bundle.extractall(path=extdir)
|
||||
bundle.close()
|
||||
if delete:
|
||||
os.remove(path)
|
||||
return [os.path.join(extdir, name) for name in namelist
|
||||
if len(name.rstrip(os.sep).split(os.sep)) == 1]
|
||||
# namelist returns paths with forward slashes even in windows
|
||||
top_level_files = [os.path.join(extdir, name) for name in namelist
|
||||
if len(name.rstrip('/').split('/')) == 1]
|
||||
# namelist doesn't include folders, append these to the list
|
||||
for name in namelist:
|
||||
root = os.path.join(extdir, name[:name.find('/')])
|
||||
if root not in top_level_files:
|
||||
top_level_files.append(root)
|
||||
return top_level_files
|
||||
|
|
|
@ -82,6 +82,7 @@ class Peptest():
|
|||
testObj = {}
|
||||
testObj['path'] = os.path.realpath(self.options.testPath)
|
||||
testObj['name'] = os.path.basename(self.options.testPath)
|
||||
testObj['here'] = os.path.dirname(testObj['path'])
|
||||
tests.append(testObj)
|
||||
else:
|
||||
# a test manifest was passed in
|
||||
|
|
|
@ -44,12 +44,15 @@ try:
|
|||
except IOError:
|
||||
description = ''
|
||||
|
||||
version = "0.0"
|
||||
version = "0.1"
|
||||
|
||||
dependencies = ['mozprofile',
|
||||
dependencies = ['ManifestDestiny',
|
||||
'mozhttpd',
|
||||
'mozlog',
|
||||
'mozprofile >= 0.1',
|
||||
'mozprocess',
|
||||
'mozrunner >= 3.0b3',
|
||||
'mozlog']
|
||||
]
|
||||
|
||||
setup(name='peptest',
|
||||
version=version,
|
||||
|
|
Загрузка…
Ссылка в новой задаче