def test_booleans(): truthy = ['yes', 'Yes', 'True', 'true', 'TRUE', 'YES', 'on', 'On', 'ON'] falsy = ['no', 'false', 'off', 'OFF', 'FALSE', 'nO'] not_truthy = ['', 'not', 'ONN', 'TRUETH', 'yess'] for case in chain(truthy, falsy): assert utils.verify_boolean(case) is True for case in truthy: assert utils.is_boolean_true(case) is True assert utils.is_boolean_false(case) is False assert utils.get_boolean(case) is True for case in falsy: assert utils.is_boolean_true(case) is False assert utils.is_boolean_false(case) is True assert utils.get_boolean(case, dflt=True) is False for case in not_truthy: assert utils.verify_boolean(case) is False assert utils.is_boolean_true(case) is False assert utils.is_boolean_false(case) is False assert utils.get_boolean(case) is False
def parse_order(self): ''' order <id> {kind|<score>}: <rsc>[:<action>] <rsc>[:<action>] ... [symmetrical=<bool>] kind :: Mandatory | Optional | Serialize ''' out = Order() out.id = self.match_identifier() if self.try_match('(%s):$' % ('|'.join(self.validation.rsc_order_kinds()))): out.kind = self.validation.canonize(self.matched(1), self.validation.rsc_order_kinds()) else: self.match(self._SCORE_RE) out.score = self.validate_score(self.matched(1), noattr=True) if self.try_match_tail('symmetrical=(true|false|yes|no|on|off)$'): out.symmetrical = is_boolean_true(self.matched(1)) out.simple, out.resources = self.match_resource_set('action') return out
def parse_order(self): ''' order <id> {kind|<score>}: <rsc>[:<action>] <rsc>[:<action>] ... [symmetrical=<bool>] kind :: Mandatory | Optional | Serialize ''' out = Order() out.id = self.match_identifier() if self.try_match('(%s):$' % ('|'.join(self.validation.rsc_order_kinds()))): out.kind = self.validation.canonize( self.matched(1), self.validation.rsc_order_kinds()) else: self.match(self._SCORE_RE) out.score = self.validate_score(self.matched(1), noattr=True) if self.try_match_tail('symmetrical=(true|false|yes|no|on|off)$'): out.symmetrical = is_boolean_true(self.matched(1)) out.simple, out.resources = self.match_resource_set('action') return out
def do_quorum(self, context, opt): "usage: quorum <bool>" if not utils.verify_boolean(opt): context.fatal_error("%s: bad boolean option" % opt) return cib_status.set_quorum(utils.is_boolean_true(opt))