本文整理汇总了Python中sigtools.support.s函数的典型用法代码示例。如果您正苦于以下问题:Python s函数的具体用法?Python s怎么用?Python s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _test
def _test(self, exp_sig, exp_src, outer, inner,
num_args=0, named_args=(),
hide_args=False, hide_kwargs=False,
use_varargs=True, use_varkwargs=True,
partial=False):
outer_sig = s(outer, name='o')
inner_sig = s(inner, name='i')
sig = forwards(
outer_sig, inner_sig,
num_args, *named_args,
hide_args=hide_args, hide_kwargs=hide_kwargs,
use_varargs=use_varargs, use_varkwargs=use_varkwargs,
partial=partial)
self.assertSigsEqual(sig, s(exp_sig))
self.assertSourcesEqual(sig.sources, {
'o': exp_src[0], 'i': exp_src[1],
'+depths': ['o', 'i']})
outer_sig = self.downgrade_sig(outer_sig)
inner_sig = self.downgrade_sig(inner_sig)
sig = forwards(
outer_sig, inner_sig,
num_args, *named_args,
hide_args=hide_args, hide_kwargs=hide_kwargs,
use_varargs=use_varargs, use_varkwargs=use_varkwargs,
partial=partial)
self.assertSigsEqual(sig, s(exp_sig))
开发者ID:epsy,项目名称:sigtools,代码行数:28,代码来源:test_forwards.py
示例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')))
)
开发者ID:epsy,项目名称:sigtools,代码行数:10,代码来源:test_modifiers.py
示例3: test_pok_interact
def test_pok_interact(self):
pok = f('self, a, *, b')
annotated = modifiers.annotate(a=1, b=2)(pok)
self.assertSigsEqual(
s('self, a:1, *, b:2'),
signature(annotated)
)
self.assertSigsEqual(
s('a:1, *, b:2'),
signature(safe_get(annotated, object(), object))
)
开发者ID:epsy,项目名称:sigtools,代码行数:11,代码来源:test_modifiers.py
示例4: poktranslator_test
def poktranslator_test(self, expected_sig_str, orig_sig_str,
posoargs, kwoargs):
expected_sig = s(expected_sig_str)
orig_sig = s(orig_sig_str)
for exp, orig in defaults_variations(expected_sig, orig_sig):
for exp, orig in stars_variations(exp, orig):
func = modifiers._PokTranslator(
func_from_sig(orig), posoargs, kwoargs)
self.assertSigsEqual(exp, signature(func))
test_func_sig_coherent(func)
repr(func) # must not cause an error
开发者ID:epsy,项目名称:sigtools,代码行数:11,代码来源:test_modifiers.py
示例5: test_preserve_annotations
def test_preserve_annotations(self):
func = f('self, a:2, b, c:3', 4)
tr = modifiers._PokTranslator(func, kwoargs=('a', 'b'))
self.assertSigsEqual(
s('self, c:3, *, a:2, b', 4),
signature(tr)
)
self.assertSigsEqual(
s('c:3, *, a:2, b', 4),
signature(safe_get(tr, object(), object))
)
开发者ID:epsy,项目名称:sigtools,代码行数:12,代码来源:test_modifiers.py
示例6: 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')))
)
开发者ID:epsy,项目名称:sigtools,代码行数:13,代码来源:test_modifiers.py
示例7: test_sigs_equal
def test_sigs_equal(self):
self.assertSigsEqual(s('one'), s('one'))
self.assertSigsEqual(s('*, one'), s('*, one'))
with self.assertRaises(AssertionError):
self.assertSigsEqual(s('one'), s('two'))
with self.assertRaises(AssertionError):
self.assertSigsEqual(s('one'), s('*, one'))
开发者ID:epsy,项目名称:sigtools,代码行数:8,代码来源:test_testutil.py
示例8: test_converter_ignore
def test_converter_ignore(self):
@parser.parameter_converter
def conv(param, annotations):
return parser.Parameter.IGNORE
sig = support.s('one:conv', locals={'conv': conv})
csig = parser.CliSignature.from_signature(sig)
self.assertEqual(str(csig), '')
开发者ID:gitter-badger,项目名称:clize,代码行数:7,代码来源:test_parser.py
示例9: _test
def _test(self, func, expected, expected_src):
sig = specifiers.signature(func)
self.assertSigsEqual(sig, support.s(expected))
self.assertSourcesEqual(sig.sources, expected_src, func)
with self.assertRaises(AssertionError):
support.test_func_sig_coherent(
func, check_return=False, check_invalid=False)
开发者ID:epsy,项目名称:sigtools,代码行数:7,代码来源:autoforwards_py35.py
示例10: test_pconverter
def test_pconverter(self):
class CustExc(Exception):
pass
@parser.parameter_converter
def converter(param, annotations):
raise CustExc
@parser.parameter_converter
def noop_converter(param, annotations):
raise NotImplementedError
sigs = [support.s("o: c", locals={"c": converter}), support.s("*, o: a", locals={"a": ("abc", converter)})]
for sig in sigs:
sparam = list(sig.parameters.values())[0]
self.assertRaises(CustExc, parser.CliSignature.convert_parameter, sparam)
开发者ID:Shir0kamii,项目名称:clize,代码行数:16,代码来源:test_parser.py
示例11: test_bad_default_good_conv
def test_bad_default_good_conv(self):
class UnknownDefault(object):
pass
deft = UnknownDefault()
sig = support.s("*, par:str=default", locals={"default": deft})
self._do_test(sig, parser.OptionParameter, "[--par=STR]", {"conv": parser.identity, "default": deft})
开发者ID:Shir0kamii,项目名称:clize,代码行数:7,代码来源:test_parser.py
示例12: test_vconverter
def test_vconverter(self):
@parser.value_converter
def converter(value):
raise NotImplementedError
sig = support.s("*, par: conv", locals={"conv": converter})
self._do_test(sig, parser.OptionParameter, "--par=CONVERTER", {"conv": converter})
开发者ID:Shir0kamii,项目名称:clize,代码行数:7,代码来源:test_parser.py
示例13: test_directly_applied
def test_directly_applied(self):
def forger(obj):
return support.s('abc')
def forged():
raise NotImplementedError
specifiers.set_signature_forger(forged, forger)
self.assertSigsEqual(support.s('abc'), specifiers.signature(forged))
开发者ID:epsy,项目名称:sigtools,代码行数:7,代码来源:test_specifiers.py
示例14: test_forger_sig
def test_forger_sig(self):
@specifiers.forger_function
def forger(p1, p2, p3, obj):
raise NotImplementedError
self.assertSigsEqual(
support.s('p1, p2, p3, *, emulate=None'),
specifiers.signature(forger))
开发者ID:epsy,项目名称:sigtools,代码行数:7,代码来源:test_specifiers.py
示例15: badparam
def badparam(self, sig_str, locals=None):
if locals is None:
locals = {}
sig = support.s(sig_str, pre='from clize import Parameter', locals=locals)
params = list(sig.parameters.values())
self.assertRaises(
ValueError, parser.CliSignature.convert_parameter, params[0])
开发者ID:gitter-badger,项目名称:clize,代码行数:7,代码来源:test_parser.py
示例16: _test
def _test(self, sig_str, num_args, named_args=(),
hide_varargs=False, hide_varkwargs=False):
sig = support.s(sig_str)
self.assertRaises(
ValueError, signatures.mask,
sig, num_args, *named_args,
hide_varargs=hide_varargs, hide_varkwargs=hide_varkwargs)
开发者ID:epsy,项目名称:sigtools,代码行数:7,代码来源:test_mask.py
示例17: _test
def _test(self, func, expected, sources, incoherent=False):
sig = specifiers.signature(func)
self.assertSigsEqual(sig, support.s(expected))
self.assertSourcesEqual(sig.sources, sources, func)
if not incoherent:
support.test_func_sig_coherent(
func, check_return=False, check_invalid=False)
开发者ID:regnat,项目名称:sigtools,代码行数:7,代码来源:test_autoforwards.py
示例18: annotated_sigtests
def annotated_sigtests(self, sig_info, in_args, args, kwargs):
sig_str, annotation, str_rep = sig_info
sig = support.s(sig_str, locals={'a': annotation})
csig = parser.CliSignature.from_signature(sig)
ba = util.read_arguments(csig, in_args)
self.assertEqual(ba.args, args)
self.assertEqual(ba.kwargs, kwargs)
开发者ID:Shir0kamii,项目名称:clize,代码行数:7,代码来源:test_parameters.py
示例19: extraparamstests
def extraparamstests(self, sig_str, extra, args, posargs, kwargs, func):
sig = support.s(sig_str)
csig = parser.CliSignature.from_signature(sig, extra=extra)
ba = csig.read_arguments(args)
self.assertEqual(ba.args, posargs)
self.assertEqual(ba.kwargs, kwargs)
self.assertEqual(ba.func, func)
开发者ID:prodigeni,项目名称:clize,代码行数:7,代码来源:test_parser.py
示例20: signaturetests
def signaturetests(self, sig_str, str_rep, args, posargs, kwargs):
sig = support.s(sig_str, locals={'P': parser.Parameter})
csig = parser.CliSignature.from_signature(sig)
ba = csig.read_arguments(args)
self.assertEqual(str(csig), str_rep)
self.assertEqual(ba.args, posargs)
self.assertEqual(ba.kwargs, kwargs)
开发者ID:prodigeni,项目名称:clize,代码行数:7,代码来源:test_parser.py
注:本文中的sigtools.support.s函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论