def bool_option_descr(self): """A Choice option provides support for UI fields. This helps support the UI configuration panel. """ copt = config.Choice('test_choice', choices=('one', 'two', 'three')) failUnlessEqual(('one', 'two', 'three'), copt.values())
def choice_option_default(self): """An explicit default value can be provided.""" copt = config.Choice('test_choice', choices=('one', 'two', 'three'), default_value='two') failUnlessEqual('test_choice', copt.name) failUnlessEqual('two', copt.default_value)
def choice_option_init(self): """A Choice option requires a name and sequence of choices. The name and choices value are available as attributes. The default value is the first choice. """ copt = config.Choice('test_choice', choices=('one', 'two', 'three')) failUnlessEqual('test_choice', copt.name) failUnlessEqual('one', copt.default_value) failUnlessEqual(('one', 'two', 'three'), copt.choices)
def config_get_options(self): """The options_ method provides access to the underlying dict.""" conf = config.Config('test_conf') bopt = config.Bool('test_bool', True) copt = config.Choice('test_choice', choices=('one', 'two', 'three')) iopt = config.Int('test_int', 2) conf.add_(bopt) conf.add_(copt) conf.add_(iopt) options = conf.options_() failUnless(options['test_bool'].value is True) failUnlessEqual(2, options['test_int'].value) failUnlessEqual('one', options['test_choice'].value)
def choice_option_set(self): """A Choice option's current value can be modified. The current value is available as the value property. Support for repr is provided. """ copt = config.Choice('test_choice', choices=('one', 'two', 'three')) failUnlessEqual('one', copt.value) ret = copt.set('two') failUnlessEqual('one', copt.default_value) failUnlessEqual('two', copt.value) failUnlessEqual('', ret) failUnlessEqual('two', repr(copt)) failUnlessEqual('two', str(copt))
def config_add(self): """Options can be accessed using the get method. Option values appear as attributes of the Config object. """ conf = config.Config('test_conf') bopt = config.Bool('test_bool', True) copt = config.Choice('test_choice', choices=('one', 'two', 'three')) iopt = config.Int('test_int', 2) conf.add_(bopt) conf.add_(copt) conf.add_(iopt) failUnless(conf.get_('test_bool').value is True) failUnlessEqual('one', conf.get_('test_choice').value) failUnlessEqual(2, conf.get_('test_int').value)
def config_save_load(self): """The config can be saved and loaded. The config.d directory is created as required. """ conf = config.Config('test_conf') bopt = config.Bool('test_bool', True) copt = config.Choice('test_choice', choices=('one', 'two', 'three')) iopt = config.Int('test_int', 2) conf.add_(bopt) conf.add_(copt) conf.add_(iopt) home = Path(__file__).resolve().parent / 'rt_test_data' config_d = home / '.vim/config.d' if config_d.exists(): try: shutil.rmtree(config_d) except OSError: # I do not understand, but running under Cygwin I have seen # PermissionError raised when shtil.rmtree tries # os.rmdir(config_d). Yet the following succeeds! os.rmdir(config_d) conf.save_() bopt.set(False) iopt.set(99) copt.set('three') failUnless(conf.test_bool is False) failUnlessEqual('three', conf.test_choice) failUnlessEqual(99, conf.test_int) conf.load_() failUnless(conf.test_bool is True) failUnlessEqual('one', conf.test_choice) failUnlessEqual(2, conf.test_int)
def choice_option_set_fail(self): """Failure to set a choice option returns an explanatory message.""" copt = config.Choice('test_choice', choices=('one', 'two', 'three')) message = copt.set('four') failUnlessEqual('one', copt.value) failUnlessEqual("'four' is not in permitted set of values", message)