Add support for snapshot testing.

User macro files passed on the command line allow a user to
override the defaults in configuration files to test new changes
in pending releases.

Fix macros issues with keys with more than one map.
This commit is contained in:
Chris Johns 2013-04-13 18:29:30 +10:00
parent 667255cb77
commit 0565e1fa4b
3 changed files with 62 additions and 43 deletions

View File

@ -239,8 +239,6 @@ class build:
# sources as these may be overridden by user loaded macros.
#
sources = package.sources()
for sm in self.macros.find('source[0-9]*'):
sources[sm] = [self.macros[sm]]
url = None
for s in sources:
tag = s[len('source'):]

View File

@ -103,42 +103,40 @@ class package:
self.config.macros[info] = '\n'.join(self.infos[info])
def get_info(self, info, expand = True):
if info in self.infos:
if info in self.config.macros:
_info = self.config.macros[info].split('\n')
if expand:
return self.config.expand(self.infos[info])
return self.config.expand(_info)
else:
return self.infos[info]
return _info
return None
def extract_info(self, label, expand = True):
ll = label.lower()
infos = {}
for i in self.infos:
il = i.lower()
if il.startswith(label):
if il == label:
il = label + '0'
elif not il[len(label):].isdigit():
continue
infos[il] = self.config.expand(self.infos[i])
keys = self.config.macros.find('%s.*' % (ll))
for k in keys:
if k == ll:
k = '%s0' % (ll)
elif not k[len(ll):].isdigit():
continue
infos[k] = [self.config.expand(self.config.macros[k])]
return infos
def find_info(self, label, expand = True):
for i in self.infos:
if i.lower() == label:
if expand:
return self.config.expand(self.infos[i])
else:
return self.infos[i]
def _find_macro(self, label, expand = True):
if label in self.config.macros:
macro = self.config.macros[label].split('\n')
if expand:
return self.config.expand(macro)
else:
return macro
return None
def find_info(self, label, expand = True):
return self._find_macro(label, expand)
def find_directive(self, label, expand = True):
for d in self.directives:
if d.lower() == label:
if expand:
return self.config.expand(self.directives[d])
else:
return self.directives[d]
return None
return self._find_macro(label, expand)
def name(self):
info = self.find_info('name')

View File

@ -118,11 +118,11 @@ class macros:
return text
def __iter__(self):
return macros.macro_iterator(self.macros[self.read_map].keys())
return macros.macro_iterator(self.keys())
def __getitem__(self, key):
macro = self.get(key)
if macro is None:
if macro is None or macro[1] == 'undefine':
raise IndexError('key: %s' % (key))
return macro[2]
@ -143,7 +143,7 @@ class macros:
raise TypeError('bad value tuple value field: %s' % (type(value[2])))
if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']:
raise TypeError('bad value tuple (type field): %s' % (value[0]))
if value[1] not in ['none', 'optional', 'required', 'override']:
if value[1] not in ['none', 'optional', 'required', 'override', 'undefine']:
raise TypeError('bad value tuple (attrib field): %s' % (value[1]))
self.macros[self.write_map][self.key_filter(key)] = value
@ -157,18 +157,31 @@ class macros:
return len(self.keys())
def keys(self):
k = self.macros[self.read_map].keys()
def _map_keys(_map):
u = []
k = []
for mk in _map:
if _map[mk][1] == 'undefine':
u += [mk]
else:
k += [mk]
return k, u
keys, undefined = _map_keys(self.macros[self.read_map])
if map is not 'global':
k += self.macros['global'].keys()
return sorted(set(k))
gk, u = _map_keys(self.macros['global'])
undefined = set(undefined + u)
for k in gk:
if k not in undefined:
keys += [k]
return sorted(set(keys))
def has_key(self, key):
if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key)))
key = self.key_filter(key)
if key not in self.macros[self.read_map].keys():
if key not in self.macros['global'].keys():
return False
if self.key_filter(key) not in self.keys():
return False
return True
def maps(self):
@ -277,7 +290,11 @@ class macros:
macro = []
token = ''
state = 'key'
return macros
for m in macros:
if m not in self.macros:
self.macros[m] = {}
for mm in macros[m]:
self.macros[m][mm] = macros[m][mm]
def load(self, name):
try:
@ -287,11 +304,6 @@ class macros:
raise error.general('opening macro file: %s' % (path.host(name)))
macros = self.parse(mc)
mc.close()
for m in macros:
if m not in self.macros:
self.macros[m] = {}
for mm in macros[m]:
self.macros[m][mm] = macros[m][mm]
self.files += [name]
def get(self, key):
@ -376,4 +388,15 @@ if __name__ == "__main__":
if d.has_key('test1'):
print 'error: copy failed.'
sys.exit(1)
m.parse("[test]\n" \
"test1: none, undefine, ''\n" \
"name: none, override, 'pink'\n")
m.set_read_map('test')
if m['name'] != 'pink':
print 'error: override failed. name is %s' % (m['name'])
sys.exit(1)
if m.has_key('test1'):
print 'error: map undefine failed.'
sys.exit(1)
print m
print m.keys()