summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Waldmann <tw AT waldmann-edv DOT de>2011-03-27 00:30:56 +0100
committerThomas Waldmann <tw AT waldmann-edv DOT de>2011-03-27 00:30:56 +0100
commit6d56abca3bb1a09184b48c06c9575fd4c3f3f519 (patch)
tree83c4c61a69706226d084668c3c538211d009fdc3
parentef84b8ffb253b0b3cd2ba2f5ca6b140ab5f04ba8 (diff)
downloadargparse-6d56abca3bb1a09184b48c06c9575fd4c3f3f519.tar.gz
make tests work on python 2.4
-rw-r--r--argparse.py11
-rw-r--r--test/test_argparse.py3
2 files changed, 12 insertions, 2 deletions
diff --git a/argparse.py b/argparse.py
index 9837432..36e54c4 100644
--- a/argparse.py
+++ b/argparse.py
@@ -90,6 +90,12 @@ import textwrap as _textwrap
from gettext import gettext as _
+try:
+ set
+except NameError:
+ # for python < 2.5 compatibility (sets module is there since 2.3):
+ from sets import Set as set
+
def _callable(obj):
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
@@ -1582,7 +1588,10 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# add help and version arguments if necessary
# (using explicit default to override global argument_default)
- default_prefix = '-' if '-' in prefix_chars else prefix_chars[0]
+ if '-' in prefix_chars:
+ default_prefix = '-'
+ else:
+ default_prefix = prefix_chars[0]
if self.add_help:
self.add_argument(
default_prefix+'h', default_prefix*2+'help',
diff --git a/test/test_argparse.py b/test/test_argparse.py
index dde6d16..3b163c2 100644
--- a/test/test_argparse.py
+++ b/test/test_argparse.py
@@ -2221,7 +2221,8 @@ class TestMutuallyExclusiveGroupErrors(TestCase):
--soup
--nuts
'''
- self.assertEqual(parser.format_help(), textwrap.dedent(expected))
+ # note: .rstrip(' ') fixes different behaviour of py 2.4 textwrap.dedent
+ self.assertEqual(parser.format_help(), textwrap.dedent(expected).rstrip(' '))
class MEMixin(object):