Ejemplo n.º 1
0
 def test_pn_pos_errinnext_context(self):
     sig_str, annotation, str_rep = RepTests.pn_pos_nextpicky
     sig = support.s(sig_str, locals={'a': annotation})
     csig = parser.CliSignature.from_signature(sig)
     try:
         util.read_arguments(csig, ('bad', ))
     except errors.BadArgumentFormat as exc:
         self.assertEqual(exc.param.display_name, 'other')
Ejemplo n.º 2
0
def sigerrortests(self, sig_str, args, exc_typ, message):
    sig = support.s(sig_str)
    csig = parser.CliSignature.from_signature(sig)
    self.assertRaises(exc_typ, read_arguments, csig, args)
    try:
        read_arguments(csig, args)
    except exc_typ as e:
        self.assertEqual('Error: ' + message, str(e))
Ejemplo n.º 3
0
 def test_pn_pos_errinnext_context(self):
     sig_str, annotation, str_rep = RepTests.pn_pos_nextpicky
     sig = support.s(sig_str, locals={'a': annotation})
     csig = parser.CliSignature.from_signature(sig)
     try:
         util.read_arguments(csig, ('bad',))
     except errors.BadArgumentFormat as exc:
         self.assertEqual(exc.param.display_name, 'other')
Ejemplo n.º 4
0
def sigerrortests(self, sig_str, args, exc_typ, message):
    sig = support.s(sig_str)
    csig = parser.CliSignature.from_signature(sig)
    self.assertRaises(exc_typ, read_arguments, csig, args)
    try:
        read_arguments(csig, args)
    except exc_typ as e:
        self.assertEqual('Error: ' + message, str(e))
Ejemplo n.º 5
0
def annotated_sigerror_tests(self, sig_info, in_args,
                             exc=errors.BadArgumentFormat, message=None):
    sig_str, annotation, str_rep = sig_info
    sig = support.s(sig_str, locals={'a': annotation})
    csig = parser.CliSignature.from_signature(sig)
    self.assertRaises(exc, util.read_arguments, csig, in_args)
    if message is not None:
        try:
            util.read_arguments(csig, in_args)
        except exc as e:
            self.assertEqual('Error: ' + message, str(e))
Ejemplo n.º 6
0
    def test_flagp_conv_long(self):
        @parser.value_converter
        def conv(arg):
            return arg

        param = parser.FlagParameter(argument_name="par", value="eggs", conv=conv, aliases=["--par"])
        self.assertEqual(param.get_all_names(), "--par[=CONV]")
        sig = support.s("*, par: p, o=False", locals={"p": param})
        self._do_test(sig, parser.FlagParameter, "[--par[=CONV]]", {"conv": conv})
        csig = parser.CliSignature.from_signature(sig)
        self.assertEqual(read_arguments(csig, []).kwargs, {})
        self.assertEqual(read_arguments(csig, ["--par"]).kwargs, {"par": "eggs"})
        self.assertEqual(read_arguments(csig, ["--par=ham"]).kwargs, {"par": "ham"})
Ejemplo n.º 7
0
    def test_flagp_conv_short(self):
        @parser.value_converter
        def conv(arg):
            raise NotImplementedError

        param = parser.FlagParameter(argument_name="par", value="eggs", conv=conv, aliases=["--par", "-p"])
        self.assertEqual(param.get_all_names(), "-p, --par[=CONV]")
        sig = support.s("*, par: p, o=False", locals={"p": param})
        self._do_test(sig, parser.FlagParameter, "[-p]", {"conv": conv})
        csig = parser.CliSignature.from_signature(sig)
        self.assertEqual(read_arguments(csig, []).kwargs, {})
        self.assertEqual(read_arguments(csig, ["-p"]).kwargs, {"par": "eggs"})
        self.assertEqual(read_arguments(csig, ["-po"]).kwargs, {"par": "eggs", "o": True})
Ejemplo n.º 8
0
def annotated_sigerror_tests(self,
                             sig_info,
                             in_args,
                             exc=errors.BadArgumentFormat,
                             message=None):
    sig_str, annotation, str_rep = sig_info
    sig = support.s(sig_str, locals={'a': annotation})
    csig = parser.CliSignature.from_signature(sig)
    self.assertRaises(exc, util.read_arguments, csig, in_args)
    if message is not None:
        try:
            util.read_arguments(csig, in_args)
        except exc as e:
            self.assertEqual('Error: ' + message, str(e))
Ejemplo n.º 9
0
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 = read_arguments(csig, args)
    self.assertEqual(str(csig), str_rep)
    self.assertEqual(ba.args, posargs)
    self.assertEqual(ba.kwargs, kwargs)
Ejemplo n.º 10
0
def extraparamstests(self, sig_str, extra, args, posargs, kwargs, func):
    sig = support.s(sig_str)
    csig = parser.CliSignature.from_signature(sig, extra=extra)
    ba = read_arguments(csig, args)
    self.assertEqual(ba.args, posargs)
    self.assertEqual(ba.kwargs, kwargs)
    self.assertEqual(ba.func, func)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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 = read_arguments(csig, args)
    self.assertEqual(str(csig), str_rep)
    self.assertEqual(ba.args, posargs)
    self.assertEqual(ba.kwargs, kwargs)
Ejemplo n.º 14
0
def extraparamstests(self, sig_str, extra, args, posargs, kwargs, func):
    sig = support.s(sig_str)
    csig = parser.CliSignature.from_signature(sig, extra=extra)
    ba = read_arguments(csig, args)
    self.assertEqual(ba.args, posargs)
    self.assertEqual(ba.kwargs, kwargs)
    self.assertEqual(ba.func, func)
Ejemplo n.º 15
0
    def test_flagp_conv_long(self):
        @parser.value_converter
        def conv(arg):
            return arg

        param = parser.FlagParameter(argument_name='par',
                                     value='eggs',
                                     conv=conv,
                                     aliases=['--par'])
        self.assertEqual(param.get_all_names(), '--par[=CONV]')
        sig = support.s('*, par: p, o=False', locals={'p': param})
        self._do_test(sig, parser.FlagParameter, '[--par[=CONV]]', {
            'conv': conv,
        })
        csig = parser.CliSignature.from_signature(sig)
        self.assertEqual(read_arguments(csig, []).kwargs, {})
        self.assertEqual(
            read_arguments(csig, ['--par']).kwargs, {'par': 'eggs'})
        self.assertEqual(
            read_arguments(csig, ['--par=ham']).kwargs, {'par': 'ham'})
Ejemplo n.º 16
0
 def test_flagp_conv_long(self):
     @parser.value_converter
     def conv(arg):
         return arg
     param = parser.FlagParameter(
         argument_name='par',
         value='eggs', conv=conv,
         aliases=['--par']
         )
     self.assertEqual(param.get_all_names(), '--par[=CONV]')
     sig = support.s('*, par: p, o=False', locals={'p': param})
     self._do_test(sig, parser.FlagParameter, '[--par[=CONV]]', {
         'conv': conv,
     })
     csig = parser.CliSignature.from_signature(sig)
     self.assertEqual(read_arguments(csig, []).kwargs, {})
     self.assertEqual(read_arguments(csig, ['--par']).kwargs,
                      {'par': 'eggs'})
     self.assertEqual(read_arguments(csig, ['--par=ham']).kwargs,
                      {'par': 'ham'})
Ejemplo n.º 17
0
 def test_flagp_conv_short(self):
     @parser.value_converter
     def conv(arg):
         raise NotImplementedError
     param = parser.FlagParameter(
         argument_name='par',
         value='eggs', conv=conv,
         aliases=['--par', '-p']
         )
     self.assertEqual(param.get_all_names(), '-p, --par[=CONV]')
     sig = support.s('*, par: p, o=False', locals={'p': param})
     self._do_test(sig, parser.FlagParameter, '[-p]', {
         'conv': conv,
     })
     csig = parser.CliSignature.from_signature(sig)
     self.assertEqual(read_arguments(csig, []).kwargs, {})
     self.assertEqual(read_arguments(csig, ['-p']).kwargs,
                      {'par': 'eggs'})
     self.assertEqual(read_arguments(csig, ['-po']).kwargs,
                      {'par': 'eggs', 'o': True})
Ejemplo n.º 18
0
    def test_flagp_conv_short(self):
        @parser.value_converter
        def conv(arg):
            raise NotImplementedError

        param = parser.FlagParameter(argument_name='par',
                                     value='eggs',
                                     conv=conv,
                                     aliases=['--par', '-p'])
        self.assertEqual(param.get_all_names(), '-p, --par[=CONV]')
        sig = support.s('*, par: p, o=False', locals={'p': param})
        self._do_test(sig, parser.FlagParameter, '[-p]', {
            'conv': conv,
        })
        csig = parser.CliSignature.from_signature(sig)
        self.assertEqual(read_arguments(csig, []).kwargs, {})
        self.assertEqual(read_arguments(csig, ['-p']).kwargs, {'par': 'eggs'})
        self.assertEqual(
            read_arguments(csig, ['-po']).kwargs, {
                'par': 'eggs',
                'o': True
            })
Ejemplo n.º 19
0
    def test_method_conv(self):
        class Spam(object):
            def method(self, arg):
                return self

        s = Spam()
        conv = parser.value_converter(s.method, name="TCONV")
        sig = support.s("*, par: conv", locals={"conv": conv})
        self._do_test(sig, parser.OptionParameter, "--par=TCONV", {"conv": conv})
        csig = parser.CliSignature.from_signature(sig)
        ba = read_arguments(csig, ["--par=arg"])
        arg = ba.kwargs["par"]
        self.assertTrue(arg is s)
Ejemplo n.º 20
0
    def test_method_conv(self):
        class Spam(object):
            def method(self, arg):
                return self

        s = Spam()
        conv = parser.value_converter(s.method, name='TCONV')
        sig = support.s('*, par: conv', locals={'conv': conv})
        self._do_test(sig, parser.OptionParameter, '--par=TCONV',
                      {'conv': conv})
        csig = parser.CliSignature.from_signature(sig)
        ba = read_arguments(csig, ['--par=arg'])
        arg = ba.kwargs['par']
        self.assertTrue(arg is s)
Ejemplo n.º 21
0
 def test_method_conv(self):
     class Spam(object):
         def method(self, arg):
             return self
     s = Spam()
     conv = parser.value_converter(s.method, name='TCONV')
     sig = support.s('*, par: conv', locals={'conv': conv})
     self._do_test(sig, parser.OptionParameter, '--par=TCONV', {
         'conv': conv
     })
     csig = parser.CliSignature.from_signature(sig)
     ba = read_arguments(csig, ['--par=arg'])
     arg = ba.kwargs['par']
     self.assertTrue(arg is s)
Ejemplo n.º 22
0
 def run_conv(self, conv, path):
     sig = support.s('*, par: c', locals={'c': conv})
     csig = parser.CliSignature.from_signature(sig)
     ba = util.read_arguments(csig, ['--par', path])
     return ba.kwargs['par']
Ejemplo n.º 23
0
 def _test_func(self, conv, inp, out):
     sig = support.s('*, par: c', locals={'c': conv})
     csig = parser.CliSignature.from_signature(sig)
     ba = util.read_arguments(csig, ['--par', inp])
     self.assertEqual(out, ba.kwargs['par'])
Ejemplo n.º 24
0
 def _test_func(self, conv, inp, out):
     sig = support.s('*, par: c', locals={'c': conv})
     csig = parser.CliSignature.from_signature(sig)
     ba = util.read_arguments(csig, ['--par', inp])
     self.assertEqual(out, ba.kwargs['par'])
Ejemplo n.º 25
0
 def run_conv(self, conv, path):
     sig = support.s('*, par: c', locals={'c': conv})
     csig = parser.CliSignature.from_signature(sig)
     ba = util.read_arguments(csig, ['--par', path])
     return ba.kwargs['par']