def __call__(self, parser, namespace, value, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `value`. If `value` parses to a boolean True value then the attribute value is 'download'. If `value` parses to a boolean False value then the attribute value is ``None``. Otherwise the attribute value is the value of `value`. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. value (str): Value parsed from the command line. """ try: value_as_bool = util.parse_bool( value, additional_true=['download', 'download-tr6', 'nightly']) except TypeError: if not util.is_url(value): value = os.path.abspath(os.path.expanduser(value)) if not (os.path.isdir(value) or util.path_accessible(value)): raise argparse.ArgumentError( self, "Keyword, valid path, or URL required: %s" % value) else: value = value.lower() if value_as_bool else None setattr(namespace, self.dest, value)
def __call__(self, parser, namespace, value, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `value`. If `value` parses to a boolean via :any:`taucmdr.util.parse_bool` then the attribute value is that boolean value. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. value (str): Value parsed from the command line/ """ try: setattr(namespace, self.dest, util.parse_bool(value)) except TypeError: raise argparse.ArgumentError(self, 'Boolean value required')
def __call__(self, parser, namespace, value, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `value`. If `value` parses to a boolean True value then the attribute value is 'download'. If `value` parses to a boolean False value then the attribute value is ``None``. Otherwise the attribute value is the value of `value`. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. value (str): Value parsed from the command line. """ try: value_as_bool = util.parse_bool(value, additional_true=['download', 'nightly']) except TypeError: if not util.is_url(value): value = os.path.abspath(os.path.expanduser(value)) if not (os.path.isdir(value) or util.path_accessible(value)): raise argparse.ArgumentError(self, "Keyword, valid path, or URL required: %s" % value) else: value = value.lower() if value_as_bool else None setattr(namespace, self.dest, value)
def test_extendfalse(self): self.assertFalse(util.parse_bool('incorrect', ['correct', '2', '3', '4', '5'], ['incorrect'])) with self.assertRaises(TypeError): util.parse_bool('incorect')
def test_false(self): self.assertFalse(util.parse_bool('off')) with self.assertRaises(TypeError): util.parse_bool('offf')
def test_true(self): self.assertTrue(util.parse_bool('yes')) with self.assertRaises(TypeError): util.parse_bool('ye')