mirror of
https://github.com/fergalmoran/picard.git
synced 2026-01-06 08:34:01 +00:00
Add Option.get_default() method and matching tests
This commit is contained in:
@@ -385,6 +385,13 @@ class Option(QtCore.QObject):
|
||||
def get(cls, section, name):
|
||||
return cls.registry.get((section, name))
|
||||
|
||||
@classmethod
|
||||
def get_default(cls, section, name):
|
||||
opt = cls.get(section, name)
|
||||
if opt is None:
|
||||
raise OptionError("No such option", section, name)
|
||||
return opt.default
|
||||
|
||||
@classmethod
|
||||
def add_if_missing(cls, section, name, default):
|
||||
if not cls.exists(section, name):
|
||||
|
||||
@@ -108,6 +108,12 @@ class TestPicardConfigOption(TestPicardConfigCommon):
|
||||
with self.assertRaisesRegex(OptionError, r"^Option setting/option: Already declared"):
|
||||
Option("setting", "option", "def")
|
||||
|
||||
def test_get_default(self):
|
||||
Option("setting", "option", "abc")
|
||||
self.assertEqual(Option.get_default("setting", "option"), "abc")
|
||||
with self.assertRaisesRegex(OptionError, "^Option setting/unknown_option: No such option"):
|
||||
Option.get_default("setting", "unknown_option")
|
||||
|
||||
|
||||
class TestPicardConfigSection(TestPicardConfigCommon):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user