Exemplo n.º 1
0
 def _test_help(self, action=None):
     argv = ['didjvu', action, '--help']
     argv = filter(None, argv)
     stdout = io.BytesIO()
     with interim(sys, argv=argv, stdout=stdout):
         ap = cli.ArgumentParser(self.methods, 'djvu')
         with assert_raises(SystemExit) as ecm:
             ap.parse_args({})
         assert_equal(ecm.exception.args, (0,))
     assert_greater(len(stdout.getvalue()), 0)
Exemplo n.º 2
0
 def _test_action(self, action, *args):
     stderr = io.BytesIO()
     argv = ['didjvu', action]
     argv += args
     with interim(sys, argv=argv, stderr=stderr):
         ap = cli.ArgumentParser(self.methods, 'djvu')
         [selected_action, options] = ap.parse_args(self.actions)
     assert_multi_line_equal(stderr.getvalue(), '')
     assert_equal(selected_action, action)
     return options
Exemplo n.º 3
0
 def test_bad_action(self, action='eggs'):
     stderr = io.BytesIO()
     with interim(sys, argv=['didjvu', action], stderr=stderr):
         ap = cli.ArgumentParser(self.methods, 'djvu')
         with assert_raises(SystemExit) as ecm:
             ap.parse_args({})
         assert_equal(ecm.exception.args, (2,))
     assert_multi_line_equal(
         stderr.getvalue(),
         'usage: didjvu [-h] [--version] {{{actions}}} ...\n'.format(actions=','.join(self.anames)) +
         "didjvu: error: invalid choice: 'eggs' (choose from {actions})\n".format(actions=', '.join(map(repr, self.anames)))
     )
Exemplo n.º 4
0
 def test_no_args(self):
     stderr = io.BytesIO()
     with interim(sys, argv=['didjvu'], stderr=stderr):
         ap = cli.ArgumentParser(self.methods, 'djvu')
         with assert_raises(SystemExit) as ecm:
             ap.parse_args({})
         assert_equal(ecm.exception.args, (2,))
     assert_multi_line_equal(
         stderr.getvalue(),
         'usage: didjvu [-h] [--version] {{{actions}}} ...\n'
         'didjvu: error: too few arguments\n'.format(actions=','.join(self.anames))
     )
Exemplo n.º 5
0
 def _test_action_no_args(self, action):
     stderr = io.BytesIO()
     with interim(sys, argv=['didjvu', action], stderr=stderr):
         ap = cli.ArgumentParser(self.methods, 'djvu')
         with assert_raises(SystemExit) as ecm:
             ap.parse_args({})
         assert_equal(ecm.exception.args, (2,))
     assert_regex(
         stderr.getvalue(),
         (r'(?s)\A'
         'usage: didjvu {action} .*\n'
         'didjvu {action}: error: too few arguments\n'
         r'\Z').format(action=action)
     )
Exemplo n.º 6
0
 def test_init(self):
     cli.ArgumentParser(self.methods, 'djvu')