summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Waldmann <tw AT waldmann-edv DOT de>2011-03-27 01:16:28 +0100
committerThomas Waldmann <tw AT waldmann-edv DOT de>2011-03-27 01:16:28 +0100
commitb40e9c0629e03ee616ddec30f687b0455a56c217 (patch)
tree0c5054724c434070601c36c453ec2da426de7d17
parent6d56abca3bb1a09184b48c06c9575fd4c3f3f519 (diff)
downloadargparse-b40e9c0629e03ee616ddec30f687b0455a56c217.tar.gz
make most tests work on python 2.3
-rw-r--r--argparse.py14
-rw-r--r--test/test_argparse.py24
2 files changed, 37 insertions, 1 deletions
diff --git a/argparse.py b/argparse.py
index 36e54c4..3457867 100644
--- a/argparse.py
+++ b/argparse.py
@@ -93,10 +93,22 @@ from gettext import gettext as _
try:
set
except NameError:
- # for python < 2.5 compatibility (sets module is there since 2.3):
+ # for python < 2.4 compatibility (sets module is there since 2.3):
from sets import Set as set
+try:
+ sorted
+except NameError:
+ # for python < 2.4 compatibility:
+ def sorted(iterable, reverse=False):
+ result = list(iterable)
+ result.sort()
+ if reverse:
+ result.reverse()
+ return result
+
+
def _callable(obj):
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
diff --git a/test/test_argparse.py b/test/test_argparse.py
index 3b163c2..9141cfb 100644
--- a/test/test_argparse.py
+++ b/test/test_argparse.py
@@ -16,6 +16,23 @@ class StdIOBuffer(StringIO):
pass
+try:
+ set
+except NameError:
+ # for python < 2.4 compatibility (sets module is there since 2.3):
+ from sets import Set as set
+
+try:
+ sorted
+except NameError:
+ # for python < 2.4 compatibility:
+ def sorted(iterable, reverse=False):
+ result = list(iterable)
+ result.sort()
+ if reverse:
+ result.reverse()
+ return result
+
# silence some warnings - these are expected
import warnings
warnings.filterwarnings(
@@ -43,6 +60,12 @@ class TestCase(unittest.TestCase):
print(obj2)
super(TestCase, self).assertEqual(obj1, obj2)
+ # Python 2.3 does not have unittest.TestCase.assertTrue:
+ def assertTrue(self, expr, msg=None):
+ if not expr:
+ msg = self._formatMessage(msg, "%s is not True" % safe_repr(expr))
+ raise self.failureException(msg)
+
class TempDirMixin(object):
@@ -4340,6 +4363,7 @@ class TestImportStar(TestCase):
if not name.startswith("_")
if not inspect.ismodule(value)
]
+ # this will fail on python 2.3 due to "set" and "sorted":
self.assertEqual(sorted(items), sorted(argparse.__all__))