Ensure there's no size for font-family settings.

See #549.
This commit is contained in:
Florian Bruhin 2015-03-16 18:32:17 +01:00
parent 4157cfe86f
commit f1b9a3c8b5
3 changed files with 78 additions and 6 deletions

View File

@ -882,27 +882,27 @@ DATA = collections.OrderedDict([
"Font used for the debugging console."),
('web-family-standard',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for standard fonts."),
('web-family-fixed',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for fixed fonts."),
('web-family-serif',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for serif fonts."),
('web-family-sans-serif',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for sans-serif fonts."),
('web-family-cursive',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for cursive fonts."),
('web-family-fantasy',
SettingValue(typ.String(none_ok=True), ''),
SettingValue(typ.FontFamily(none_ok=True), ''),
"Font family for fantasy fonts."),
('web-size-minimum',

View File

@ -700,6 +700,25 @@ class Font(BaseType):
raise configexc.ValidationError(value, "must be a valid font")
class FontFamily(Font):
"""A Qt font family."""
def validate(self, value):
if not value:
if self._none_ok:
return
else:
raise configexc.ValidationError(value, "may not be empty!")
match = self.font_regex.match(value)
if not match:
raise configexc.ValidationError(value, "must be a valid font")
for group in 'style', 'weight', 'namedweight', 'size':
if match.group(group):
raise configexc.ValidationError(value, "may not include a "
"{}!".format(group))
class QtFont(Font):
"""A Font which gets converted to q QFont."""

View File

@ -1196,6 +1196,59 @@ class FontTests(unittest.TestCase):
self.assertIsNone(self.t2.transform(''))
class FontFamilyTests(unittest.TestCase):
"""Test FontFamily."""
TESTS = ['"Foobar Neue"', 'inconsolatazi4', 'Foobar']
INVALID = [
'10pt "Foobar Neue"',
'10PT "Foobar Neue"',
'10px "Foobar Neue"',
'10PX "Foobar Neue"',
'bold "Foobar Neue"',
'italic "Foobar Neue"',
'oblique "Foobar Neue"',
'normal bold "Foobar Neue"',
'bold italic "Foobar Neue"',
'bold 10pt "Foobar Neue"',
'italic 10pt "Foobar Neue"',
'oblique 10pt "Foobar Neue"',
'normal bold 10pt "Foobar Neue"',
'bold italic 10pt "Foobar Neue"',
]
def setUp(self):
self.t = configtypes.FontFamily()
def test_validate_empty(self):
"""Test validate with an empty string."""
with self.assertRaises(configexc.ValidationError):
self.t.validate('')
def test_validate_empty_none_ok(self):
"""Test validate with an empty string and none_ok=True."""
t = configtypes.FontFamily(none_ok=True)
t.validate('')
def test_validate_valid(self):
"""Test validate with valid values."""
for val in self.TESTS:
with self.subTest(val=val):
self.t.validate(val)
def test_validate_invalid(self):
"""Test validate with invalid values."""
for val in self.INVALID:
with self.subTest(val=val):
with self.assertRaises(configexc.ValidationError, msg=val):
self.t.validate(val)
def test_transform_empty(self):
"""Test transform with an empty value."""
self.assertIsNone(self.t.transform(''))
class RegexTests(unittest.TestCase):
"""Test Regex."""