Fixed/added some config parsing tests
This commit is contained in:
@@ -253,20 +253,19 @@ class MultiWorldParser(object):
|
||||
for key in settingsDefinition.render:
|
||||
option = settingsDefinition.render[key]
|
||||
if option.has_key("default"):
|
||||
self.defaults[key] = option.get("default")
|
||||
self.defaults[key] = option["default"]
|
||||
|
||||
|
||||
self.defaults.update(glob)
|
||||
|
||||
|
||||
import pprint
|
||||
pprint.pprint(glob, indent=2)
|
||||
|
||||
def validate(self):
|
||||
|
||||
|
||||
for worldname in self.render:
|
||||
world = self.render[worldname]
|
||||
world = dict()
|
||||
world.update(self.defaults)
|
||||
world.update(self.render[worldname])
|
||||
|
||||
for key in world:
|
||||
if key not in settingsDefinition.render:
|
||||
@@ -278,8 +277,9 @@ class MultiWorldParser(object):
|
||||
val = definition['validator'](world[key])
|
||||
world[key] = val
|
||||
except Exception as e:
|
||||
print "Error: %r" % e
|
||||
next
|
||||
#print "Error validating %s: %r" % (key, e)
|
||||
raise e
|
||||
self.render[worldname] = world
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -62,15 +62,22 @@ def validateBGColor(color):
|
||||
"""BG color must be an HTML color, with an option leading # (hash symbol)
|
||||
returns an (r,b,g) 3-tuple
|
||||
"""
|
||||
if color[0] != "#":
|
||||
color = "#%s" % color
|
||||
if len(color) != 7:
|
||||
raise ValidationException("%r is not a valid color. Expected HTML color syntax (i.e. #RRGGBB)" % color)
|
||||
|
||||
r = int(color[1:3], 16)
|
||||
g = int(color[3:5], 16)
|
||||
b = int(color[5:7], 16)
|
||||
return (r,g,b,0)
|
||||
if type(color) == str:
|
||||
if color[0] != "#":
|
||||
color = "#" + color
|
||||
if len(color) != 7:
|
||||
raise ValidationException("%r is not a valid color. Expected HTML color syntax (i.e. #RRGGBB)" % color)
|
||||
try:
|
||||
r = int(color[1:3], 16)
|
||||
g = int(color[3:5], 16)
|
||||
b = int(color[5:7], 16)
|
||||
return (r,g,b,0)
|
||||
except ValueError:
|
||||
raise ValidationException("%r is not a valid color. Expected HTML color syntax (i.e. #RRGGBB)" % color)
|
||||
elif type(color) == tuple:
|
||||
if len(color) != 4:
|
||||
raise ValidationException("%r is not a valid color. Expected a 4-tuple" % (color,))
|
||||
return color
|
||||
|
||||
|
||||
def validateOptImg(opt):
|
||||
|
||||
Reference in New Issue
Block a user