예제 #1
0
  def test_literals(self):
    def example_fun(a=5, b=5.0, c=None, d=True, e='hello', f=(1, (2, 3))):  # pylint: disable=g-bad-name, unused-argument
      pass

    sig = parser._generate_signature(example_fun, reverse_index={})
    self.assertEqual(
        sig, ['a=5', 'b=5.0', 'c=None', 'd=True', "e='hello'", 'f=(1, (2, 3))'])
예제 #2
0
    def test_type_annotations(self):
        # pylint: disable=unused-argument

        def example_fun(self,
                        cls,
                        x: List[str],
                        z: int,
                        a: Union[List[str], str, int] = None,
                        b: str = 'test',
                        *,
                        y: bool = False,
                        c: int,
                        **kwargs) -> None:
            pass

        # pylint: enable=unused-argument

        sig = parser._generate_signature(example_fun, reverse_index={})
        self.assertEqual(sig.arguments, [
            'cls', 'x: List[str]', 'z: int',
            'a: Union[List[str], str, int] = None', "b: str = 'test'", '*',
            'y: bool = False', 'c: int', '**kwargs'
        ])
        self.assertEqual(sig.return_type, 'None')
        self.assertEqual(sig.arguments_typehint_exists, True)
        self.assertEqual(sig.return_typehint_exists, True)
예제 #3
0
  def test_literals(self):
    def example_fun(a=5, b=5.0, c=None, d=True, e='hello', f=(1, (2, 3))):  # pylint: disable=g-bad-name, unused-argument
      pass

    sig = parser._generate_signature(example_fun, reverse_index={})
    self.assertEqual(
        sig, ['a=5', 'b=5.0', 'c=None', 'd=True', "e='hello'", 'f=(1, (2, 3))'])
예제 #4
0
    def test_known_object(self):
        known_object = object()
        reverse_index = {id(known_object): 'location.of.object.in.api'}

        def example_fun(arg=known_object):  # pylint: disable=unused-argument
            pass

        sig = parser._generate_signature(example_fun, reverse_index)
        self.assertEqual(sig, ['arg=location.of.object.in.api'])
예제 #5
0
  def test_known_object(self):
    known_object = object()
    reverse_index = {id(known_object): 'location.of.object.in.api'}

    def example_fun(arg=known_object):  # pylint: disable=unused-argument
      pass

    sig = parser._generate_signature(example_fun, reverse_index)
    self.assertEqual(sig, ['arg=location.of.object.in.api'])
예제 #6
0
    def test_compulsory_kwargs_without_defaults_with_args(self):
        def example_fun(x, z, *args, a=True, b='test', y=None, c, **kwargs):  # pylint: disable=unused-argument
            return True

        sig = parser._generate_signature(example_fun, reverse_index={})
        self.assertEqual(sig.arguments, [
            'x', 'z', '*args', 'a=True', "b='test'", 'y=None', 'c', '**kwargs'
        ])
        self.assertEqual(sig.arguments_typehint_exists, False)
        self.assertEqual(sig.return_typehint_exists, False)
예제 #7
0
    def test_dotted_name(self):
        # pylint: disable=g-bad-name

        class a(object):
            class b(object):
                class c(object):
                    class d(object):
                        def __init__(self, *args):
                            pass

        # pylint: enable=g-bad-name

        e = {'f': 1}

        def example_fun(arg1=a.b.c.d, arg2=a.b.c.d(1, 2), arg3=e['f']):  # pylint: disable=unused-argument
            pass

        sig = parser._generate_signature(example_fun, reverse_index={})
        self.assertEqual(sig,
                         ['arg1=a.b.c.d', 'arg2=a.b.c.d(1, 2)', "arg3=e['f']"])
예제 #8
0
  def test_dotted_name(self):
    # pylint: disable=g-bad-name

    class a(object):

      class b(object):

        class c(object):

          class d(object):

            def __init__(self, *args):
              pass
    # pylint: enable=g-bad-name

    e = {'f': 1}

    def example_fun(arg1=a.b.c.d, arg2=a.b.c.d(1, 2), arg3=e['f']):  # pylint: disable=unused-argument
      pass

    sig = parser._generate_signature(example_fun, reverse_index={})
    self.assertEqual(sig, ['arg1=a.b.c.d', 'arg2=a.b.c.d(1, 2)', "arg3=e['f']"])