зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1312520 - Add an option to the manifestparser to prevent defaults from propagating to individual section definitions. r=ahal
Consumers will be expected to process defaults themselves through the "manifest_defaults" member variable instead. MozReview-Commit-ID: IGnOj3zEJfE
This commit is contained in:
Родитель
223cc662a8
Коммит
47d22a4d61
|
@ -8,8 +8,8 @@ __all__ = ['read_ini']
|
|||
|
||||
|
||||
def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
||||
comments=';#', separators=('=', ':'),
|
||||
strict=True):
|
||||
comments=';#', separators=('=', ':'), strict=True,
|
||||
handle_defaults=True):
|
||||
"""
|
||||
read an .ini file and return a list of [(section, values)]
|
||||
- fp : file pointer or path to read
|
||||
|
@ -19,6 +19,7 @@ def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
|||
- comments : characters that if they start a line denote a comment
|
||||
- separators : strings that denote key, value separation in order
|
||||
- strict : whether to be strict about parsing
|
||||
- handle_defaults : whether to incorporate defaults into each section
|
||||
"""
|
||||
|
||||
# variables
|
||||
|
@ -111,8 +112,12 @@ def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
|||
if defaults_only:
|
||||
return [(default, variables)]
|
||||
|
||||
# interpret the variables
|
||||
# Interpret the variables in the context of inherited defaults if
|
||||
# requested.
|
||||
def interpret_variables(global_dict, local_dict):
|
||||
if not handle_defaults:
|
||||
return local_dict
|
||||
|
||||
variables = global_dict.copy()
|
||||
|
||||
# These variables are combinable when they appear both in default
|
||||
|
|
|
@ -46,7 +46,7 @@ class ManifestParser(object):
|
|||
"""read .ini manifests"""
|
||||
|
||||
def __init__(self, manifests=(), defaults=None, strict=True, rootdir=None,
|
||||
finder=None):
|
||||
finder=None, handle_defaults=True):
|
||||
"""Creates a ManifestParser from the given manifest files.
|
||||
|
||||
:param manifests: An iterable of file paths or file objects corresponding
|
||||
|
@ -66,6 +66,10 @@ class ManifestParser(object):
|
|||
interactions. Finder objects are part of the mozpack package,
|
||||
documented at
|
||||
http://gecko.readthedocs.org/en/latest/python/mozpack.html#module-mozpack.files
|
||||
:param handle_defaults: If not set, do not propagate manifest defaults to individual
|
||||
test objects. Callers are expected to manage per-manifest
|
||||
defaults themselves via the manifest_defaults member
|
||||
variable in this case.
|
||||
"""
|
||||
self._defaults = defaults or {}
|
||||
self._ancestor_defaults = {}
|
||||
|
@ -75,6 +79,7 @@ class ManifestParser(object):
|
|||
self.rootdir = rootdir
|
||||
self.relativeRoot = None
|
||||
self.finder = finder
|
||||
self._handle_defaults = handle_defaults
|
||||
if manifests:
|
||||
self.read(*manifests)
|
||||
|
||||
|
@ -139,7 +144,8 @@ class ManifestParser(object):
|
|||
rootdir = self.rootdir + os.path.sep
|
||||
|
||||
# read the configuration
|
||||
sections = read_ini(fp=fp, variables=defaults, strict=self.strict)
|
||||
sections = read_ini(fp=fp, variables=defaults, strict=self.strict,
|
||||
handle_defaults=self._handle_defaults)
|
||||
self.manifest_defaults[filename] = defaults
|
||||
|
||||
parent_section_found = False
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[DEFAULT]
|
||||
support-files = foo.js # a comment
|
||||
|
||||
[test1]
|
||||
[test2]
|
||||
[test7]
|
||||
[test8]
|
||||
support-files = bar.js # another comment
|
||||
[test3]
|
||||
[test9]
|
||||
foo = bar
|
||||
|
||||
|
|
|
@ -42,14 +42,56 @@ class TestDefaultSupportFiles(unittest.TestCase):
|
|||
default = os.path.join(here, 'default-suppfiles.ini')
|
||||
parser = ManifestParser(manifests=(default,))
|
||||
expected_supp_files = {
|
||||
'test1': 'foo.js # a comment',
|
||||
'test2': 'foo.js bar.js ',
|
||||
'test3': 'foo.js # a comment',
|
||||
'test7': 'foo.js # a comment',
|
||||
'test8': 'foo.js bar.js ',
|
||||
'test9': 'foo.js # a comment',
|
||||
}
|
||||
for test in parser.tests:
|
||||
expected = expected_supp_files[test['name']]
|
||||
self.assertEqual(test['support-files'], expected)
|
||||
|
||||
|
||||
class TestOmitDefaults(unittest.TestCase):
|
||||
"""Tests passing omit-defaults prevents defaults from propagating to definitions.
|
||||
"""
|
||||
|
||||
def test_defaults(self):
|
||||
manifests = (os.path.join(here, 'default-suppfiles.ini'),
|
||||
os.path.join(here, 'default-skipif.ini'))
|
||||
parser = ManifestParser(manifests=manifests, handle_defaults=False)
|
||||
expected_supp_files = {
|
||||
'test8': 'bar.js # another comment',
|
||||
}
|
||||
expected_skip_ifs = {
|
||||
'test1': "debug",
|
||||
'test2': "os == 'linux'",
|
||||
'test3': "os == 'win'",
|
||||
'test4': "os == 'win' && debug",
|
||||
'test6': "debug # a second pesky comment",
|
||||
}
|
||||
for test in parser.tests:
|
||||
for field, expectations in (('support-files', expected_supp_files),
|
||||
('skip-if', expected_skip_ifs)):
|
||||
expected = expectations.get(test['name'])
|
||||
if not expected:
|
||||
self.assertNotIn(field, test)
|
||||
else:
|
||||
self.assertEqual(test[field], expected)
|
||||
|
||||
expected_defaults = {
|
||||
os.path.join(here, 'default-suppfiles.ini'): {
|
||||
"support-files": "foo.js # a comment",
|
||||
},
|
||||
os.path.join(here, 'default-skipif.ini'): {
|
||||
"skip-if": "os == 'win' && debug # a pesky comment",
|
||||
},
|
||||
}
|
||||
for path, defaults in expected_defaults.items():
|
||||
self.assertIn(path, parser.manifest_defaults)
|
||||
actual_defaults = parser.manifest_defaults[path]
|
||||
for key, value in defaults.items():
|
||||
self.assertIn(key, actual_defaults)
|
||||
self.assertEqual(value, actual_defaults[key])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче