def test_get_target_args(self):
        class Target1(Target):
            def __init__(self, arg1, arg2=42, **kwargs):
                """
        :param arg1: The first arg.
        :param arg2: The second arg.
        """
                super(Target1, self).__init__(**kwargs)

        class Target2(Target1):
            pass

        class Target3(Target2):
            def __init__(self, arg3, arg4=None, **kwargs):
                super(Target1, self).__init__(**kwargs)

        self.assertEqual(
            sorted(BuildDictionaryInfoExtracter.basic_target_args + [
                FunctionArg('arg1', 'The first arg.', False, None),
                FunctionArg('arg2', 'The second arg.', True, 42),
                FunctionArg('arg3', '', False, None),
                FunctionArg('arg4', '', True, None)
            ]),
            sorted(
                BuildDictionaryInfoExtracter.get_args_for_target_type(
                    Target3)))

        # Check a trivial case.
        class Target4(Target):
            pass

        self.assertEqual(
            BuildDictionaryInfoExtracter.basic_target_args,
            BuildDictionaryInfoExtracter.get_args_for_target_type(Target4))
예제 #2
0
    def test_get_object_factory_info(self):
        class Foo:
            """Foo docstring."""
            def __call__(self, bar, baz=42):
                """
                :param bar: Bar details.
                :param int baz: Baz details.
                """

        bfa = BuildFileAliases(targets={},
                               objects={},
                               context_aware_object_factories={"foo": Foo})
        extracter = BuildDictionaryInfoExtracter(bfa)
        self.assertEqual(
            [
                BuildSymbolInfo(
                    "foo",
                    "Foo docstring.",
                    [],
                    [
                        FunctionArg("bar", "Bar details.", False, None),
                        FunctionArg("baz", "Baz details.", True, 42),
                    ],
                )
            ],
            extracter.get_object_factory_info(),
        )
    def test_get_object_factory_info(self):
        class Foo(object):
            """Foo docstring."""
            def __call__(self, bar, baz=42):
                """
        :param bar: Bar details.
        :param int baz: Baz details.
        """

        bfa = BuildFileAliases(targets={},
                               objects={},
                               context_aware_object_factories={'foo': Foo})
        extracter = BuildDictionaryInfoExtracter(bfa)
        self.assertEquals([
            BuildSymbolInfo('foo', 'Foo docstring.', [], [
                FunctionArg('bar', 'Bar details.', False, None),
                FunctionArg('baz', 'Baz details.', True, 42)
            ])
        ], extracter.get_object_factory_info())
    def test_get_object_info_datatype(self):
        class FooDatatype(datatype(['bar', 'baz'])):
            """Foo docstring."""
            def __new__(cls, bar, baz=42):
                """
        :param bar: Bar details.
        :param int baz: Baz details.
        """
                return super(FooDatatype, cls).__new__(cls, bar, baz)

        bfa = BuildFileAliases(
            targets={},
            objects={'foo': FooDatatype},
            context_aware_object_factories={},
        )
        extracter = BuildDictionaryInfoExtracter(bfa)
        self.assertEquals([
            BuildSymbolInfo('foo', 'Foo docstring.', [], [
                FunctionArg('bar', 'Bar details.', False, None),
                FunctionArg('baz', 'Baz details.', True, 42)
            ])
        ], extracter.get_object_info())
예제 #5
0
    def test_get_target_args(self):
        class Target1(Target):
            def __init__(self, arg1, arg2=42, **kwargs):
                """
        :param arg1: The first arg.
        :param arg2: The second arg.
        """
                super(Target1, self).__init__(**kwargs)

        class Target2(Target1):
            pass

        class Target3(Target2):
            def __init__(self, arg3, arg4=None, **kwargs):
                super(Target1, self).__init__(**kwargs)

        self.maxDiff = None
        self.assertEqual(
            BuildDictionaryInfoExtracter.basic_target_args + [
                FunctionArg('arg1', 'The first arg.', False, None),
                FunctionArg('arg2', 'The second arg.', True, 42),
                FunctionArg('arg3', '', False, None),
                FunctionArg('arg4', '', True, None)
            ], BuildDictionaryInfoExtracter.get_target_args(Target3))
예제 #6
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__))
    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))
예제 #8
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),
        )