diff options
author | Anthon van der Neut <anthon@mnt.org> | 2015-01-14 21:02:09 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2015-01-14 21:02:09 +0100 |
commit | 50dae579992b7f92750d1704bc2f1019543dd227 (patch) | |
tree | 9570d2c8c8c0ab8695fd8b0d278a740ae8ead647 | |
parent | 680b278b1da87bd5bd6ef5c84f24e59f9a7ed23a (diff) | |
download | ruamel.std.argparse-50dae579992b7f92750d1704bc2f1019543dd227.tar.gz |
- update failing test on py26
- now dependent on ruamel.base for creating ruamel/std/__init__.py
-rw-r--r-- | __init__.py | 7 | ||||
-rw-r--r-- | setup.py | 4 | ||||
-rw-r--r-- | test/test_program.py | 16 | ||||
-rw-r--r-- | tox.ini | 1 |
4 files changed, 25 insertions, 3 deletions
diff --git a/__init__.py b/__init__.py index d51a261..7a575ac 100644 --- a/__init__.py +++ b/__init__.py @@ -33,7 +33,7 @@ def _convert_version(tup): # < -version_info = (0, 4, 2) +version_info = (0, 5) __version__ = _convert_version(version_info) del _convert_version @@ -360,6 +360,11 @@ class ProgramBase(object): sp.add_argument(*arg, **kw) def _parse_args(self, *args, **kw): + """ + optional keyword arguments: + default_sub_parser='<subparsername>', allows empty subparser + help_all=True -> show help for all subcommands with --help-all + """ tmp_args = args if args else sys.argv[1:] name = kw.pop('default_sub_parser', None) if name is not None and '--version' not in tmp_args: @@ -75,7 +75,7 @@ class MyInstallLib(install_lib.install_lib): "create __init__.py on the fly" def run(self): install_lib.install_lib.run(self) - init_txt = dedent('''\ + init_txt = dedent('''\y # coding: utf-8 # Copyright © 2013-2014 Anthon van der Neut, RUAMEL bvba "generated __init__.py " @@ -91,6 +91,7 @@ class MyInstallLib(install_lib.install_lib): for p in range(len(init_path)) ]: if not os.path.exists(product_init): + raise NotImplementedError print('creating %s' % product_init) with open(product_init, "w") as fp: fp.write(init_txt) @@ -117,6 +118,7 @@ class MyInstallLib(install_lib.install_lib): def main(): install_requires = [ + "ruamel.base", ] if sys.version_info[:2] == (2, 6): install_requires.append("argparse") diff --git a/test/test_program.py b/test/test_program.py index 3d98b03..fa6320b 100644 --- a/test/test_program.py +++ b/test/test_program.py @@ -152,6 +152,19 @@ class ParseHelpOutput: return True return False + def between_curly_braces(self, chunk, elems): + """check if elements are in comma splitted contents of {}""" + for l in self._chunks[chunk]: + start_idx = l.find('{') + end_idx = l.find('}') + test_elems = l[start_idx + 1:end_idx-1].split(',') + for elem in elems: + if elem not in test_elems: + break + else: + return True + return False + @pytest.fixture(scope='class') def program(): @@ -166,7 +179,8 @@ class TestProgram: assert pho.start('positional arguments', 'hg') if sys.version_info[:2] == (2, 6): # 2.6 argparse scrambles order - assert pho.somewhere('usage', 'git,e,d,f') + x = 'a b c d git'.split() + assert pho.between_curly_braces('usage', x) else: assert pho.somewhere('usage', 'c,d,f,e') assert pho.start('optional arguments', '--verbose') @@ -5,3 +5,4 @@ envlist = py26,py27,py33,py34 commands = py.test test deps = pytest + ruamel.base |