From a39cf3b0e3ec24c80f800b2ce4f6b448c69358a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Neuha=CC=88user?= Date: Sun, 1 Apr 2012 02:46:19 +0200 Subject: [PATCH] Add Python 2.6 support --- awwparse/__init__.py | 28 ++++++++++++++-------------- awwparse/testsuite/__init__.py | 5 ++++- awwparse/testsuite/types.py | 30 ++++++++++++++++++++---------- awwparse/utils.py | 2 +- tox.ini | 6 +++++- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/awwparse/__init__.py b/awwparse/__init__.py index 09ba5b9..c90bd48 100644 --- a/awwparse/__init__.py +++ b/awwparse/__init__.py @@ -214,46 +214,46 @@ def option_prefixes(self): """ A set of all option name prefixes. """ - return {option.name_prefix for option in self.options.values()} + return set(option.name_prefix for option in self.options.values()) @property def abbreviated_option_prefixes(self): """ A set of all abbreviated option name prefixes. """ - return { + return set( option.abbreviation_prefix for option in self.options.values() - } + ) @property def option_shorts(self): """ A mapping of all abbreviated option argument names to options. """ - return { - option.short: option for option in self.options.values() + return dict( + (option.short, option) for option in self.options.values() if option.short is not None - } + ) @property def option_longs(self): """ A mapping of all complete option argument names to options. """ - return { - option.long: option for option in self.options.values() + return dict( + (option.long, option) for option in self.options.values() if option.long is not None - } + ) @property def defaults(self): """ A mapping of option names to option default values. """ - return { - name: option.default for name, option in self.options.items() + return dict( + (name, option.default) for name, option in self.options.items() if option.default is not missing - } + ) def get_usage(self, arguments=None): result = [] if arguments is None else arguments.trace[:-1] @@ -754,14 +754,14 @@ def copy(self): return option def get_usage(self, using="short"): - if using not in {"short", "long", "both"}: + if using not in set(["short", "long", "both"]): raise ValueError( "using has to be 'short', 'long' or 'both'; not %r" % using ) if using == "both" and self.short and self.long: caller = u("%s, %s") % (self.short, self.long) elif (using == "short" and self.short or - using in {"long", "both"} and not self.long): + using in set(["long", "both"]) and not self.long): caller = self.short else: caller = self.long diff --git a/awwparse/testsuite/__init__.py b/awwparse/testsuite/__init__.py index 9b7d8c3..f154c6a 100644 --- a/awwparse/testsuite/__init__.py +++ b/awwparse/testsuite/__init__.py @@ -8,7 +8,10 @@ """ import re import sys -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest import textwrap from functools import wraps from itertools import chain diff --git a/awwparse/testsuite/types.py b/awwparse/testsuite/types.py index ceccc1e..f3fe7ca 100644 --- a/awwparse/testsuite/types.py +++ b/awwparse/testsuite/types.py @@ -95,7 +95,7 @@ def test_parse_and_store(self): command.add_option("foo", Option("a", Set(String()))) self.assert_equal( command.run(["-a", "foo", "-a", "bar"]), - {"foo": {u("foo"), u("bar")}} + {"foo": set([u("foo"), u("bar")])} ) @@ -227,7 +227,13 @@ def test_convert(self): with self.assert_raises(UserTypeError): floating.convert("1j") - _parse_test = ( + +class FloatTestCase(FloatingTestCaseMixin, TestCase): + type = Float + floating_type = float + + test_parse = make_parse_test( + Float, [(["1.0"], 1.0)], [(["1.0", "2.0", "3.0"], [1.0, 2.0, 3.0])], [ @@ -237,18 +243,22 @@ def test_convert(self): ) -class FloatTestCase(FloatingTestCaseMixin, TestCase): - type = Float - floating_type = float - - test_parse = make_parse_test(Float, *FloatingTestCaseMixin._parse_test) - - class DecimalTestCase(FloatingTestCaseMixin, TestCase): type = Decimal floating_type = decimal.Decimal - test_parse = make_parse_test(Decimal, *FloatingTestCaseMixin._parse_test) + test_parse = make_parse_test( + Decimal, + [(["1.0"], decimal.Decimal("1.0"))], + [( + ["1.0", "2.0", "3.0"], + [decimal.Decimal("1.0"), decimal.Decimal("2.0"), decimal.Decimal("3.0")] + )], + [ + (["1.0"], [decimal.Decimal("1.0")]), + (["1.0", "2.0"], [decimal.Decimal("1.0"), decimal.Decimal("2.0")]) + ] + ) class ComplexTestCase(TestCase): diff --git a/awwparse/utils.py b/awwparse/utils.py index f8f5c02..55a21a8 100644 --- a/awwparse/utils.py +++ b/awwparse/utils.py @@ -37,7 +37,7 @@ def set_attributes_from_kwargs(object, kwargs, defaults): """ set_attributes( object, - {key: kwargs.pop(key, value) for key, value in defaults.items()} + dict((key, kwargs.pop(key, value)) for key, value in defaults.items()) ) if kwargs: raise TypeError( diff --git a/tox.ini b/tox.ini index d896b3b..c9720e7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,9 @@ [tox] -envlist=py27,py32,pypy +envlist=py26,py27,pypy,py32 [testenv] commands=python run-tests.py + +[testenv:py26] +deps=unittest2 +commands=python run-tests.py