Bug 1061982 - manifestparser changes to support conditional subsuites, r=jmaher

This commit is contained in:
Jonathan Griffin 2014-09-05 10:44:22 -07:00
parent 71484f95ca
commit bc92b3c074
3 changed files with 84 additions and 2 deletions

View File

@ -1105,10 +1105,34 @@ class TestManifest(ManifestParser):
"""
- exists : return only existing tests
- disabled : whether to return disabled tests
- tags : keys and values to filter on (e.g. `os = linux mac`)
- options: an optparse or argparse options object, used for subsuites
- values : keys and values to filter on (e.g. `os = linux mac`)
"""
tests = [i.copy() for i in self.tests] # shallow copy
# Conditional subsuites are specified using:
# subsuite = foo,condition
# where 'foo' is the subsuite name, and 'condition' is the same type of
# condition used for skip-if. If the condition doesn't evaluate to true,
# the subsuite designation will be removed from the test.
#
# Look for conditional subsuites, and replace them with the subsuite itself
# (if the condition is true), or nothing.
for test in tests:
subsuite = test.get('subsuite')
if ',' in subsuite:
try:
subsuite, condition = subsuite.split(',')
except ValueError:
raise ParseError("subsuite condition can't contain commas")
# strip any comments from the condition
condition = condition.split('#')[0]
matched = parse(condition, **values)
if matched:
test['subsuite'] = subsuite
else:
test['subsuite'] = ''
# Filter on current subsuite
if options:
if options.subsuite:

View File

@ -0,0 +1,13 @@
[test1]
subsuite=bar,foo=="bar" # this has a comment
[test2]
subsuite=bar,foo=="bar"
[test3]
subsuite=baz
[test4]
[test5]
[test6]
subsuite=bar,foo=="szy" || foo=="bar"

View File

@ -4,7 +4,7 @@ import os
import shutil
import tempfile
import unittest
from manifestparser import TestManifest
from manifestparser import TestManifest, ParseError
here = os.path.dirname(os.path.abspath(__file__))
@ -57,6 +57,51 @@ class TestTestManifest(unittest.TestCase):
names = [i['name'] for i in manifest.tests]
self.assertFalse('test_0202_app_launch_apply_update_dirlocked.js' in names)
def test_manifest_subsuites(self):
"""
test subsuites and conditional subsuites
"""
class AttributeDict(dict):
def __getattr__(self, attr):
return self[attr]
def __setattr__(self, attr, value):
self[attr] = value
relative_path = os.path.join(here, 'subsuite.ini')
manifest = TestManifest(manifests=(relative_path,))
info = {'foo': 'bar'}
options = {'subsuite': 'bar'}
# 6 tests total
self.assertEquals(len(manifest.active_tests(exists=False, **info)), 6)
# only 3 tests for subsuite bar when foo==bar
self.assertEquals(len(manifest.active_tests(exists=False,
options=AttributeDict(options),
**info)), 3)
options = {'subsuite': 'baz'}
other = {'something': 'else'}
# only 1 test for subsuite baz, regardless of conditions
self.assertEquals(len(manifest.active_tests(exists=False,
options=AttributeDict(options),
**info)), 1)
self.assertEquals(len(manifest.active_tests(exists=False,
options=AttributeDict(options),
**other)), 1)
# 4 tests match when the condition doesn't match (all tests except
# the unconditional subsuite)
info = {'foo': 'blah'}
options = {'subsuite': None}
self.assertEquals(len(manifest.active_tests(exists=False,
options=AttributeDict(options),
**info)), 5)
# test for illegal subsuite value
manifest.tests[0]['subsuite'] = 'subsuite=bar,foo=="bar",type="nothing"'
self.assertRaises(ParseError, manifest.active_tests, exists=False,
options=AttributeDict(options), **info)
if __name__ == '__main__':
unittest.main()