本文整理汇总了Python中sigtools.support.f函数的典型用法代码示例。如果您正苦于以下问题:Python f函数的具体用法?Python f怎么用?Python f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call
def test_call(self):
outer = support.f('*args, **kwargs')
inner = support.f('a, *, b')
forw = specifiers.forwards_to_function(inner)(outer)
instance = object()
forw_get_prox = _util.safe_get(forw, instance, object)
self.assertEqual(
forw_get_prox(1, b=2),
{'args': (instance, 1), 'kwargs': {'b': 2}})
示例2: test_use_twice
def test_use_twice(self):
annotator = modifiers.annotate(a=1)
self.assertSigsEqual(
s('a:1, b'),
signature(annotator(f('a, b')))
)
self.assertSigsEqual(
s('a:1'),
signature(annotator(f('a')))
)
示例3: test_specifiers_sig_after
def test_specifiers_sig_after(self):
inner = f('a, b', name='inner')
outer = f('x, y, z, *args, **kwargs', name='outer')
pt = modifiers.kwoargs('z')(outer)
pt = specifiers.forwards_to_function(inner)(pt)
sig = specifiers.signature(pt)
self.assertSigsEqual(sig, s('x, y, a, b, *, z'))
self.assertSourcesEqual(
sig.sources, {'inner': 'ab', 'outer': 'xyz',
'+depths': ['outer', 'inner']})
self.assertEqual(sig.sources['x'], [pt])
示例4: test_success
def test_success(self):
self.assertSigsEqual(
s('a, b:1'),
signature(modifiers.annotate(b=1)(f('a, b')))
)
self.assertSigsEqual(
s('a:1, b:2'),
signature(modifiers.annotate(a=1, b=2)(f('a, b')))
)
self.assertSigsEqual(
s('a:1, b', 2),
signature(modifiers.annotate(2, a=1)(f('a, b')))
)
示例5: _test_func
def _test_func(self, sig, wrapper_sigs, doc, wrapper_docs, help_str):
ifunc = f(sig, pre="from clize import Parameter")
ifunc.__doc__ = doc
func = ifunc
for sig, doc in zip(wrapper_sigs, wrapper_docs):
wfunc = f('func, ' + sig, pre="from clize import Parameter")
wfunc.__doc__ = doc
func = wrapper_decorator(wfunc)(func)
r = runner.Clize(func)
h = help.ClizeHelp(r, None)
h.prepare()
p_help_str = str(h.show('func'))
self.assertEqual(help_str.split(), p_help_str.split())
示例6: test_custom_param_help
def test_custom_param_help(self):
class CustParam(parser.OptionParameter):
def show_help(self, desc, after, f, cols):
cols.append('I am', 'a custom parameter!')
f.append("There is stuff after me.")
f.append(desc)
f.extend(after)
func = f(
"*, param: a",
locals={'a': parser.use_class(named=CustParam)})
func.__doc__ = """
param: Param desc
After param
_:_
"""
r = runner.Clize(func)
self._do_test(r, ['func --param=STR', USAGE_HELP], """
Usage: func [OPTIONS]
Options:
I am a custom parameter!
There is stuff after me.
Param desc
After param
Other actions:
-h, --help Show the help
""")
示例7: test_whole_help
def test_whole_help(self, sig, doc, help_str):
func = f(sig, pre="from clize import Parameter")
func.__doc__ = doc
r = runner.Clize(func)
h = help.ClizeHelp(r, None)
p_help_str = str(h.show('func'))
self.assertEqual(p_help_str.split(), help_str.split())
示例8: test_attr_conservation_after
def test_attr_conservation_after(self):
func = f('s, a')
pt = modifiers.kwoargs('a')(func)
pt.attr = object()
self.assertIs(pt.attr, modifiers.kwoargs('a')(pt).attr)
bpt = pt.__get__(object(), object)
self.assertIs(pt.attr, bpt.attr)
self.assertIs(pt.attr, modifiers.kwoargs('a')(bpt).attr)
示例9: test_show_list_morekw
def test_show_list_morekw(self):
func = support.f('par:a', locals={'a': RepTests.mapped_basic[1]})
out, err = util.run(func, ['name', 'list', '-k', 'xyz'])
self.assertEqual('', err.getvalue())
self.assertEqual(
"""name: Possible values for par:
hello h1
goodbye h2""".split(),
out.getvalue().split())
示例10: test_show_list
def test_show_list(self):
func = support.f('par:a', locals={'a': RepTests.oneof_help[1]})
out, err = util.run(func, ['name', 'list'])
self.assertEqual('', err.getvalue())
self.assertEqual(
"""name: Possible values for par:
hello h1
bye h2""".split(),
out.getvalue().split())
示例11: test_alt_middle
def test_alt_middle(self):
_func = support.f('')
self.assertRaises(
errors.ArgsBeforeAlternateCommand,
self._test_func,
'*a', [
parser.AlternateCommandParameter(
func=_func, aliases=['--alt'])],
('a', '--alt', 'a', 'b'), ['a', 'b'], {}, _func
)
示例12: test_show_list
def test_show_list(self):
func = support.f('par:a', locals={'a': RepTests.mapped_basic[1]})
out, err = self.crun(func, ['name', 'list'])
self.assertEqual('', err.getvalue())
self.assertLinesEqual(
"""
name: Possible values for par:
hello h1
goodbye h2""",
out.getvalue())
示例13: _test
def _test(self, expected_sig_str, orig_sig_str, exceptions):
orig_func = f(orig_sig_str)
expected_sig = s(expected_sig_str)
func = modifiers.autokwoargs(exceptions=exceptions)(orig_func)
self.assertSigsEqual(expected_sig, signature(func))
if not exceptions: # test the arg-less form of @autokwargs
func = modifiers.autokwoargs(orig_func)
self.assertSigsEqual(expected_sig, signature(func))
示例14: test_show_list_alt
def test_show_list_alt(self):
func = support.f('par:a',
locals={'a': RepTests.mapped_alternate_list[1]})
out, err = util.run(func, ['name', 'options'])
self.assertEqual('', err.getvalue())
self.assertEqual(
"""name: Possible values for par:
hello h1
goodbye h2""".split(),
out.getvalue().split())
示例15: _test
def _test(self, outer, inner, args, kwargs,
expected, expected_get, exp_src, exp_src_get):
outer_f = support.f(outer, name='outer')
inner_f = support.f(inner, name='inner')
forw = specifiers.forwards_to_function(inner_f, *args, **kwargs)(outer_f)
sig = specifiers.signature(forw)
self.assertSigsEqual(sig, support.s(expected))
self.assertSourcesEqual(sig.sources, {
'outer': exp_src[0], 'inner': exp_src[1],
'+depths': ['outer', 'inner']})
sig_get = specifiers.signature(_util.safe_get(forw, object(), object))
self.assertSigsEqual(sig_get, support.s(expected_get))
self.assertSourcesEqual(sig_get.sources, {
'outer': exp_src_get[0], 'inner': exp_src_get[1],
'+depths': ['outer', 'inner']})