diff options
author | steven.bethard <devnull@localhost> | 2009-05-04 05:20:50 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-05-04 05:20:50 +0000 |
commit | da2a4da94bdb285c7b568e4fd0e546577e446f33 (patch) | |
tree | db2e973157287c0c17eb1fb1cb00ce01f4d8a152 | |
parent | c8ced44d922425227df2601912402835563801f3 (diff) | |
download | argparse-da2a4da94bdb285c7b568e4fd0e546577e446f33.tar.gz |
Make append* actions copy their default value.
Bump version numbers, and clean up description text in setup.py.
Ignore some generated and local files.
-rw-r--r-- | README.txt | 2 | ||||
-rw-r--r-- | argparse.py | 11 | ||||
-rw-r--r-- | setup.py | 14 | ||||
-rw-r--r-- | test/test_argparse.py | 27 |
4 files changed, 42 insertions, 12 deletions
@@ -1,4 +1,4 @@ -argparse 0.9.1
+argparse 0.9.2
==============
The argparse module makes writing command line tools in Python easy.
diff --git a/argparse.py b/argparse.py index bc640a2..8544dd7 100644 --- a/argparse.py +++ b/argparse.py @@ -72,8 +72,9 @@ considered public as object names -- the API of the formatter objects is still considered an implementation detail.)
"""
-__version__ = '0.9.1'
+__version__ = '0.9.2'
+import copy as _copy
import os as _os
import re as _re
import sys as _sys
@@ -833,7 +834,9 @@ class _AppendAction(Action): metavar=metavar)
def __call__(self, parser, namespace, values, option_string=None):
- _ensure_value(namespace, self.dest, []).append(values)
+ items = _copy.copy(_ensure_value(namespace, self.dest, []))
+ items.append(values)
+ setattr(namespace, self.dest, items)
class _AppendConstAction(Action):
@@ -857,7 +860,9 @@ class _AppendConstAction(Action): metavar=metavar)
def __call__(self, parser, namespace, values, option_string=None):
- _ensure_value(namespace, self.dest, []).append(self.const)
+ items = _copy.copy(_ensure_value(namespace, self.dest, []))
+ items.append(self.const)
+ setattr(namespace, self.dest, items)
class _CountAction(Action):
@@ -16,21 +16,19 @@ import textwrap
import distutils.core
+import argparse
distutils.core.setup(
name='argparse',
- version='0.9.1',
+ version=argparse.__version__,
author='Steven Bethard',
author_email='steven.bethard@gmail.com',
url='http://code.google.com/p/argparse/',
- description='An optparse-inspired command-line parsing library',
+ description='Python command-line parsing library',
long_description = textwrap.dedent("""\
- Argparse takes the best of the optparse command-line parsing module
- and brings it new life. Argparse adds positional as well as
- optional arguments, the ability to create parsers for sub-commands,
- more informative help and usage messages, and much more. At the
- same time, it retains the ease and flexibility of use that made
- optparse so popular."""),
+ The argparse module provides an easy, declarative interface for
+ creating command line tools.
+ """),
license='Apache 2.0',
classifiers=[
'Development Status :: 4 - Beta',
diff --git a/test/test_argparse.py b/test/test_argparse.py index f5906a0..6609e3c 100644 --- a/test/test_argparse.py +++ b/test/test_argparse.py @@ -632,6 +632,18 @@ class TestOptionalsActionAppend(ParserTestCase): ]
+class TestOptionalsActionAppendWithDefault(ParserTestCase):
+ """Tests the append action for an Optional"""
+
+ argument_signatures = [Sig('--baz', action='append', default=['X'])]
+ failures = ['a', '--baz', 'a --baz', '--baz a b']
+ successes = [
+ ('', NS(baz=['X'])),
+ ('--baz a', NS(baz=['X', 'a'])),
+ ('--baz a --baz b', NS(baz=['X', 'a', 'b'])),
+ ]
+
+
class TestOptionalsActionAppendConst(ParserTestCase):
"""Tests the append_const action for an Optional"""
@@ -647,6 +659,21 @@ class TestOptionalsActionAppendConst(ParserTestCase): ]
+class TestOptionalsActionAppendConstWithDefault(ParserTestCase):
+ """Tests the append_const action for an Optional"""
+
+ argument_signatures = [
+ Sig('-b', action='append_const', const=Exception, default=['X']),
+ Sig('-c', action='append', dest='b'),
+ ]
+ failures = ['a', '-c', 'a -c', '-bx', '-b x']
+ successes = [
+ ('', NS(b=['X'])),
+ ('-b', NS(b=['X', Exception])),
+ ('-b -cx -b -cyz', NS(b=['X', Exception, 'x', Exception, 'yz'])),
+ ]
+
+
class TestOptionalsActionCount(ParserTestCase):
"""Tests the count action for an Optional"""
|