1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import unittest
from inspect import getfullargspec
from wrapt.arguments import formatargspec
class TestFormatargspec35(unittest.TestCase):
def assertFormatEqual(self, func, ref):
formatted = formatargspec(*getfullargspec(func))
self.assertEqual(formatted, ref)
def test_formatargspec(self):
def foo1():
pass
self.assertFormatEqual(foo1, "()")
def foo2(a, b="c"):
pass
self.assertFormatEqual(foo2, ("(a, b='c')"))
def foo3(a, b, *args, **kwargs):
pass
self.assertFormatEqual(foo3, "(a, b, *args, **kwargs)")
def foo4(a: int, b) -> list:
return []
formatted4 = "(a: int, b) -> list"
self.assertFormatEqual(foo4, formatted4)
# examples from https://www.python.org/dev/peps/pep-3102/
def sortwords(*wordlist, case_sensitive=False):
pass
self.assertFormatEqual(sortwords, "(*wordlist, case_sensitive=False)")
def compare(a, b, *, key=None):
pass
self.assertFormatEqual(compare, "(a, b, *, key=None)")
|