diff --git a/plugins/Config/test.py b/plugins/Config/test.py index 288b20cfc..7dd073862 100644 --- a/plugins/Config/test.py +++ b/plugins/Config/test.py @@ -1,7 +1,7 @@ ### # Copyright (c) 2002-2005, Jeremiah Fincher # Copyright (c) 2009, James McCoy -# Copyright (c) 2010-2021, Valentin Lorentz +# Copyright (c) 2010-2022, Valentin Lorentz # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -33,11 +33,20 @@ import random from supybot.test import * import supybot.conf as conf +import supybot.registry as registry _letters = 'abcdefghijklmnopqrstuvwxyz' def random_string(): return ''.join(random.choice(_letters) for _ in range(16)) +class Fruit(registry.OnlySomeStrings): + validStrings = ('Apple', 'Orange') + +group = conf.registerGroup(conf.supybot.plugins.Config, 'test') +conf.registerGlobalValue(group, 'fruit', + Fruit('Orange', '''Must be a fruit''')) + + class ConfigTestCase(ChannelPluginTestCase): # We add utilities so there's something in supybot.plugins. plugins = ('Config', 'User', 'Utilities', 'Web') @@ -50,6 +59,16 @@ class ConfigTestCase(ChannelPluginTestCase): self.assertNotRegexp('config get supybot.reply', r'registry\.Group') self.assertResponse('config supybot.protocols.irc.throttleTime', '0.0') + def testSetOnlysomestrings(self): + self.assertResponse('config supybot.plugins.Config.test.fruit Apple', + 'The operation succeeded.') + self.assertResponse('config supybot.plugins.Config.test.fruit orange', + 'The operation succeeded.') + self.assertResponse('config supybot.plugins.Config.test.fruit Tomatoe', + "Error: Valid values include 'Apple' and " + "'Orange', not 'Tomatoe'.") + + def testList(self): self.assertError('config list asldfkj') self.assertError('config list supybot.asdfkjsldf') diff --git a/src/registry.py b/src/registry.py index 430e2bd45..252c2fcf0 100644 --- a/src/registry.py +++ b/src/registry.py @@ -710,7 +710,7 @@ class OnlySomeStrings(String): def setValue(self, s): v = self.normalize(s) - if s in self.validStrings: + if v in self.validStrings: self.__parent.setValue(v) else: self.error(v)