Esempio n. 1
0
    def testGetArgSpecOnPartialInvalidArgspec(self):
        """Tests getargspec on partial function that doesn't have valid argspec."""
        def func(m, n, l, k=4):
            return 2 * m + l + n * k

        partial_func = functools.partial(func, n=7)

        with self.assertRaisesRegexp(ValueError,
                                     'Function has keyword-only.*'):
            tf_inspect.getargspec(partial_func)
Esempio n. 2
0
  def testGetArgSpecOnPartialInvalidArgspec(self):
    """Tests getargspec on partial function that doesn't have valid argspec."""

    def func(m, n, l, k=4):
      return 2 * m + l + n * k

    partial_func = functools.partial(func, n=7)

    with self.assertRaisesRegexp(ValueError, 'Function has keyword-only.*'):
      tf_inspect.getargspec(partial_func)
Esempio n. 3
0
    def testGetArgSpecOnPartialKeywordArgument(self):
        """Tests getargspec on partial function that prunes some arguments."""
        def func(m, n):
            return 2 * m + n

        partial_func = functools.partial(func, n=7)
        argspec = tf_inspect.FullArgSpec(args=['m'],
                                         varargs=None,
                                         varkw=None,
                                         defaults=None,
                                         kwonlyargs=['n'],
                                         kwonlydefaults={'n': 7},
                                         annotations={})

        self.assertEqual(argspec, tf_inspect.getfullargspec(partial_func))

        with self.assertRaisesRegexp(ValueError,
                                     'Function has keyword-only.*'):
            tf_inspect.getargspec(partial_func)
Esempio n. 4
0
    def testGetArgSpecOnNewClass(self):
        class NewClass(object):
            def __new__(cls, a, b=1, c='hello'):
                pass

        argspec = tf_inspect.ArgSpec(args=['cls', 'a', 'b', 'c'],
                                     varargs=None,
                                     keywords=None,
                                     defaults=(1, 'hello'))

        self.assertEqual(argspec, tf_inspect.getargspec(NewClass))
Esempio n. 5
0
    def testGetArgSpecOnInitClass(self):
        class InitClass(object):
            def __init__(self, a, b=1, c='hello'):
                pass

        argspec = tf_inspect.ArgSpec(args=['self', 'a', 'b', 'c'],
                                     varargs=None,
                                     keywords=None,
                                     defaults=(1, 'hello'))

        self.assertEqual(argspec, tf_inspect.getargspec(InitClass))
Esempio n. 6
0
  def testGetArgSpecOnPartialWithVarkwargs(self):
    """Tests getargspec on partial function with variable keyword arguments."""

    def func(m, n, **kwarg):
      return m * n + len(kwarg)

    partial_func = functools.partial(func, 7)
    argspec = tf_inspect.ArgSpec(
        args=['n'], varargs=None, keywords='kwarg', defaults=None)

    self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 7
0
  def testGetArgSpecOnPartialKeywordArgument(self):
    """Tests getargspec on partial function that prunes some arguments."""

    def func(m, n):
      return 2 * m + n

    partial_func = functools.partial(func, n=7)
    argspec = tf_inspect.FullArgSpec(
        args=['m'],
        varargs=None,
        varkw=None,
        defaults=None,
        kwonlyargs=['n'],
        kwonlydefaults={'n': 7},
        annotations={})

    self.assertEqual(argspec, tf_inspect.getfullargspec(partial_func))

    with self.assertRaisesRegexp(ValueError, 'Function has keyword-only.*'):
      tf_inspect.getargspec(partial_func)
Esempio n. 8
0
  def testGetArgSpecOnPartialNoArgumentsLeft(self):
    """Tests getargspec on partial function that prunes all arguments."""

    def func(m, n):
      return 2 * m + n

    partial_func = functools.partial(func, 7, 10)
    argspec = tf_inspect.ArgSpec(
        args=[], varargs=None, keywords=None, defaults=None)

    self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 9
0
  def testGetArgSpecOnPartialPositionalArgumentOnly(self):
    """Tests getargspec on partial function with only positional arguments."""

    def func(m, n):
      return 2 * m + n

    partial_func = functools.partial(func, 7)
    argspec = tf_inspect.ArgSpec(
        args=['n'], varargs=None, keywords=None, defaults=None)

    self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 10
0
    def testGetArgSpecOnPartialWithVarkwargs(self):
        """Tests getargspec on partial function with variable keyword arguments."""
        def func(m, n, **kwarg):
            return m * n + len(kwarg)

        partial_func = functools.partial(func, 7)
        argspec = tf_inspect.ArgSpec(args=['n'],
                                     varargs=None,
                                     keywords='kwarg',
                                     defaults=None)

        self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 11
0
    def testGetArgSpecOnPartialPositionalArgumentOnly(self):
        """Tests getargspec on partial function with only positional arguments."""
        def func(m, n):
            return 2 * m + n

        partial_func = functools.partial(func, 7)
        argspec = tf_inspect.ArgSpec(args=['n'],
                                     varargs=None,
                                     keywords=None,
                                     defaults=None)

        self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 12
0
    def testGetArgSpecOnCallableObject(self):
        class Callable(object):
            def __call__(self, a, b=1, c='hello'):
                pass

        argspec = tf_inspect.ArgSpec(args=['self', 'a', 'b', 'c'],
                                     varargs=None,
                                     keywords=None,
                                     defaults=(1, 'hello'))

        test_obj = Callable()
        self.assertEqual(argspec, tf_inspect.getargspec(test_obj))
Esempio n. 13
0
    def testGetArgSpecOnPartialNoArgumentsLeft(self):
        """Tests getargspec on partial function that prunes all arguments."""
        def func(m, n):
            return 2 * m + n

        partial_func = functools.partial(func, 7, 10)
        argspec = tf_inspect.ArgSpec(args=[],
                                     varargs=None,
                                     keywords=None,
                                     defaults=None)

        self.assertEqual(argspec, tf_inspect.getargspec(partial_func))
Esempio n. 14
0
    def testGetArgSpecOnPartialValidArgspec(self):
        """Tests getargspec on partial function with valid argspec."""
        def func(m, n, l, k=4):
            return 2 * m + l + n * k

        partial_func = functools.partial(func, n=7, l=2)
        argspec = tf_inspect.FullArgSpec(args=['m'],
                                         varargs=None,
                                         varkw=None,
                                         defaults=None,
                                         kwonlyargs=['n', 'l', 'k'],
                                         kwonlydefaults={
                                             'n': 7,
                                             'l': 2,
                                             'k': 4
                                         },
                                         annotations={})

        self.assertEqual(argspec, tf_inspect.getfullargspec(partial_func))
        with self.assertRaisesRegexp(ValueError,
                                     'Function has keyword-only.*'):
            tf_inspect.getargspec(partial_func)
Esempio n. 15
0
  def testGetArgSpecOnPartialValidArgspec(self):
    """Tests getargspec on partial function with valid argspec."""

    def func(m, n, l, k=4):
      return 2 * m + l + n * k

    partial_func = functools.partial(func, n=7, l=2)
    argspec = tf_inspect.FullArgSpec(
        args=['m'],
        varargs=None,
        varkw=None,
        defaults=None,
        kwonlyargs=['n', 'l', 'k'],
        kwonlydefaults={
            'n': 7,
            'l': 2,
            'k': 4
        },
        annotations={})

    self.assertEqual(argspec, tf_inspect.getfullargspec(partial_func))
    with self.assertRaisesRegexp(ValueError, 'Function has keyword-only.*'):
      tf_inspect.getargspec(partial_func)
Esempio n. 16
0
  def testGetArgSpecOnNewClass(self):

    class NewClass(object):

      def __new__(cls, a, b=1, c='hello'):
        pass

    argspec = tf_inspect.ArgSpec(
        args=['cls', 'a', 'b', 'c'],
        varargs=None,
        keywords=None,
        defaults=(1, 'hello'))

    self.assertEqual(argspec, tf_inspect.getargspec(NewClass))
Esempio n. 17
0
  def testGetArgSpecOnInitClass(self):

    class InitClass(object):

      def __init__(self, a, b=1, c='hello'):
        pass

    argspec = tf_inspect.ArgSpec(
        args=['self', 'a', 'b', 'c'],
        varargs=None,
        keywords=None,
        defaults=(1, 'hello'))

    self.assertEqual(argspec, tf_inspect.getargspec(InitClass))
Esempio n. 18
0
  def testGetArgSpecOnCallableObject(self):

    class Callable(object):

      def __call__(self, a, b=1, c='hello'):
        pass

    argspec = tf_inspect.ArgSpec(
        args=['self', 'a', 'b', 'c'],
        varargs=None,
        keywords=None,
        defaults=(1, 'hello'))

    test_obj = Callable()
    self.assertEqual(argspec, tf_inspect.getargspec(test_obj))