def test_from_argparse_args():
    args = Namespace(a=1, b='test', c=True, d='not valid')
    my_instance = from_argparse_args(ArgparseExample, args)
    assert my_instance.a == 1
    assert my_instance.b == 'test'
    assert my_instance.c

    parser = ArgumentParser()
    mock_trainer = MagicMock()
    _ = from_argparse_args(mock_trainer, parser)
    mock_trainer.parse_argparser.assert_called_once_with(parser)
    def from_argparse_args(cls, args: Union[Namespace, ArgumentParser], **kwargs):
        """Create an instance from CLI arguments.

        Args:
            args: The parser or namespace to take arguments from. Only known arguments will be
             parsed and passed to the :class:`LightningDataModule`.
            **kwargs: Additional keyword arguments that may override ones in the parser or namespace.
             These must be valid DataModule arguments.

        Example::
            parser = ArgumentParser(add_help=False)
            parser = LightningDataModule.add_argparse_args(parser)
            module = LightningDataModule.from_argparse_args(args)
        """
        return from_argparse_args(cls, args, **kwargs)
Beispiel #3
0
 def from_argparse_args(cls: Type['_T'], args: Union[Namespace,
                                                     ArgumentParser],
                        **kwargs) -> '_T':
     return from_argparse_args(cls, args, **kwargs)
Beispiel #4
0
 def from_argparse_args(cls, args: Union[Namespace, ArgumentParser],
                        **kwargs):
     return from_argparse_args(cls, args, **kwargs)