def test_get_function_args(self):
    # Test standalone function.
    def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
      pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', False, None),
                      FunctionArg('arg3', '', True, 42), FunctionArg('arg4', '', True, None),
                      FunctionArg('arg5', '', True, 'foo')],
      BuildDictionaryInfoExtracter.get_function_args(func))

    # Test member function.
    class TestCls(object):
      def __init__(self, arg1, arg2=False):
        pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', True, False)],
                     BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))

    # Test *args, **kwargs situation.
    def generic_func(arg1, arg2=42, *args, **kwargs):
      """
      :param arg1: The first arg.
      :param arg2: The second arg.
      :param args: Some extra varargs.
      :param arg3: The third arg.
      :param arg4: The fourth arg (default: 'Foo').
      """

    self.assertEqual([FunctionArg('arg1', 'The first arg.', False, None),
                      FunctionArg('arg2', 'The second arg.', True, 42),
                      FunctionArg('*args', 'Some extra varargs.', False, None),
                      FunctionArg('arg3', 'The third arg.', True, None),
                      FunctionArg('arg4', "The fourth arg.", True, "'Foo'")],
                     BuildDictionaryInfoExtracter.get_function_args(generic_func))
예제 #2
0
  def test_get_function_args(self):
    # Test standalone function.
    def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
      pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', False, None),
                      FunctionArg('arg3', '', True, 42), FunctionArg('arg4', '', True, None),
                      FunctionArg('arg5', '', True, 'foo')],
      BuildDictionaryInfoExtracter.get_function_args(func))

    # Test member function.
    class TestCls(object):
      def __init__(self, arg1, arg2=False):
        pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', True, False)],
                     BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))

    # Test *args, **kwargs situation.
    def generic_func(arg1, arg2=42, *args, **kwargs):
      """
      :param arg1: The first arg.
      :param arg2: The second arg.
      :param args: Some extra varargs.
      :param arg3: The third arg.
      :param arg4: The fourth arg (default: 'Foo').
      """

    self.assertEqual([FunctionArg('arg1', 'The first arg.', False, None),
                      FunctionArg('arg2', 'The second arg.', True, 42),
                      FunctionArg('*args', 'Some extra varargs.', False, None),
                      FunctionArg('arg3', 'The third arg.', True, None),
                      FunctionArg('arg4', "The fourth arg.", True, "'Foo'")],
                     BuildDictionaryInfoExtracter.get_function_args(generic_func))
예제 #3
0
    def test_get_function_args(self):
        # Test standalone function.
        def func(arg1, arg2, arg3=42, arg4=None, arg5="foo"):
            pass

        self.assertEqual(
            [
                FunctionArg("arg1", "", False, None),
                FunctionArg("arg2", "", False, None),
                FunctionArg("arg3", "", True, 42),
                FunctionArg("arg4", "", True, None),
                FunctionArg("arg5", "", True, "foo"),
            ],
            BuildDictionaryInfoExtracter.get_function_args(func),
        )

        # Test member function.
        class TestCls:
            def __init__(self, arg1, arg2=False):
                pass

        self.assertEqual(
            [
                FunctionArg("arg1", "", False, None),
                FunctionArg("arg2", "", True, False)
            ],
            BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__),
        )

        # Test *args, **kwargs situation.
        def generic_func(arg1, arg2=42, *args, **kwargs):
            """
            :param arg1: The first arg.
            :param arg2: The second arg.
            :param args: Some extra varargs.
            :param arg3: The third arg.
            :param arg4: The fourth arg (default: 'Foo').
            """

        self.assertEqual(
            [
                FunctionArg("arg1", "The first arg.", False, None),
                FunctionArg("arg2", "The second arg.", True, 42),
                FunctionArg("*args", "Some extra varargs.", False, None),
                FunctionArg("arg3", "The third arg.", True, None),
                FunctionArg("arg4", "The fourth arg.", True, "'Foo'"),
            ],
            BuildDictionaryInfoExtracter.get_function_args(generic_func),
        )
  def test_get_function_args(self):
    # Test standalone function.
    def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
      pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', False, None),
                      FunctionArg('arg3', '', True, 42), FunctionArg('arg4', '', True, None),
                      FunctionArg('arg5', '', True, 'foo')],
      BuildDictionaryInfoExtracter.get_function_args(func))

    # Test member function.
    class TestCls(object):
      def __init__(self, arg1, arg2=False):
        pass

    self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', True, False)],
                     BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))
예제 #5
0
    def test_get_function_args(self):
        # Test standalone function.
        def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
            pass

        self.assertEqual([
            FunctionArg('arg1', '', False, None),
            FunctionArg('arg2', '', False, None),
            FunctionArg('arg3', '', True, 42),
            FunctionArg('arg4', '', True, None),
            FunctionArg('arg5', '', True, 'foo')
        ], BuildDictionaryInfoExtracter.get_function_args(func))

        # Test member function.
        class TestCls(object):
            def __init__(self, arg1, arg2=False):
                pass

        self.assertEqual([
            FunctionArg('arg1', '', False, None),
            FunctionArg('arg2', '', True, False)
        ], BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))